The official Python SDK for Manus AI - Integrate AI agents into your workflows
Project description
Manus Python SDK
Official Python SDK for the Manus AI API.
Features
- 🚀 OpenAI SDK Compatible - Use with the official OpenAI Python SDK
- ⚡ Async Support - Full async/await support with
httpx - 📦 Complete API Coverage - All Manus API endpoints supported
- 🔒 Type Safe - Full type hints and Pydantic models
- 🔄 Streaming - Support for streaming responses
- 📄 File Upload - Easy file upload with presigned URLs
- 🔔 Webhooks - Webhook management and signature verification
Installation
pip install manus-sdk
Or install with optional dependencies:
pip install "manus-sdk[all]"
Quick Start
Using OpenAI SDK (Recommended)
from openai import OpenAI
client = OpenAI(
base_url="https://api.manus.im/v1",
api_key="**", # Placeholder
default_headers={
"API_KEY": "your-manus-api-key",
},
)
# Create a task
response = client.responses.create(
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "What's the weather today?"}
],
}
],
extra_body={
"task_mode": "agent",
"agent_profile": "manus-1.6",
},
)
print(f"Task created: {response.id}")
print(f"Status: {response.status}")
Using Native SDK
from manus import Manus
client = Manus(api_key="your-api-key")
# Create a task via Responses API
response = client.responses.create(
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "Hello, world!"}
],
}
],
extra_body={
"task_mode": "agent",
"agent_profile": "manus-1.6",
},
)
# List projects
projects = client.projects.list()
# Upload a file
file = client.files.create_and_upload(
filename="document.pdf",
file_content="/path/to/file.pdf",
)
API Reference
Tasks
Create and manage AI tasks:
# Create a task
response = client.responses.create(
input=[{"role": "user", "content": [{"type": "input_text", "text": "Hello"}]}],
extra_body={"task_mode": "agent", "agent_profile": "manus-1.6"},
)
# Get task status
task = client.get(f"/tasks/{task_id}", cast_to=object)
# List tasks
tasks = client.get("/v1/tasks", cast_to=object)
Projects
Organize tasks into projects:
# Create a project
project = client.projects.create(
name="My Project",
description="Project description",
instruction="Default instruction for all tasks",
)
# List projects
projects = client.projects.list()
# Get a project
project = client.projects.retrieve(project_id)
# Update a project
project = client.projects.update(
project_id,
name="New Name",
description="Updated description",
)
# Delete a project
client.projects.delete(project_id)
Files
Upload and manage files:
# Create file record and upload in one step
file = client.files.create_and_upload(
filename="document.pdf",
file_content="/path/to/file.pdf",
purpose="assistants",
)
# Or create and upload separately
file_record = client.files.create(filename="document.pdf")
client.files.upload(file_record.id, file_content, file_record.upload_url)
# List files
files = client.files.list()
# Get file details
file = client.files.retrieve(file_id)
# Delete a file
client.files.delete(file_id)
Webhooks
Manage webhook subscriptions:
# Create a webhook
webhook = client.webhooks.create(
url="https://your-server.com/webhook",
events=["task.created", "task.completed", "task.failed"],
)
# List webhooks
webhooks = client.webhooks.list()
# Verify webhook signature
from manus import Webhooks
is_valid = Webhooks.verify_signature(
payload=request.body,
signature=request.headers["X-Manus-Signature"],
secret="your-webhook-secret",
)
Async Usage
import asyncio
from manus import AsyncManus
async def main():
client = AsyncManus(api_key="your-api-key")
# Create a task
response = await client.responses.create(
input=[{"role": "user", "content": [{"type": "input_text", "text": "Hello"}]}],
extra_body={"task_mode": "agent", "agent_profile": "manus-1.6"},
)
# List projects
projects = await client.projects.list()
await client.close()
asyncio.run(main())
Streaming
from manus import Manus
client = Manus(api_key="your-api-key")
# Streaming response
stream = client.chat.completions.create(
model="manus-v1",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Error Handling
from manus import Manus, APIError, RateLimitError, AuthenticationError
client = Manus(api_key="your-api-key")
try:
response = client.responses.create(...)
except AuthenticationError as e:
print(f"Authentication failed: {e}")
except RateLimitError as e:
print(f"Rate limited: {e}")
except APIError as e:
print(f"API error: {e.status_code} - {e}")
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
MANUS_API_KEY |
Your Manus API key | - |
MANUS_BASE_URL |
API base URL | https://api.manus.ai/v1 |
Client Options
client = Manus(
api_key="your-api-key",
base_url="https://api.manus.im/v1",
timeout=600.0, # 10 minutes
max_retries=3,
default_headers={"X-Custom-Header": "value"},
)
Task Statuses
| Status | Description |
|---|---|
running |
Task is being processed |
pending |
Waiting for user input |
completed |
Task finished successfully |
error |
Task failed |
File Management
- Uploaded files are automatically deleted after 48 hours
- Presigned upload URLs expire after 3 minutes
- Supported formats: PDF, DOCX, TXT, MD, CSV, XLSX, images, code files
Examples
See the examples/ directory for complete examples:
basic_usage.py- Basic task creationasync_example.py- Async usagestreaming.py- Streaming responseschat_completion.py- Chat completionsfile_upload.py- File uploadwebhooks.py- Webhook management
Development
Setup
# Clone the repository
git clone https://github.com/manus-im/manus-python-sdk.git
cd manus-python-sdk
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -e ".[dev]"
Testing
# Run all tests
pytest
# Run with coverage
pytest --cov=manus --cov-report=html
# Run specific test file
pytest tests/test_client.py
Linting
# Run ruff
ruff check src/manus tests
# Run mypy
mypy src/manus
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
Support
- Documentation: https://open.manus.im/docs
- API Reference: https://open.manus.im/docs/api-reference
- Issues: https://github.com/manus-im/manus-python-sdk/issues
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 manus_sdk-0.1.0.tar.gz.
File metadata
- Download URL: manus_sdk-0.1.0.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61f18656e350c40f6b926aba5cf0d94ad201f8bca3e952c1d4087541386e543a
|
|
| MD5 |
6fc8eba34f8908c075d126a02c62eff6
|
|
| BLAKE2b-256 |
fab2a4efa92c4076a78f3863fe9917579cfe8e6f65fe8b452c9b01d8b1dae14c
|
File details
Details for the file manus_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: manus_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dbc9be119fa8ea558710cdbc1ea91a93384a373e235c515045b1f3bf425e6f3
|
|
| MD5 |
8e9f50269204c7dd6223659327c806b1
|
|
| BLAKE2b-256 |
86d5f4967555079a526c2f4b43a6b57ead25966f8f041db4da26fd3f76e1b9c6
|