Skip to main content

Official Python SDK for Zaguan CoreX

Project description

๐Ÿš€ Zaguan Python SDK

The official Python SDK for Zaguan CoreX

PyPI version Python 3.8+ License Tests

One API. 15+ Providers. 500+ Models. Infinite Possibilities.

Installation โ€ข Quick Start โ€ข Documentation โ€ข Examples โ€ข Support


๐ŸŒŸ What is Zaguan?

Zaguan CoreX is an enterprise-grade AI gateway that provides unified access to multiple AI providers through a single, OpenAI-compatible API. Think of it as your universal adapter for AI services.

Why Zaguan?

  • ๐Ÿ”Œ One API for Everything - Switch between OpenAI, Anthropic, Google, and 12+ other providers without changing code
  • ๐Ÿ’ฐ Built-in Credits System - Track usage, set limits, and manage costs across all providers
  • ๐ŸŽฏ OpenAI Compatible - Drop-in replacement for OpenAI SDK with zero code changes
  • ๐Ÿš€ Production Ready - Enterprise-grade reliability, monitoring, and support
  • ๐Ÿ”’ Secure & Compliant - SOC 2, GDPR, and HIPAA ready infrastructure

Installation

pip install zaguan-sdk

๐Ÿš€ Quick Start

Basic Chat Completion

from zaguan_sdk import ZaguanClient, ChatRequest, Message

# Initialize the client
client = ZaguanClient(
    base_url="https://api.zaguanai.com",
    api_key="your-api-key"
)

# Simple chat completion
response = client.chat(ChatRequest(
    model="openai/gpt-4o-mini",
    messages=[Message(role="user", content="What is Python?")]
))

print(response.choices[0].message.content)

Streaming Responses

# Stream responses in real-time
for chunk in client.chat_stream(ChatRequest(
    model="openai/gpt-4o-mini",
    messages=[Message(role="user", content="Tell me a story")]
)):
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Async Support

import asyncio
from zaguan_sdk import AsyncZaguanClient

async def main():
    async with AsyncZaguanClient(
        base_url="https://api.zaguanai.com",
        api_key="your-api-key"
    ) as client:
        response = await client.chat(ChatRequest(
            model="anthropic/claude-3-5-sonnet",
            messages=[Message(role="user", content="Hello!")]
        ))
        print(response.choices[0].message.content)

asyncio.run(main())

Multi-Provider Usage

# Switch providers without changing code
models = [
    "openai/gpt-4o",
    "anthropic/claude-3-5-sonnet",
    "google/gemini-2.0-flash",
    "deepseek/deepseek-chat"
]

for model in models:
    response = client.chat(ChatRequest(
        model=model,
        messages=[Message(role="user", content="Hi!")]
    ))
    print(f"{model}: {response.choices[0].message.content}")

โœจ Features

๐ŸŽฏ Core Capabilities

Feature Description
๐Ÿ”„ Sync & Async Both ZaguanClient and AsyncZaguanClient for any use case
๐Ÿ”Œ OpenAI Compatible Drop-in replacement - change 3 lines, keep everything else
๐ŸŒ Multi-Provider Access OpenAI, Anthropic, Google, DeepSeek, and 12+ more
๐Ÿ“ก Streaming Real-time response streaming with cancellation support
๐Ÿ›ก๏ธ Type Safe Full type hints and Pydantic validation for all models
โšก Production Ready Comprehensive error handling, retries, and timeouts

๐Ÿ“ฆ Complete API Coverage

๐Ÿ’ฌ Chat & Completions

  • โœ… Chat completions
  • โœ… Streaming responses
  • โœ… Function calling
  • โœ… Tool use
  • โœ… Vision (multimodal)

๐Ÿง  Embeddings & Search

  • โœ… Text embeddings
  • โœ… Batch embeddings
  • โœ… Semantic search ready

๐ŸŽจ Image Generation

  • โœ… DALL-E 2 & 3
  • โœ… Image editing
  • โœ… Image variations

๐ŸŽ™๏ธ Audio Processing

  • โœ… Speech-to-text (Whisper)
  • โœ… Audio translation
  • โœ… Text-to-speech (6 voices)

๐Ÿ” Content Safety

  • โœ… Content moderation
  • โœ… Policy compliance
  • โœ… Safety scores

๐Ÿ’ฐ Credits & Usage

  • โœ… Balance tracking
  • โœ… Usage history
  • โœ… Cost analytics

๐ŸŽฏ 100% coverage of major OpenAI-compatible endpoints

๐Ÿ“š Examples

Embeddings for Semantic Search

from zaguan_sdk import EmbeddingRequest

# Create embeddings
response = client.create_embeddings(EmbeddingRequest(
    model="openai/text-embedding-3-small",
    input=["Python is great", "I love coding"]
))

for embedding in response.data:
    print(f"Embedding: {embedding.embedding[:5]}...")  # First 5 dimensions

Audio Transcription

# Transcribe audio file
transcription = client.create_transcription(
    file_path="meeting.mp3",
    model="whisper-1",
    language="en"
)
print(transcription.text)

Image Generation

from zaguan_sdk import ImageGenerationRequest

# Generate image with DALL-E
response = client.create_image(ImageGenerationRequest(
    prompt="A serene mountain landscape at sunset",
    model="dall-e-3",
    size="1024x1024",
    quality="hd"
))
print(response.data[0].url)

Content Moderation

from zaguan_sdk import ModerationRequest

# Check content safety
result = client.create_moderation(ModerationRequest(
    input="Your content here"
))

if result.results[0].flagged:
    print("Content flagged:", result.results[0].categories)

๐Ÿ“ More examples in examples/ directory

โœจ Advanced Features

Anthropic Messages API (Native)

Access Anthropic's extended thinking and native API features:

from zaguan_sdk import (
    AnthropicMessagesRequest,
    AnthropicMessage,
    AnthropicThinkingConfig
)

# Use extended thinking for complex reasoning
request = AnthropicMessagesRequest(
    model="anthropic/claude-3-5-sonnet",
    messages=[
        AnthropicMessage(role="user", content="Explain quantum computing")
    ],
    max_tokens=2048,
    thinking=AnthropicThinkingConfig(
        type="enabled",
        budget_tokens=5000  # Internal reasoning budget
    )
)

response = client.messages(request)

# Process thinking and response blocks
for block in response.content:
    if block.type == "thinking":
        print(f"๐Ÿง  Thinking: {block.thinking}")
    elif block.type == "text":
        print(f"๐Ÿ’ฌ Response: {block.text}")

Streaming Utilities

Accumulate streaming responses easily:

from zaguan_sdk import StreamAccumulator

accumulator = StreamAccumulator()

for chunk in client.chat_stream(request):
    accumulator.add_chunk(chunk)
    # Print as we go
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

# Get the complete message
message = accumulator.get_message()

Retry Logic

Built-in retry with exponential backoff:

from zaguan_sdk import RetryConfig, with_retry

retry_config = RetryConfig(
    max_retries=5,
    initial_delay=1.0,
    exponential_base=2.0,
    jitter=True
)

@with_retry(retry_config)
def make_request():
    return client.chat(request)

response = make_request()  # Automatically retries on failures

Observability

Track metrics and logs:

from zaguan_sdk import MetricsCollector, LoggingHook

# Collect metrics
metrics = MetricsCollector()

# After requests...
summary = metrics.get_summary()
print(f"Success rate: {summary['success_rate']:.2%}")
print(f"Average latency: {summary['average_latency_ms']:.2f}ms")
print(f"Total cost: ${summary['total_cost']:.6f}")

๐Ÿ“š Learn more: Advanced Features Guide

๐ŸŒ Supported Providers

Access 15+ AI providers through one unified API:

Provider Models Specialties
OpenAI GPT-4o, GPT-4, GPT-3.5 Chat, embeddings, images, audio
Anthropic Claude 3.5 Sonnet, Opus Long context, analysis
Google Gemini 2.0, Gemini Pro Multimodal, reasoning
DeepSeek DeepSeek-V3, Reasoner Coding, reasoning
Alibaba Qwen 2.5 Multilingual
xAI Grok 2 Real-time data
Perplexity Sonar Search-augmented
Cohere Command R+ Enterprise RAG
Groq Llama 3, Mixtral Ultra-fast inference
And more...

๐Ÿ”— Full provider list: docs/SDK/SDK_PROVIDER_FEATURES.md

๐Ÿ“– Documentation

๐Ÿ“˜ Getting Started

๐ŸŽฏ Advanced Features

๐Ÿ—๏ธ Architecture

๐Ÿงช Development

๐Ÿš€ Migration from OpenAI SDK

Switching from OpenAI SDK? It's just 3 lines:

# Before (OpenAI SDK)
from openai import OpenAI
client = OpenAI(api_key="sk-...")

# After (Zaguan SDK)
from zaguan_sdk import ZaguanClient
client = ZaguanClient(
    base_url="https://api.zaguanai.com",
    api_key="your-zaguan-key"
)

# Everything else stays exactly the same! ๐ŸŽ‰
response = client.chat.completions.create(...)

๐Ÿ› ๏ธ Development

Setup Development Environment

# Clone repository
git clone https://github.com/ZaguanLabs/zaguan-sdk-python.git
cd zaguan-sdk-python

# Install dependencies
pip install -r requirements.txt

# Install in development mode
pip install -e .

Running Tests

# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=zaguan_sdk --cov-report=html

# Run specific test file
pytest tests/test_client.py -v

Building and Publishing

# Build package
make build

# Run tests
make test

# Publish to PyPI (maintainers only)
make publish

๐Ÿค Support

Getting Help

Community

๐Ÿ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

Built with โค๏ธ using:

  • httpx - Modern HTTP client
  • pydantic - Data validation and type safety
  • pytest - Testing framework

โฌ† Back to Top

Made with โค๏ธ by Zaguan Labs

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

zaguan_sdk-0.2.0.tar.gz (37.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zaguan_sdk-0.2.0-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

Details for the file zaguan_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: zaguan_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 37.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for zaguan_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ed37a2753ef86fc551b0a5a64e971b62f7addd3ad9d64a0b845ed1768d7f1a13
MD5 25a6da700602887ef34dcef91f54ef8f
BLAKE2b-256 c518b8c74796f03ae1779dda452b22415bbe9021117b42fcbf436641d4a6a7ad

See more details on using hashes here.

File details

Details for the file zaguan_sdk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: zaguan_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for zaguan_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cda86d1bb33e6335ac5c26c860ea4a0a9973a408a0ff4d37eb6e69876709a136
MD5 3644a8524190535dbcdf0b1fdad3d91d
BLAKE2b-256 ecf5a5ed96ad4e0f049ba0ec513c40fb9c2a1e3c0b9e07bfbd1a1cfcb17016a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page