Python SDK for SovereignEG — Sovereign AI Platform
Project description
SovereignEG Python SDK
Official Python client for the SovereignEG sovereign AI platform.
Install
pip install sovereigneg
Quick Start
from sovereigneg import SovereignEG
client = SovereignEG(
api_key="sk-seg-your-key-here",
base_url="http://localhost:8000", # or https://api.sovereigneg.ai
)
# Chat
response = client.chat("What is sovereign AI?")
print(response.content)
# Streaming
for token in client.chat("Tell me about Egypt", stream=True):
print(token, end="", flush=True)
# Embeddings
emb = client.embed("Hello world")
print(f"Dimension: {len(emb.embedding)}")
Examples
See the examples/ folder:
chat.py— basic chat completionstreaming.py— real-time token streamingembeddings.py— generate embeddingsrag.py— upload documents and search
Rate Limiting
All API responses include rate limit headers:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 42
X-RateLimit-Reset: 1771234567
When rate limited (HTTP 429), the response includes a Retry-After header and structured error:
{
"error": {
"type": "rate_limit_exceeded",
"message": "Rate limit exceeded. Your developer plan allows 60 requests per minute.",
"plan": "developer",
"limit": 60,
"retry_after": 3.2
}
}
Handling rate limits in your code:
import time
from sovereigneg import SovereignEG
client = SovereignEG(api_key="sk-seg-...")
try:
response = client.chat("Hello!")
except Exception as e:
if hasattr(e, 'status_code') and e.status_code == 429:
retry_after = e.response.headers.get("Retry-After", "1")
time.sleep(float(retry_after))
response = client.chat("Hello!") # Retry
Per-Plan Limits
| Plan | Chat RPM | Embeddings RPM | Burst | Concurrent |
|---|---|---|---|---|
| Free (Student) | 10 | 20 | 3 | 1 |
| Developer | 60 | 120 | 10 | 3 |
| SME (Business) | 200 | 500 | 30 | 10 |
Automatic Retries
The SDK automatically retries on transient errors (429 rate limits, 5xx server errors, network timeouts) with exponential backoff:
# Default: 2 retries. Customize:
client = SovereignEG(api_key="sk-seg-...", max_retries=5)
The SDK respects Retry-After headers from the server, so rate-limited requests wait the appropriate duration before retrying.
API Reference
SovereignEG(api_key, base_url, timeout, tenant_id, max_retries)
Create a client instance. max_retries defaults to 2.
client.chat(message, model, system, temperature, max_tokens, stream)
Send a chat completion. Returns ChatCompletion or ChatStream.
client.embed(input, model)
Generate embeddings. Returns Embedding with .embedding or .embeddings.
client.upload(file_path, tenant_id)
Upload a document for RAG. Returns DocumentUpload.
Document ACL — Control who can access uploaded documents:
# Default: all tenant members can read
client.upload("report.pdf", tenant_id="your-tenant-id")
# Group-restricted: only engineering and finance groups
client.upload("report.pdf", tenant_id="your-tenant-id",
acl_level="group", acl_groups="engineering,finance")
# Private: only the uploader can read
client.upload("report.pdf", tenant_id="your-tenant-id", acl_level="private")
ACL levels:
tenant(default) — all members of the tenant can readgroup— only members of the specified groups can readprivate— only the document owner (uploader) can read
ACL is enforced on search, list, and delete. Admins can always access all documents.
client.search(query, top_k, tenant_id)
Search documents. Returns list of SearchResult. Results are ACL-filtered — only documents the caller has permission to see are returned.
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 sovereigneg-0.1.0.tar.gz.
File metadata
- Download URL: sovereigneg-0.1.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1edb76826bd1e413549dde5c3f4899998b05b8f2c060f1e5bf47f94ea8cc703d
|
|
| MD5 |
8051fb7e78fdb62c157e9e0defd2c340
|
|
| BLAKE2b-256 |
ea4217f553772f526c1949508d4f3fc8e0355d300a862ffd68d4af5431d3b86d
|
File details
Details for the file sovereigneg-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sovereigneg-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1aa6d563034b247bdbf55d930e64bf1d84249e1cbdf46a404775f12fecca5fa5
|
|
| MD5 |
8e42ab530e3a7b0f259e0e5e406b1f61
|
|
| BLAKE2b-256 |
3a6d9e3dc5ccf6f41851ccc6c9ce5804d238db639d4eee0c5d5d4a4aca0b1051
|