Python SDK for Moderately AI platform
Project description
Moderately AI Python SDK
The official Python SDK for the Moderately AI platform, providing programmatic access to agents, datasets, pipelines, and team management.
Features
- Python 3.8+ Support: Compatible with Python 3.8 and later versions
- Type Safety: Full type annotations with mypy support
- Async/Await: Built-in support for asynchronous operations
- Team-scoped Operations: Automatic filtering and scoping to your team
- Resource Management: Agents, datasets, pipelines, files, and users
- Error Handling: Comprehensive exception handling for different error scenarios
- Rate Limiting: Built-in rate limit handling and retry logic
- Modern Tooling: Uses PDM for dependency management, Ruff for linting, and pytest for testing
Installation
pip install moderatelyai-sdk
Quick Start
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"
)
# Use the client - all operations are automatically scoped to your team
users = client.users.list()
dataset = client.datasets.create(name="My Dataset")
agents = client.agents.list()
Usage
Working with Datasets
from moderatelyai_sdk import ModeratelyAI
client = ModeratelyAI(team_id="your-team-id", api_key="your-api-key")
# Create a dataset
dataset = client.datasets.create(
name="Customer Data",
description="Customer interaction dataset"
)
# Upload data to the dataset
version = dataset.upload_data("/path/to/data.csv")
print(f"Uploaded version {version.version_no} with {version.row_count} rows")
# List all datasets
datasets = client.datasets.list()
Working with Agents
# List all agents in your team
agents = client.agents.list()
# Create and run an agent execution
execution = client.agent_executions.create(
agent_id="agent_123",
input_data={"query": "Process this data"}
)
Working with Pipelines
# Create a pipeline
pipeline = client.pipelines.create(
name="Document Processing Pipeline",
description="Processes legal documents and extracts key information"
)
# Create a configuration version with workflow logic
config_version = client.pipeline_configuration_versions.create(
pipeline_id=pipeline["pipelineId"],
configuration={
"id": "doc-processor",
"name": "Document Processor",
"version": "1.0.0",
"blocks": {
"input": {
"id": "input",
"type": "input",
"config": {"json_schema": {"type": "object"}}
},
"llm": {
"id": "llm",
"type": "llm",
"config": {
"provider": "anthropic",
"model": "small",
"temperature": 0.2
}
},
"output": {
"id": "output",
"type": "output",
"config": {"name": "results"}
}
}
}
)
# Execute the pipeline
execution = client.pipeline_executions.create(
pipeline_configuration_version_id=config_version["pipelineConfigurationVersionId"],
pipeline_input={"documents": ["doc1.pdf", "doc2.pdf"]},
pipeline_input_summary="Process 2 legal documents"
)
# Monitor execution status
status = client.pipeline_executions.retrieve(execution["pipelineExecutionId"])
print(f"Execution status: {status['status']}")
# Get execution results when completed
if status["status"] == "completed":
output = client.pipeline_executions.get_output(execution["pipelineExecutionId"])
print(f"Results: {output}")
# List all pipelines in your team
pipelines = client.pipelines.list()
Using Context Manager
from moderatelyai_sdk import ModeratelyAI
with ModeratelyAI(team_id="your-team-id", api_key="your-api-key") as client:
users = client.users.list()
print(f"Found {len(users)} users")
Error Handling
from moderatelyai_sdk import ModeratelyAI, APIError, AuthenticationError
client = ModeratelyAI(team_id="your-team-id", api_key="your-api-key")
try:
dataset = client.datasets.create(name="Test Dataset")
except AuthenticationError:
print("Invalid API key")
except APIError as e:
print(f"API error: {e}")
if hasattr(e, 'status_code'):
print(f"Status code: {e.status_code}")
Configuration
The client can be configured with various options:
client = ModeratelyAI(
team_id="your-team-id",
api_key="your-api-key",
base_url="https://api.moderately.ai", # Custom API endpoint
timeout=30, # Request timeout in seconds
max_retries=3 # Maximum retry attempts
)
Development
This project uses PDM for dependency management. To set up the development environment:
# Install PDM
pip install pdm
# Install dependencies
pdm install
# Install pre-commit hooks
pdm run pre-commit install
# Run tests
pdm run pytest
# Run linting
pdm run ruff check .
pdm run ruff format .
# Type checking
pdm run mypy src/
API Reference
ModeratelyAI
The main client class for interacting with the Moderately AI API.
Resource Groups
client.users: Manage users in your teamclient.teams: Manage team settings and informationclient.agents: Manage AI agentsclient.agent_executions: Create and monitor agent executionsclient.datasets: Manage datasets with rich functionality (upload, download, schema management)client.pipelines: Manage pipeline metadata (create, update, delete pipelines)client.pipeline_configuration_versions: Manage pipeline workflow configurations and logicclient.pipeline_executions: Execute pipelines and monitor execution statusclient.files: Upload and manage files
Exceptions
ModeratelyAIError: Base exception classAPIError: Raised for API-related errorsAuthenticationError: Raised for authentication failuresConflictError: Raised for resource conflictsNotFoundError: Raised when resources are not foundRateLimitError: Raised when rate limits are exceededTimeoutError: Raised for request timeoutsUnprocessableEntityError: Raised for validation errorsValidationError: Raised for input validation errors
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For questions and support, please visit our GitHub repository or contact us at sdk@moderately.ai.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moderatelyai_sdk-0.2.2.tar.gz.
File metadata
- Download URL: moderatelyai_sdk-0.2.2.tar.gz
- Upload date:
- Size: 54.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.25.5 CPython/3.11.12 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc2597e2120f40d8d097f7a3dda3f34ac4e3fda933098825180b931755402db6
|
|
| MD5 |
f818399b8bc576b3e98084ddf7806686
|
|
| BLAKE2b-256 |
fddb4a1a8aecdf4be667c83c89b8ee6a664affb75571fb23bff783b87fe29c44
|
File details
Details for the file moderatelyai_sdk-0.2.2-py3-none-any.whl.
File metadata
- Download URL: moderatelyai_sdk-0.2.2-py3-none-any.whl
- Upload date:
- Size: 89.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.25.5 CPython/3.11.12 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5789e595b27fb3814468e7fdc4103a3b1bbfb1f861d72807422131a5ed9933c
|
|
| MD5 |
b45ba17033b912d4fe33a8d36188d96d
|
|
| BLAKE2b-256 |
35bdbcb9269c48958de936ba981519eb10567260e64662fe3950ceb950e155ee
|