Skip to main content

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 completion
  • streaming.py — real-time token streaming
  • embeddings.py — generate embeddings
  • rag.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 read
  • group — only members of the specified groups can read
  • private — 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.

Metadata

Release files for sovereigneg 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sovereigneg 0.1.0
File Size Uploaded Provenance Actions
sovereigneg-0.1.0.tar.gz 10.0 kB Without provenance Details for sovereigneg-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sovereigneg 0.1.0
File Interpreter ABI Platform Actions
sovereigneg-0.1.0-py3-none-any.whl Python 3 none any Details for sovereigneg-0.1.0-py3-none-any.whl

Total release size: 18.0 kB

Release files / sovereigneg-0.1.0.tar.gz

Download URL sovereigneg-0.1.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1edb76826bd1e413549dde5c3f4899998b05b8f2c060f1e5bf47f94ea8cc703d
BLAKE2b-256 checksum
How to use checksums
ea4217f553772f526c1949508d4f3fc8e0355d300a862ffd68d4af5431d3b86d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / sovereigneg-0.1.0-py3-none-any.whl

Download URL sovereigneg-0.1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1aa6d563034b247bdbf55d930e64bf1d84249e1cbdf46a404775f12fecca5fa5
BLAKE2b-256 checksum
How to use checksums
3a6d9e3dc5ccf6f41851ccc6c9ce5804d238db639d4eee0c5d5d4a4aca0b1051
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for sovereigneg 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page