Python SDK

Integrate Alephant into your Python applications
View as Markdown

The official Alephant Python SDK provides convenient access to the Alephant SaaS API from any Python 3.8+ application. It supports both synchronous and asynchronous usage and is fully type-hinted for great IDE support.

Installation

Install the SDK via pip:

$pip install alephantai-saas-api

Initialization

You can initialize either a synchronous or asynchronous client depending on your application architecture.

Synchronous Client

1import os
2from alephantai_saas import AlephantAi007131Api, AlephantAi007131ApiEnvironment
3
4client = AlephantAi007131Api(
5 # Set the target environment (DEFAULT points to Alephant Cloud)
6 environment=AlephantAi007131ApiEnvironment.DEFAULT,
7 # Pass your API token via Bearer auth
8 token=f"Bearer {os.getenv('ALEPHANT_API_TOKEN')}"
9)

Asynchronous Client

For modern async frameworks like FastAPI or Starlette:

1import os
2from alephantai_saas import AsyncAlephantAi007131Api, AlephantAi007131ApiEnvironment
3
4async_client = AsyncAlephantAi007131Api(
5 environment=AlephantAi007131ApiEnvironment.DEFAULT,
6 token=f"Bearer {os.getenv('ALEPHANT_API_TOKEN')}"
7)

Example Usage

Listing Workspaces

1def fetch_workspaces():
2 try:
3 response = client.workspaces.list_workspaces()
4 for workspace in response.data:
5 print(f"Workspace: {workspace.name} (ID: {workspace.id})")
6 except Exception as e:
7 print(f"Error fetching workspaces: {e}")

Fetching Agent Analytics

1async def get_agent_metrics(agent_id: str):
2 analytics = await async_client.analytics.get_agent_analytics(
3 agent_id=agent_id,
4 period="7d"
5 )
6 print(f"Total Cost: ${analytics.total_cost}")
7 print(f"Total Requests: {analytics.total_requests}")

Environments

If you are using an Enterprise private deployment, you can override the base URL by passing a string to the environment parameter instead of the default enum.

1client = AlephantAi007131Api(
2 environment="https://alephant.your-company.com/api",
3 token="Bearer <token>"
4)