***

title: Python SDK
subtitle: Integrate Alephant into your Python applications
description: 'Installation, configuration, and usage of the Alephant Python SDK'
--------------------------------------------------------------------------------

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:

```bash
pip install alephantai-saas-api
```

## Initialization

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

### Synchronous Client

```python
import os
from alephantai_saas import AlephantAi007131Api, AlephantAi007131ApiEnvironment

client = AlephantAi007131Api(
    # Set the target environment (DEFAULT points to Alephant Cloud)
    environment=AlephantAi007131ApiEnvironment.DEFAULT,
    # Pass your API token via Bearer auth
    token=f"Bearer {os.getenv('ALEPHANT_API_TOKEN')}"
)
```

### Asynchronous Client

For modern async frameworks like FastAPI or Starlette:

```python
import os
from alephantai_saas import AsyncAlephantAi007131Api, AlephantAi007131ApiEnvironment

async_client = AsyncAlephantAi007131Api(
    environment=AlephantAi007131ApiEnvironment.DEFAULT,
    token=f"Bearer {os.getenv('ALEPHANT_API_TOKEN')}"
)
```

## Example Usage

### Listing Workspaces

```python
def fetch_workspaces():
    try:
        response = client.workspaces.list_workspaces()
        for workspace in response.data:
            print(f"Workspace: {workspace.name} (ID: {workspace.id})")
    except Exception as e:
        print(f"Error fetching workspaces: {e}")
```

### Fetching Agent Analytics

```python
async def get_agent_metrics(agent_id: str):
    analytics = await async_client.analytics.get_agent_analytics(
        agent_id=agent_id,
        period="7d"
    )
    print(f"Total Cost: ${analytics.total_cost}")
    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.

```python
client = AlephantAi007131Api(
    environment="https://alephant.your-company.com/api",
    token="Bearer <token>"
)
```
