Official Python SDK for the Ensoul API
Project description
Ensoul Python SDK
Python client library for the Ensoul personality simulation API.
Installation
pip install ensoul
Quick Start
from ensoul import Ensoul
client = Ensoul(api_key="your-api-key")
# Create a persona
persona = client.personas.create(name="Alex", domain="my_domain")
# Send a chat message
response = client.chat.send(persona.id, "Hello, who are you?")
print(response.response)
The API key can also be set via the ENSOUL_API_KEY environment variable, in which case no api_key argument is needed.
The client supports context managers for automatic cleanup:
with Ensoul(api_key="your-api-key") as client:
persona = client.personas.get("persona-id")
Async Usage
import asyncio
from ensoul import AsyncEnsoul
async def main():
async with AsyncEnsoul(api_key="your-api-key") as client:
persona = await client.personas.create(name="Jordan", domain="my_domain")
response = await client.chat.send(persona.id, "Tell me about yourself.")
print(response.response)
asyncio.run(main())
Streaming
Chat supports server-sent events (SSE) for streaming responses:
from ensoul import Ensoul
from ensoul.streaming import parse_chat_event
client = Ensoul(api_key="your-api-key")
stream = client.chat.stream("persona-id", "What do you think about music?")
for event in stream.events():
parsed = parse_chat_event(event)
if not parsed.is_final:
print(parsed.chunk, end="", flush=True)
else:
print() # newline after stream completes
The async client returns an AsyncSSEStream that works the same way with async for.
Pagination
List endpoints return a SyncPage (or AsyncPage) object. Use .auto_paging_iter() to iterate through all pages automatically:
# Manual page access
page = client.personas.list(per_page=50)
print(page.items) # current page items
print(page.total) # total count across all pages
# Automatic pagination — fetches subsequent pages as needed
for persona in client.personas.list().auto_paging_iter():
print(persona.name)
Async pagination works the same way with async for.
Error Handling
All SDK errors inherit from EnsoulError. HTTP errors are subclasses of APIError:
from ensoul.errors import (
EnsoulError,
APIError,
AuthenticationError,
AuthorizationError,
NotFoundError,
RateLimitError,
ValidationError,
ConflictError,
ServerError,
)
try:
persona = client.personas.get("nonexistent-id")
except NotFoundError:
print("Persona not found")
except AuthenticationError:
print("Invalid or missing API key")
except RateLimitError:
print("Rate limit exceeded — back off and retry")
except APIError as e:
print(f"API error {e.status_code}: {e.message}")
Configuration
The client reads two environment variables as defaults:
| Variable | Purpose |
|---|---|
ENSOUL_API_KEY |
API key (avoids passing api_key= in code) |
ENSOUL_BASE_URL |
API base URL (default: https://api.ensoul-ai.com) |
Demo API — the current hosted demo is available at:
export ENSOUL_BASE_URL="https://api.demo.ensoul-ai.com"
export ENSOUL_API_KEY="your-api-key"
With these set, Ensoul() connects to the demo with no constructor arguments.
You can also pass the base URL explicitly:
client = Ensoul(api_key="ens_...", base_url="https://api.demo.ensoul-ai.com")
Authentication
API key (recommended):
client = Ensoul(api_key="ens_...")
# or set ENSOUL_API_KEY in the environment
client = Ensoul()
Bearer token:
client = Ensoul(bearer_token="eyJ...")
OAuth2 token exchange (client credentials flow):
token_response = client.auth.token(
grant_type="client_credentials",
client_id="your-client-id",
client_secret="your-client-secret",
)
authed_client = Ensoul(bearer_token=token_response.access_token)
Resources
| Namespace | Description |
|---|---|
client.personas |
CRUD, list (paginated), batch create, personality vectors, filters, connections |
client.chat |
Send messages, streaming SSE, conversation history |
client.domains |
Domain configuration management |
client.simulations |
Time-based evolution simulations |
client.aggregate |
Aggregate queries with streaming results |
client.memory |
Persona memory management |
client.sessions |
Hierarchical session orchestration |
client.frameworks |
Framework management |
client.auth |
OAuth2 token exchange and API key management |
client.health |
Service health checks |
client.info |
Server info and configuration |
Requirements
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 ensoul-0.1.0.tar.gz.
File metadata
- Download URL: ensoul-0.1.0.tar.gz
- Upload date:
- Size: 68.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a56393956a8ca252590da2383a72b46a63fede4413f099e6f0a15ecb4e70770f
|
|
| MD5 |
2a4e5347b123499f479e01923d83860e
|
|
| BLAKE2b-256 |
ad8d190540fc2274fb1fc26852487856b6496e4809bd10097e42ee485549d325
|
File details
Details for the file ensoul-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ensoul-0.1.0-py3-none-any.whl
- Upload date:
- Size: 43.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31c7ee182878dc5ca8b215b3e75bb8e63313ec2cb9d662d99484e9875ffcba85
|
|
| MD5 |
a7c01b550f94a73ab9726a3a81c1e709
|
|
| BLAKE2b-256 |
a765ac8fefd6b036768c0e8c8b8a46bb392dfa7eb649f104ccb5b2786bf0d7e1
|