DiracX Client Library
The DiracX Python Client Library, currently at version 0.0.12, provides a Pythonic interface for interacting with the DiracX AI platform. It allows developers to integrate advanced AI functionalities into their applications by accessing features like model listing and AI task creation. The library is under active development, with frequent pre-1.0 releases.
Warnings
- breaking The library is currently in a pre-1.0 state (0.0.x versions). This means the API is unstable and subject to frequent breaking changes without adhering to semantic versioning (e.g., a minor version bump might introduce breaking changes).
- gotcha The library has a strict dependency on Pydantic V2 (`pydantic>=2.7.0`). If your project also uses Pydantic V1, this will lead to package conflicts or runtime errors due to incompatible APIs. Ensure your project's Pydantic usage is compatible with V2.
- gotcha Authentication relies on `DIRACX_API_KEY` and `DIRACX_API_SECRET` environment variables. If these are not correctly set, the client initialization will fail or API calls will be unauthorized, often leading to `exit(1)` in example scripts.
Install
-
pip install diracx-client
Imports
- DiracXClient
from diracx_client import DiracXClient
Quickstart
import os
from diracx_client import DiracXClient
# Ensure DIRACX_API_KEY and DIRACX_API_SECRET are set as environment variables
# For local development, you might use a .env file and python-dotenv.
# e.g., os.environ['DIRACX_API_KEY'] = 'your_key'
# os.environ['DIRACX_API_SECRET'] = 'your_secret'
api_key = os.environ.get("DIRACX_API_KEY", "")
api_secret = os.environ.get("DIRACX_API_SECRET", "")
if not api_key or not api_secret:
print("Error: DIRACX_API_KEY and DIRACX_API_SECRET environment variables must be set.")
# In a real application, you might raise an exception or handle this more gracefully.
exit(1)
# Initialize the DiracXClient
client = DiracXClient(api_key=api_key, api_secret=api_secret)
# Example: Fetch available models
try:
models_response = client.models.list_all()
print("Successfully fetched models.")
if models_response.data:
print(f"First model ID: {models_response.data[0].id}")
print(f"First model Name: {models_response.data[0].name}")
else:
print("No models found.")
except Exception as e:
print(f"Error fetching models: {e}")