Client Classes

The SDK provides both synchronous and asynchronous clients for interacting with the Moderately AI platform.

Synchronous Client

class moderatelyai_sdk.ModeratelyAI(*, team_id=None, api_key=None, base_url=None, timeout=None, max_retries=3, retry_config=None, default_headers=None, default_query=None, http_client=None)[source]

Bases: BaseClient

Synchronous client for the Moderately AI API.

The main client for interacting with the Moderately AI platform. Provides access to all platform resources through resource groups like files, datasets, agents, and pipelines. All operations are automatically scoped to your team.

users

User management operations

teams

Team settings and information

agents

AI agent management and execution

agent_executions

Agent execution monitoring

datasets

Dataset upload, management, and schema operations

pipelines

Pipeline creation and configuration management

pipeline_configuration_versions

Pipeline workflow configuration

pipeline_executions

Pipeline execution and monitoring

files

File upload, download, and management

Parameters:
  • api_key (Optional[str]) – Your API key. If not provided, reads from MODERATELY_API_KEY environment variable.

  • team_id (Optional[str]) – Your team ID. If not provided, reads from MODERATELY_TEAM_ID environment variable.

  • base_url (Optional[str]) – API base URL. Defaults to https://api.moderately.ai

  • timeout (Union[float, Timeout, None]) – Request timeout in seconds. Defaults to 30.0.

  • max_retries (int) – Maximum retry attempts. Defaults to 3.

  • retry_config (Optional[RetryConfig]) – Custom retry configuration. Optional.

  • default_headers (Optional[Dict[str, str]]) – Additional headers to include in all requests. Optional.

  • default_query (Optional[Dict[str, object]]) – Additional query parameters to include in all requests. Optional.

  • http_client (Optional[Client]) – Custom HTTP client instance. Optional.

Example

```python import moderatelyai_sdk

# Initialize with environment variables (recommended) client = moderatelyai_sdk.ModeratelyAI() # reads MODERATELY_API_KEY and MODERATELY_TEAM_ID

# Or initialize with explicit parameters client = moderatelyai_sdk.ModeratelyAI(

team_id=”your-team-id”, api_key=”your-api-key”

)

# Advanced configuration client = moderatelyai_sdk.ModeratelyAI(

team_id=”your-team-id”, api_key=”your-api-key”, timeout=60, max_retries=5

)

# Use the client - all operations are automatically scoped to your team users = client.users.list() # User management dataset = client.datasets.create(name=”Data”) # Dataset operations agents = client.agents.list() # AI agent management pipeline = client.pipelines.create(name=”ML”) # Pipeline operations file = client.files.upload(file=”data.csv”) # File management ```

Raises:
__init__(*, team_id=None, api_key=None, base_url=None, timeout=None, max_retries=3, retry_config=None, default_headers=None, default_query=None, http_client=None)[source]

Initialize the Moderately AI client.

Parameters:
  • team_id (Optional[str]) – The team ID to scope all API requests to. If not provided, will read from MODERATELY_TEAM_ID environment variable.

  • api_key (Optional[str]) – Your API key. If not provided, will read from MODERATELY_API_KEY environment variable.

  • base_url (Optional[str]) – Override the default base URL for the API. Defaults to https://api.moderately.ai.

  • timeout (Union[float, Timeout, None]) – Request timeout in seconds. Defaults to 30 seconds.

  • max_retries (int) – Maximum number of retries. Defaults to 3.

  • retry_config (Optional[RetryConfig]) – Advanced retry configuration. If provided, max_retries is ignored.

  • default_headers (Optional[Dict[str, str]]) – Default headers to include with every request.

  • default_query (Optional[Dict[str, object]]) – Default query parameters to include with every request.

  • http_client (Optional[Client]) – Custom httpx client instance. If provided, other HTTP options are ignored.

Raises:

ValueError – If no API key or team ID is provided via parameter or environment variable.

__enter__()[source]

Context manager entry.

Return type:

ModeratelyAI

__exit__(exc_type, exc_val, exc_tb)[source]

Context manager exit.

Parameters:
Return type:

None

close()[source]

Close the underlying HTTP client.

Return type:

None

Asynchronous Client

class moderatelyai_sdk.AsyncModeratelyAI(*, team_id=None, api_key=None, base_url=None, timeout=None, max_retries=2, default_headers=None, default_query=None, http_client=None)[source]

Bases: AsyncBaseClient

Asynchronous client for the Moderately AI API.

The async client provides the same interface as the synchronous client, but all methods are async and return awaitable objects. Ideal for use in async frameworks like FastAPI, aiohttp, or asyncio applications.

users

User management operations (async)

teams

Team settings and information (async)

agents

AI agent management and execution (async)

agent_executions

Agent execution monitoring (async)

datasets

Dataset upload, management, and schema operations (async)

pipelines

Pipeline creation and configuration management (async)

pipeline_configuration_versions

Pipeline workflow configuration (async)

pipeline_executions

Pipeline execution and monitoring (async)

files

File upload, download, and management (async)

Parameters:
  • api_key (Optional[str]) – Your API key. If not provided, reads from MODERATELY_API_KEY environment variable.

  • team_id (Optional[str]) – Your team ID. If not provided, reads from MODERATELY_TEAM_ID environment variable.

  • base_url (Optional[str]) – API base URL. Defaults to https://api.moderately.ai

  • timeout (Union[float, Timeout, None]) – Request timeout in seconds. Defaults to 10.0.

  • max_retries (int) – Maximum retry attempts. Defaults to 2.

  • default_headers (Optional[Dict[str, str]]) – Additional headers to include in all requests. Optional.

  • default_query (Optional[Dict[str, object]]) – Additional query parameters to include in all requests. Optional.

  • http_client (Optional[AsyncClient]) – Custom async HTTP client instance. Optional.

Example

```python import asyncio import moderatelyai_sdk

async def main():

# Use as async context manager (recommended) async with moderatelyai_sdk.AsyncModeratelyAI() as client:

# All operations are awaitable and team-scoped users = await client.users.list() # User management dataset = await client.datasets.create(name=”Data”) # Dataset operations agents = await client.agents.list() # AI agent management file = await client.files.upload(file=”data.csv”) # File management

asyncio.run(main()) ```

```python # FastAPI integration example from fastapi import FastAPI, UploadFile import moderatelyai_sdk

app = FastAPI()

@app.post(“/upload”) async def upload_file(file: UploadFile):

async with moderatelyai_sdk.AsyncModeratelyAI() as client:
uploaded = await client.files.upload(

file=await file.read(), name=file.filename

) return {“file_id”: uploaded.file_id, “name”: uploaded.name}

```

Raises:
__init__(*, team_id=None, api_key=None, base_url=None, timeout=None, max_retries=2, default_headers=None, default_query=None, http_client=None)[source]

Initialize the async Moderately AI client.

Parameters:
  • team_id (Optional[str]) – The team ID to scope all API requests to. If not provided, will read from MODERATELY_TEAM_ID environment variable.

  • api_key (Optional[str]) – Your API key. If not provided, will read from MODERATELY_API_KEY environment variable.

  • base_url (Optional[str]) – Override the default base URL for the API. Defaults to https://api.moderately.ai.

  • timeout (Union[float, Timeout, None]) – Request timeout in seconds. Defaults to 10 seconds.

  • max_retries (int) – Maximum number of retries. Defaults to 2.

  • default_headers (Optional[Dict[str, str]]) – Default headers to include with every request.

  • default_query (Optional[Dict[str, object]]) – Default query parameters to include with every request.

  • http_client (Optional[AsyncClient]) – Custom httpx async client instance. If provided, other HTTP options are ignored.

Raises:

ValueError – If no API key or team ID is provided via parameter or environment variable.

async __aenter__()[source]

Async context manager entry.

Return type:

AsyncModeratelyAI

async __aexit__(exc_type, exc_val, exc_tb)[source]

Async context manager exit.

Parameters:
Return type:

None

async close()[source]

Close the underlying HTTP client.

Return type:

None

Configuration

class moderatelyai_sdk.RetryConfig(max_retries=3, backoff_factor=2.0, max_backoff=60.0, retryable_status_codes=None)[source]

Bases: object

Configuration for retry behavior.

Parameters:
__init__(max_retries=3, backoff_factor=2.0, max_backoff=60.0, retryable_status_codes=None)[source]
Parameters: