Skip to main content

Wrapper4AI

Multi-provider, pluggable LLM wrapper with token counting, history management, streaming, and seamless extensibility.

Unified Python client for OpenAI, Anthropic, Google Gemini, Mistral AI, DeepSeek, AWS Bedrock, Hugging Face, and Perplexity AI.


Features

  • Unified interface for multiple LLM providers
  • Chat history with optional tracking and token trimming
  • Streaming support for all providers
  • Token counting (tiktoken when available)
  • Provider registry — register custom backends via BaseProvider
  • Config from env — API keys and regions from environment variables

Installation

pip install wrapper4ai

Install with optional dependencies for the providers you use:

# One provider
pip install wrapper4ai[openai]

# Multiple
pip install wrapper4ai[openai,anthropic,google,mistral]

# All providers
pip install wrapper4ai[all]

Optional extras: openai, anthropic, google, mistral, bedrock, huggingface, all, dev.


Supported Providers

Provider Default model Optional extra
OpenAI gpt-4o openai
Anthropic claude-sonnet-4-20250514 anthropic
Google gemini-2.0-flash google
Mistral AI mistral-large-latest mistral
DeepSeek deepseek-chat —
AWS Bedrock Claude / Llama / Titan bedrock
Hugging Face HuggingFaceH4/zephyr-7b-beta huggingface
Perplexity sonar-pro —

Usage

Connect and chat

from wrapper4ai import connect

client = connect("openai", "gpt-4o", api_key="sk-...")
response = client.chat("Tell me a joke.")
print(response)

API keys can be set via environment variables (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY, MISTRAL_API_KEY) or passed as api_key=.

Streaming

client = connect("anthropic", "claude-sonnet-4-20250514")
for chunk in client.stream("Write a short poem."):
    print(chunk, end="")

With history

History is kept by default; you can clear it or turn it off per call:

client = connect("openai", "gpt-4o")
client.chat("My name is Alex.")
client.chat("What is my name?")  # uses history
client.chat("Hello!", use_history=False)  # no history update
client.clear_history()

Stateless completion

messages = [
    {"role": "user", "content": "What is 2+2?"},
]
reply = client.complete(messages)  # does not change client history

System prompt and token counting

client = connect("openai", "gpt-4o", system_prompt="You are a helpful assistant.")
client.chat("Hi!")
n = client.count_tokens("Some text")
n = client.count_tokens(client.history)
total = client.total_tokens_used
title = client.generate_title("A long discussion about AI")

List providers and custom backends

from wrapper4ai import list_providers, connect
from wrapper4ai.providers import BaseProvider, register_provider

print(list_providers())  # ['anthropic', 'bedrock', 'deepseek', 'google', ...]

class MyProvider(BaseProvider):
    def generate(self, messages): ...
    def stream(self, messages): ...
    def count_tokens(self, messages): ...

register_provider("my_backend", MyProvider)
client = connect("my_backend", "my-model")

Testing

pip install -e ".[dev]"
PYTHONPATH=. pytest tests/ -v

Tests use a mock provider; no API keys required for the test suite.


License

MIT.

Metadata

Release files for wrapper4ai 0.1.3

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

Source distribution (sdist)

Source distribution for wrapper4ai 0.1.3
File Size Uploaded Provenance
wrapper4ai-0.1.3.tar.gz 15.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 37.5 kB

Release files / wrapper4ai-0.1.3.tar.gz

Download URL wrapper4ai-0.1.3.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c53da08c93b49503a750504addc210932a8a43377d6dcf70c4009fbec270724e
BLAKE2b-256 checksum
How to use checksums
3ef90dd258f55e4ce8bc7914120a0d4c5e7f7af4b5f482a5f358422e94eb7307
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release files / wrapper4ai-0.1.3-py3-none-any.whl

Download URL wrapper4ai-0.1.3-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a89ddc458feb9870e55cc88ad88a913f6f821d1e4b25aa5ff7c4d527a459b36e
BLAKE2b-256 checksum
How to use checksums
9890082e0000afcff9f9831688e091711fc58f96212354c1d6888834fc098f79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Security for wrapper4ai 0.1.3

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.

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