Using the Foji Python Client in Notebook Servers

From FojiSoft Docs
Revision as of 17:09, 13 September 2024 by Chris.Hansen (talk | contribs) (Created page with "The Foji Python client is designed to interact with various services within the FojiSoft application suite, including relational data access, metric services, dataset management, and predictive analytics. This guide explains how to use key methods available for these functionalities in Notebook Servers. ==== Installation ==== The <code>foji</code> package is already available in your Notebook Server. ==== Key Components ==== The "Foji" Python client consists of four pr...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The Foji Python client is designed to interact with various services within the FojiSoft application suite, including relational data access, metric services, dataset management, and predictive analytics. This guide explains how to use key methods available for these functionalities in Notebook Servers.

Installation

The foji package is already available in your Notebook Server.

Key Components

The "Foji" Python client consists of four primary modules that facilitate the following tasks:

  1. Relational (ClickHouse Client): Execute queries against a relational data store.
  2. Metrics (Cortex Client): Fetch real-time and time-series metrics from the Cortex service.
  3. DataSets: Fetch datasets from the Forge AI platform.
  4. Predictions (AutoML Client): Retrieve predictions from pre-trained Forge AI models.

How to Use

1. ClickHouse Client (Relational Data Access)

The ClickHouse client provides access to a relational data store using SQL queries. It also supports date parsing.

from foji import relational

# Execute a SQL query with optional parameters
query = "SELECT * FROM users WHERE age > {age:Int32}"
params = {"age": 25}
results = relational.query(query, params)

# Print results
for row in results:
    print(row)

Key Method:

  • query(query: str, params: dict[str, Any] = None) -> list[dict]: Executes an SQL query with optional parameters and returns the results as a list of dictionaries.
2. Cortex Client (Metrics Service)

The Cortex client provides interfaces to query real-time and historical metrics using the Cortex API.

from foji import metrics

# Query for an instant metric value
result = metrics.instant("up")

# Query for a range of metrics
result_range = metrics.range("up", "2023-01-01T00:00:00Z", "2023-01-01T01:00:00Z", "60s")

# Print results
print(result)
print(result_range)

Key Methods:

  • instant(query: str, time: int | str = None) -> CortexResult: Queries metrics at a specific point in time.
  • query(query: str, time: int | str = None) -> CortexResult: Queries metrics at a specific point in time.
  • range(query: str, start: int | str, end: int | str, step: float | str = None) -> CortexResult: Queries time-series metrics for a given time range.
3. DataSets Client (Dataset Management)

The DataSets client allows you to fetch datasets stored within Foji.

from foji import dataSets

# Fetch a dataset by its ID
data = dataSets.fetch("dataset_id", "2023-01-01T00:00:00Z", "2023-01-01T01:00:00Z", "60s")

# Print data
print(data)

Key Method:

  • fetch(id: str, start: str, end: str, step: str = "1m") -> list[dict[str, Any]]: Fetches data from a Data Set
4. Prediction Client (AutoML Predictions)

The Predictions client enables you to retrieve predictions from pre-trained Forge AI models.

from foji import predictions

# Fetch a prediction using input data
input_data = {"feature1": 1.5, "feature2": 3.4}
predicted_value = predictions.fetch("model_id", input_data)

# Fetch multiple predictions
input_data_list = [{"feature1": 1.5, "feature2": 3.4}, {"feature1": 2.1, "feature2": 4.0}]
predicted_values = predictions.fetch("model_id", input_data_list)

# Print predictions
print(predicted_value)
for prediction in predicted_values:
    print(prediction)

Key Method:

  • fetch(id: str, data: dict | list[dict]) -> float | str | list[Prediction]: Fetches single or multiple predictions based on the input data.

Conclusion

The "Foji" Python client provides seamless integration with Foji services, enabling efficient access to relational data, metrics, datasets, and prediction models. By leveraging these key methods, you can streamline data processing and predictive analysis within the Forge AI Notebook Server environment.