A lightweight Python library for calling LLMs through a unified interface with built-in caching, retry policies, and session management
Project description
sūtram (సూత్రం)
The thread that connects
A unified Python interface for LLM providers. One thread to connect your code to any language model — with built-in caching, retry policies, and multi-turn session management.
In Sanskrit, sūtram means "thread" or "formula" — the essential connection that holds everything together.
Features
- Unified Provider Interface — One API to call OpenRouter, OpenAI, Anthropic, and more
- Built-in Caching — Avoid redundant API calls with pluggable cache backends
- Retry Policies — Configurable exponential/fixed backoff with status-code filtering
- Multi-turn Sessions — First-class support for conversation history management
- Sync & Async — Full support for both synchronous and asynchronous workflows
- Extensible — Add new providers by subclassing
BaseProvider
Installation
pip install sutram
Quick Start
from sutram import create_provider, Session, DictCache
# Create a provider
provider = create_provider(
name="openrouter",
model="openai/gpt-4",
api_key="your-api-key",
cache=DictCache(),
)
# Single-turn call
response = provider.call_llm("What is the meaning of sūtram?")
print(response)
# Multi-turn conversation
session = Session(system_prompt="You are a helpful assistant.")
session.add_user_message("Hello!")
response = provider.chat(session.get_messages())
session.add_assistant_message(response)
session.add_user_message("Tell me more.")
response = provider.chat(session.get_messages())
Configuration
from sutram import create_provider, DictCache
provider = create_provider(
name="openrouter",
model="openai/gpt-4",
api_key="your-api-key",
max_retries=3,
backoff_factor=1.0,
strategy="exponential",
timeout=120,
retry_on_status=[429, 500, 502, 503, 504],
cache=DictCache(),
)
Adding a Custom Provider
from sutram import BaseProvider, PROVIDER_REGISTRY
class MyProvider(BaseProvider):
def _build_request_body(self, messages: list[dict]) -> dict:
return {"model": self.model, "messages": messages}
def _parse_response(self, data: dict) -> str:
return data["choices"][0]["message"]["content"]
PROVIDER_REGISTRY["myprovider"] = {
"cls": MyProvider,
"base_url": "https://api.myprovider.com/v1/chat",
}
License
MIT
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
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 sutram-0.1.2.tar.gz.
File metadata
- Download URL: sutram-0.1.2.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0304a9f3263be621435d52b95279455a2cb412b2cb98092fa5b22fe06aff3ec1
|
|
| MD5 |
460a895d189819a28b4f1a6c9b930e34
|
|
| BLAKE2b-256 |
eb84665c49570cc00e5d6d804f788e1123b9618eb8d6fc709c8a2d0037543c89
|
File details
Details for the file sutram-0.1.2-py3-none-any.whl.
File metadata
- Download URL: sutram-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4c7c50d4b695262a0546c2b166778360fa82d5421072ba0a5cf83c50393320e
|
|
| MD5 |
e522b4d2ef7311ad0796b5ce1eb6aa7b
|
|
| BLAKE2b-256 |
a64d3e8b8818a382114392d2bc505bf95b01a996eeef5a4fb13fb0533f7b0be7
|