Official Python SDK for the Ciralgo Platform API
Project description
Ciralgo Python SDK
Official Python SDK for the Ciralgo Platform API.
Version: 1.1.0 (mirrors openapi.json info.version).
Install
pip install ciralgo
Requires Python 3.9+.
Quickstart
from ciralgo import Client
client = Client(api_key="sk-cg-...") # or set CIRALGO_API_KEY in your env
response = client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Say hello."}],
)
print(response["choices"][0]["message"]["content"])
Authentication
The SDK reads the API key from (in order):
- The
api_key=argument toClient(...)orAsyncClient(...). - The
CIRALGO_API_KEYenvironment variable.
If neither is set, AuthenticationError is raised at construction time.
The optional CIRALGO_BASE_URL env var overrides the default https://api.ciralgo.com. This is useful for staging or for self-hosted Ciralgo deployments.
Endpoints
The four public proxy operations from the Ciralgo OpenAPI spec (v1.1.0):
Chat completions
response = client.chat.completions.create(
model="anthropic/claude-sonnet-4-6",
messages=[
{"role": "system", "content": "You are a finance compliance assistant."},
{"role": "user", "content": "Summarise EU AI Act Article 15."},
],
temperature=0.2,
max_tokens=400,
tags={"project": "ai-act-summariser", "env": "prod"},
)
Streaming chat completions
for chunk in client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Stream me a haiku."}],
stream=True,
):
delta = chunk["choices"][0]["delta"].get("content", "")
print(delta, end="", flush=True)
Embeddings
embedding = client.embeddings.create(
model="openai/text-embedding-3-small",
input="EU AI Act Article 15 covers accuracy, robustness and cybersecurity.",
)
print(len(embedding["data"][0]["embedding"])) # → vector dimension
Usage
usage = client.usage.get(from_date="2026-06-01", to_date="2026-06-30")
print(usage["total_cost_usd"], usage["calls"])
Anthropic Messages
response = client.anthropic.messages_create(
model="anthropic/claude-sonnet-4-6",
max_tokens=400,
system="You are an EU compliance assistant.",
messages=[{"role": "user", "content": "What is GDPR Article 32?"}],
)
print(response["content"][0]["text"])
Error handling
The SDK maps HTTP status codes to typed exceptions. Catch the specific class:
from ciralgo import Client
from ciralgo.errors import RateLimitError, UpstreamError, AuthenticationError
try:
response = client.chat.completions.create(...)
except RateLimitError as e:
time.sleep(e.retry_after or 5)
# retry
except UpstreamError as e:
# upstream LLM provider 5xx, pick a different model
...
except AuthenticationError:
# rotate / re-issue the key
raise
Every exception carries:
code: stable string error code from the API envelope (e.g.rate_limit_exceeded)message: human-readabletrace_id: pass this to Ciralgo support to look up the request server-sidestatus_code: HTTP statusretry_after: only set on 429
Async
import asyncio
from ciralgo import AsyncClient
async def main():
async with AsyncClient() as client:
# NOTE: async surface in v1.1.0 is the client construction +
# close lifecycle. Full async parity for chat / embeddings ships
# in v1.2.0.
pass
asyncio.run(main())
Migration to a codegen client
The current client is hand-written. A codegen-based replacement is viable using openapi-python-client against the published Ciralgo OpenAPI spec. The hand-written client gives us control over:
- Streaming semantics (
stream=Truereturning an iterator). - The
X-Ciralgo-Tagsheader marshalling. - The typed exception hierarchy (codegen produces a single error class).
A future major bump (v2.0.0) can switch to codegen if the trade-offs
change.
Development
From the SDK repo root:
pip install -e ".[dev]"
pytest
ruff check src
mypy src
Publishing
Publishing to PyPI is handled by a GitHub Actions workflow triggered on
tags of the form sdk-py-v*. The workflow uses PyPI Trusted Publishing
(OIDC). No long-lived API token is stored in CI secrets.
The engineer-facing release runbook (version bump, tag push, environment approval, troubleshooting) is at docs/publish-runbook.md.
License
Apache-2.0
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 ciralgo-1.1.0.tar.gz.
File metadata
- Download URL: ciralgo-1.1.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86fe77f0fe68d7f8eede3fc11d22e5cc6b13388bbc44277b6fb83c380211bb3f
|
|
| MD5 |
b93a854e8bf11e22429f940fa24dac22
|
|
| BLAKE2b-256 |
1dca9d52778da621fa524d7e6de34f813925c959e68ad677802dc9239e1023a1
|
File details
Details for the file ciralgo-1.1.0-py3-none-any.whl.
File metadata
- Download URL: ciralgo-1.1.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3dd30fff47d3372c45547fdffb7eaf057153a45c4be1273f3b3958a54f579b7
|
|
| MD5 |
deeb9ec9a752034ff9e7804c641801ca
|
|
| BLAKE2b-256 |
bd26a5d328f6e30b91bb682f06a67cf595b35f85dd5714d95010bcf9b879e5bc
|