DiracX Python API Client
The DiracX Python API Client provides an interface for interacting with the DiracX API. It simplifies making requests, handling authentication, and processing responses for various DiracX services. The current version is 0.0.12, and as a rapidly evolving library targeting Python 3.11+, it experiences frequent updates.
Warnings
- breaking As the library is in early development (version 0.0.x), breaking changes can be introduced in any patch release without a major version increment, affecting method signatures, return types, or data structures.
- gotcha API key (`DIRACX_API_KEY`) and base URL (`DIRACX_BASE_URL`) are typically provided via environment variables. Failing to set `DIRACX_API_KEY` will result in authentication errors.
- gotcha All API responses are wrapped in a standard `success`/`error_message`/`data` structure. Direct access to `response.data` without checking `response.success` can lead to errors if the API call failed.
Install
-
pip install diracx-api
Imports
- DiracXClient
from diracx_api import DiracXClient
Quickstart
import os
from diracx_api import DiracXClient
# Ensure DIRACX_API_KEY and DIRACX_BASE_URL are set in your environment
api_key = os.environ.get("DIRACX_API_KEY", "")
base_url = os.environ.get("DIRACX_BASE_URL", "https://api.diracx.com")
if not api_key:
print("Warning: DIRACX_API_KEY environment variable not set. API calls may fail.")
try:
client = DiracXClient(api_key=api_key, base_url=base_url)
# Example: List assets
assets_response = client.assets.list_assets()
if assets_response.success:
print("Assets retrieved successfully:")
for asset in assets_response.data:
print(f" ID: {asset.asset_id}, Symbol: {asset.symbol}")
else:
print(f"Failed to retrieve assets: {assets_response.error_message}")
except Exception as e:
print(f"An error occurred during API interaction: {e}")