Python SDK for interacting with the CirtusAI backend API.
Project description
CirtusAI Python SDK
CirtusAI provides a lightweight Python wrapper around the CirtusAI backend API. It enables:
- Exchanging API keys for access tokens;
- Reading the identity linked to an API key;
- Filtering mailbox content (folder, sender, unread flag, date range);
- Sending messages with optional Base64 attachments;
- Consistent error handling and session management.
Prerequisite: the backend must expose
/api/auth/api-key/loginand allow JWT access to mail endpoints.
Installation
pip install cirtusai
For local development inside this repository:
pip install -e ./sdk
Quick Start
from datetime import datetime, timedelta, timezone
from cirtusai import CirtusClient
client = CirtusClient(
base_url="https://api.cirtusai.com",
api_key="cai_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
)
# Read identity information
identity = client.get_identity()
print(identity.id, identity.credentials.signature_key)
for asset in identity.assets:
print(asset.type, asset.address)
# Fetch unread messages from the past week
now = datetime.now(timezone.utc)
messages = client.list_messages(
unread=True,
start_date=now - timedelta(days=7),
)
for msg in messages:
print(msg.subject, msg.created_at)
# Send a message
client.send_message(
to=["teammate@example.com"],
subject="Weekly summary",
content="Please see attached report.",
)
Production vs local: Use
https://api.cirtusai.comfor production traffic. During development you can pointbase_urlat your sandbox instance (for examplehttp://127.0.0.1:8000) and keep the defaults forapi_prefix(/api) and timeouts.
Configuration
CirtusClient accepts a few optional parameters for advanced scenarios:
api_prefix: change the API namespace if your deployment serves the backend under a different path.timeout: override the default 10s request timeout.session: supply a pre-configuredrequests.Session(proxy settings, retries, etc.).auto_authenticate: set toFalsewhen you need to defer authentication and callauthenticate()manually.
Every public method ensures a valid token is present and will automatically re-authenticate if the server indicates expiration.
Filtering Mail
list_messages supports inline keyword arguments or an explicit MessageFilters object if you prefer strong typing:
from datetime import datetime, timezone
from cirtusai import CirtusClient, MessageFilters
client = CirtusClient(base_url="https://api.cirtusai.com", api_key="cai_...")
last_week = datetime.now(timezone.utc) - timedelta(days=7)
filters = MessageFilters(folder="inbox", unread=True, start_date=last_week, limit=50)
messages = client.list_messages(filters=filters)
You can mix and match: passing folder, sender, unread, start_date, end_date, or limit directly to list_messages will automatically build the same filter payload.
Attachments
Attach Base64 encoded content along with file metadata. You can optionally supply content_type to hint MIME information to downstream systems:
import base64
from cirtusai import Attachment, CirtusClient
client = CirtusClient(base_url="https://api.cirtusai.com", api_key="cai_...")
content = base64.b64encode(b"example").decode()
attachment = Attachment(
filename="demo.txt",
content=content,
size=len(content),
content_type="text/plain",
)
client.send_message(
to=["recipient@example.com"],
subject="Demo",
content="Sample with attachment",
attachments=[attachment],
)
Read State & Cleanup
The client exposes helpers for day-to-day mailbox maintenance:
client.set_read_state(ids=[101, 102], unread=False)
client.delete_messages(ids=[203, 204])
Both methods accept any iterable of numeric message IDs and raise if you accidentally pass an empty list so you do not trigger no-op API calls.
Error Handling
The SDK raises a small hierarchy of exceptions:
AuthenticationError: API key invalid or session expired;APIError: non-2xx responses with structured error details;CirtusSDKError: networking or client side failures.
from cirtusai import AuthenticationError, APIError
try:
client.list_messages()
except AuthenticationError:
client.authenticate(force=True)
except APIError as exc:
print("Request failed", exc.status_code, exc.detail)
Tests
pytest
Tests rely on unittest.mock to stub HTTP behaviour and can run in CI without network access.
Contributing
- Fork and clone the repository;
- Install dependencies:
pip install -e ./sdk[dev]; - Ensure
pytestpasses before submitting pull requests.
Project details
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 cirtusai-0.1.1.tar.gz.
File metadata
- Download URL: cirtusai-0.1.1.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbc0f4ff4e87d0ae78dfcbd1afa0b5d3fe3f34049783bf5f4e9efa92afe46696
|
|
| MD5 |
c567a8c876294d45418712bfc275c5e8
|
|
| BLAKE2b-256 |
8882f5174f4a724ca012cc3942988ba94389d8d8f597e1e31a6fa36c7aca00e5
|
Provenance
The following attestation bundles were made for cirtusai-0.1.1.tar.gz:
Publisher:
publish.yml on CirtusAI/Cirtus-SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cirtusai-0.1.1.tar.gz -
Subject digest:
dbc0f4ff4e87d0ae78dfcbd1afa0b5d3fe3f34049783bf5f4e9efa92afe46696 - Sigstore transparency entry: 702347781
- Sigstore integration time:
-
Permalink:
CirtusAI/Cirtus-SDK@3d70b4f5701c8b781d289c030e186724c5291e02 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/CirtusAI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3d70b4f5701c8b781d289c030e186724c5291e02 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cirtusai-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cirtusai-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2e68a132af2fc7c1950f33263e19eb0616a8a626eedbce5cff19d782e139b8e
|
|
| MD5 |
3947db62bfc6c18cba32f9ae9785199f
|
|
| BLAKE2b-256 |
f5e182aee028e2a7bc7a9c640ad59681edec657fce8a3d80bf292930b8fb5b30
|
Provenance
The following attestation bundles were made for cirtusai-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on CirtusAI/Cirtus-SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cirtusai-0.1.1-py3-none-any.whl -
Subject digest:
b2e68a132af2fc7c1950f33263e19eb0616a8a626eedbce5cff19d782e139b8e - Sigstore transparency entry: 702347783
- Sigstore integration time:
-
Permalink:
CirtusAI/Cirtus-SDK@3d70b4f5701c8b781d289c030e186724c5291e02 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/CirtusAI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3d70b4f5701c8b781d289c030e186724c5291e02 -
Trigger Event:
push
-
Statement type: