Unified Python SDK for building LLM applications across multiple AI providers
Project description
Zhivex AI SDK for Python
Zhivex AI SDK for Python is an async-first SDK for building LLM applications against multiple providers with one shared contract.
It brings the same design goals as the TypeScript Zhivex AI SDK into Python:
- one normalized interface for text generation, streaming, tools, structured output, embeddings, and routing
- thin provider adapters instead of provider-specific app logic everywhere
- portable application code that can switch models and vendors with minimal changes
Why Zhivex AI SDK
Modern AI apps usually start simple and then drift into provider lock-in:
- OpenAI requests look one way
- Anthropic uses a different message format
- Gemini and Vertex differ again
- local and routed setups add yet another layer
Zhivex AI SDK gives you a common language model contract so your application code can stay stable while providers change underneath.
Highlights
- Unified
generate_text()andstream_text()primitives - Structured output with
generate_object() - Tool execution across multiple model steps
- Embeddings support where the provider supports it
- Provider factories for hosted and local models
- Gateway routing with fallback support
- Middleware for telemetry, caching, and circuit breaking
- Model catalog helpers for cost and recommendation metadata
Supported Providers
| Provider | Text | Streaming | Tools | Structured Output | Embeddings |
|---|---|---|---|---|---|
| OpenAI | Yes | Yes | Yes | Yes | Yes |
| Azure OpenAI | Yes | Yes | Yes | Yes | Yes |
| Anthropic | Yes | Yes | Yes | Prompted fallback | No |
| Gemini | Yes | Yes | Yes | Yes | Yes |
| Vertex AI | Yes | Yes | Yes | Yes | Yes |
| Bedrock | Yes | No | No | No | No |
| OpenRouter | Yes | Yes | Yes | Yes | Yes |
| Qwen | Yes | Yes | Yes | Yes | Yes |
| Kimi | Yes | Yes | Yes | Yes | Yes |
| Ollama | Yes | Yes | Yes | Yes | Yes |
Installation
For local development with uv:
make dev
If you prefer plain pip:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -e ".[dev]"
When published to PyPI, installation will look like:
pip install zhivex-ai-sdk
Quick Start
import asyncio
from zhivex_ai import create_openai, generate_text
async def main() -> None:
openai = create_openai()
result = await generate_text(
model=openai("gpt-4o-mini"),
prompt="Describe Zhivex AI SDK in one sentence.",
)
print(result.text)
print(result.usage)
asyncio.run(main())
Core API
Text generation
import asyncio
from zhivex_ai import create_anthropic, generate_text
async def main() -> None:
anthropic = create_anthropic()
result = await generate_text(
model=anthropic("claude-3-5-sonnet"),
system="Be concise and technical.",
prompt="What is a provider adapter?",
)
print(result.text)
asyncio.run(main())
Structured output
import asyncio
from pydantic import BaseModel
from zhivex_ai import create_openai, generate_object
class Recipe(BaseModel):
title: str
difficulty: str
async def main() -> None:
openai = create_openai()
result = await generate_object(
model=openai("gpt-4o-mini"),
prompt="Return a compact JSON recipe summary.",
schema=Recipe,
)
print(result.object.model_dump())
asyncio.run(main())
Streaming
import asyncio
from zhivex_ai import create_openai, stream_text
async def main() -> None:
openai = create_openai()
result = stream_text(
model=openai("gpt-4o-mini"),
prompt="Reply in two short sentences.",
)
async for chunk in result.text_stream():
print(chunk, end="")
final = await result.collect()
print("\n", final.finish_reason)
asyncio.run(main())
Gateway fallback routing
import asyncio
from zhivex_ai import (
GatewayConfig,
GatewayMessage,
GatewayModelTarget,
create_anthropic,
create_gateway,
create_openai,
)
async def main() -> None:
gateway = create_gateway(
GatewayConfig(
adapters={
"openai": create_openai(),
"anthropic": create_anthropic(),
}
)
)
result = await gateway.generate(
messages=[GatewayMessage(role="user", content="Say hello in one sentence.")],
primary=GatewayModelTarget(provider="openai", model_id="gpt-4o-mini"),
fallbacks=[GatewayModelTarget(provider="anthropic", model_id="claude-3-5-sonnet")],
)
print(result.text)
print(result.provider_used, result.model_used)
asyncio.run(main())
Provider Factories
The package currently exposes:
create_openai()create_azure_openai()create_anthropic()create_gemini()create_vertex()create_bedrock()create_openrouter()create_qwen()create_kimi()create_ollama()
OpenAI-compatible providers such as OpenRouter, Qwen, Kimi, and Ollama reuse the same normalized adapter model.
Why not use provider SDKs directly?
Using provider SDKs directly is totally reasonable when:
- you only target one provider
- you are comfortable rewriting message, tool, and streaming logic per vendor
- you do not need fallback routing or a shared abstraction layer
Zhivex AI SDK is a better fit when:
- you want one contract across multiple model vendors
- you expect to switch providers over time
- you want tools, structured output, caching, telemetry, and routing to live above the provider layer
- you want application code that reads the same whether the model is OpenAI, Anthropic, Gemini, or local
Middleware
Zhivex AI SDK includes middleware helpers similar to the TypeScript SDK:
wrap_language_model(...)create_telemetry_middleware(...)create_cached_generate_middleware(...)create_in_memory_generate_cache()create_file_generate_cache(...)create_circuit_breaker_middleware(...)
These let you keep cross-cutting concerns outside provider adapters and application prompts.
Examples
Project Status
This project is usable today, but still early.
Current status:
- core generation and streaming primitives are implemented
- major provider adapters are in place
- gateway, catalog, and middleware helpers are included
- test coverage exists for the shared contract and key adapters
What to expect:
- API polish may continue as the Python port matures
- provider-specific behavior may still expand over time
- GitHub Copilot SDK integration is not included yet
Roadmap
Near-term release goals:
- first TestPyPI release
- first public PyPI release
- more adapter coverage tests for Gemini, Vertex, and Bedrock
- API polish and docs cleanup
Potential next additions:
- GitHub Copilot SDK integration
- richer provider capability metadata
- more middleware and transport helpers
- higher-level chat/session utilities
Development
Run local validation with:
make check
Individual commands:
make test
make build
make release-check
make build uses the local .venv without build isolation so it works in restricted environments once make dev has installed the dev toolchain.
Publishing
The repository already includes:
- CI workflow: ci.yml
- TestPyPI workflow: publish-testpypi.yml
- PyPI workflow: publish-pypi.yml
- release guide: RELEASING.md
Before the first public release, confirm:
- the final package name on PyPI
- the
0.1.0release tag and release notes - Trusted Publishing configuration on PyPI and TestPyPI
License
MIT. See LICENSE.
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 zhivex_ai_sdk-0.1.0.tar.gz.
File metadata
- Download URL: zhivex_ai_sdk-0.1.0.tar.gz
- Upload date:
- Size: 31.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2866eac5b800d3dbb30b187aa7c0840b4008a372d225a695bda8ee352a96452f
|
|
| MD5 |
307f9cfac3a271cd14d1830b5fd9286f
|
|
| BLAKE2b-256 |
51ecd40f71b1b6185d1ded69dadb38060f418237212398f860dc1d8a89592f00
|
Provenance
The following attestation bundles were made for zhivex_ai_sdk-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on Zhivex/zhivex-ai-sdk-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zhivex_ai_sdk-0.1.0.tar.gz -
Subject digest:
2866eac5b800d3dbb30b187aa7c0840b4008a372d225a695bda8ee352a96452f - Sigstore transparency entry: 1203562108
- Sigstore integration time:
-
Permalink:
Zhivex/zhivex-ai-sdk-py@1b8115dca239255c182fa5a715f7a6b4ea151072 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Zhivex
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1b8115dca239255c182fa5a715f7a6b4ea151072 -
Trigger Event:
push
-
Statement type:
File details
Details for the file zhivex_ai_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: zhivex_ai_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 41.3 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 |
3804ee8d3726534f362a247039f520ec3a1b0e44265e2ac543a3933d8ed8a047
|
|
| MD5 |
ed9e8041f2cf2cfdb72050f46759b748
|
|
| BLAKE2b-256 |
63de9d8252cae9f8c15f66ff67d426109a3bc9c089832b46d69b64559465456f
|
Provenance
The following attestation bundles were made for zhivex_ai_sdk-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on Zhivex/zhivex-ai-sdk-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zhivex_ai_sdk-0.1.0-py3-none-any.whl -
Subject digest:
3804ee8d3726534f362a247039f520ec3a1b0e44265e2ac543a3933d8ed8a047 - Sigstore transparency entry: 1203562113
- Sigstore integration time:
-
Permalink:
Zhivex/zhivex-ai-sdk-py@1b8115dca239255c182fa5a715f7a6b4ea151072 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Zhivex
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1b8115dca239255c182fa5a715f7a6b4ea151072 -
Trigger Event:
push
-
Statement type: