casual-llm
Lightweight LLM provider abstraction with standardized message models.
Part of the "casual" ecosystem of lightweight AI tools.
Upgrading from v0.4.x? See the Migration Guide for breaking changes.
Features
- Client/Model Separation - Configure API connections once, create multiple models
- Protocol-based - Uses
typing.Protocol, no inheritance required - Multi-provider - Works with OpenAI, Anthropic (Claude), Ollama, or your custom provider
- Lightweight - Minimal dependencies (pydantic, httpx)
- Async-first - Built for modern async Python
- Type-safe - Full type hints with py.typed marker
- OpenAI-compatible - Standard message format used across the industry
- Tool calling - First-class support for function/tool calling
- Per-model usage tracking - Track token usage per model for cost monitoring
- Vision support - Send images to vision-capable models
- Streaming - Stream responses in real-time with
AsyncIterator
Installation
# Core only (pydantic + httpx)
uv add casual-llm
# With specific providers
uv add casual-llm[ollama]
uv add casual-llm[openai]
uv add casual-llm[anthropic]
# With all providers
uv add casual-llm[ollama,openai,anthropic]
# Or using pip
pip install casual-llm[openai,anthropic]
Quick Start
from casual_llm import OpenAIClient, Model, UserMessage
# Create client (works with OpenAI, OpenRouter, LM Studio, etc.)
client = OpenAIClient(
api_key="sk-...", # or set OPENAI_API_KEY env var
base_url="https://openrouter.ai/api/v1", # optional, omit for OpenAI
)
# Create model
model = Model(client, "gpt-4o-mini")
# Generate response
response = await model.chat([UserMessage(content="Hello!")])
print(response.content)
More examples:
- Quick Start Guide - Ollama, Anthropic, and more
- Vision Guide - Send images to models
- Streaming Guide - Real-time responses
- Advanced Usage - Custom clients, configuration classes
- API Reference - Full API documentation
- Examples Directory - Complete working examples
Message Models
casual-llm provides OpenAI-compatible message models that work with any provider:
from casual_llm import (
UserMessage,
AssistantMessage,
SystemMessage,
ToolResultMessage,
TextContent,
ImageContent,
)
# System message (sets behavior)
system_msg = SystemMessage(content="You are a helpful assistant.")
# User message (simple text)
user_msg = UserMessage(content="Hello!")
# User message (multimodal - text + image)
vision_msg = UserMessage(
content=[
TextContent(text="What's in this image?"),
ImageContent(source="https://example.com/image.jpg"),
]
)
# Assistant message (response from LLM)
assistant_msg = AssistantMessage(content="I'll help you with that.")
# Tool result message (after executing a tool)
tool_msg = ToolResultMessage(
name="get_weather",
tool_call_id="call_123",
content='{"temp": 20, "condition": "sunny"}'
)
Why casual-llm?
| Feature | casual-llm | LangChain | litellm |
|---|---|---|---|
| Dependencies | 2 core (pydantic, httpx) | 100+ | 50+ |
| Protocol-based | Yes | No | No |
| Type-safe | Full typing | Partial | Partial |
| Message models | Included | Separate | None |
| Multi-model sharing | Yes | No | Yes |
| Vision support | All providers | Yes | Yes |
| Streaming | All providers | Yes | Yes |
| Providers | OpenAI, Anthropic, Ollama | Many | Many |
| Learning curve | Minutes | Hours | Medium |
Use casual-llm when you want:
- Lightweight, focused library (not a framework)
- Protocol-based design (no inheritance)
- Standard message models shared across your codebase
- Efficient multi-model usage with shared connections
- Simple, predictable API
Use LangChain when you need:
- Full-featured framework with chains, agents, RAG
- Massive ecosystem of integrations
- Higher-level abstractions
Part of the casual-* Ecosystem
- casual-mcp - MCP server orchestration and tool calling
- casual-llm (this library) - LLM provider abstraction
- casual-memory - Memory intelligence with conflict detection
All casual-* libraries share the same philosophy: lightweight, protocol-based, easy to use.
Contributing
Contributions welcome! Please see CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE for details.
Links
- GitHub: https://github.com/casualgenius/casual-llm
- PyPI: https://pypi.org/project/casual-llm/
- Issues: https://github.com/casualgenius/casual-llm/issues
- Migration Guide: MIGRATION-0.5.0.md
- casual-mcp: https://github.com/casualgenius/casual-mcp
Metadata
Release files for casual-llm 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| casual_llm-0.8.0.tar.gz | 60.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| casual_llm-0.8.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 101.1 kB
Release files / casual_llm-0.8.0.tar.gz
| Download URL | casual_llm-0.8.0.tar.gz |
|---|---|
| Size | 60.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a05b89a797f99be831be403cb8e746feae3b1a2600f5b4d764e68d6bab93d531
|
|
BLAKE2b-256 checksum How to use checksums |
9a38b4095415c837f5bb7e89c0e6f33f12c519c323a99bd7795354f9219802c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 27, 2026.
Transparency logRelease files / casual_llm-0.8.0-py3-none-any.whl
| Download URL | casual_llm-0.8.0-py3-none-any.whl |
|---|---|
| Size | 40.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1995495a7434e1f6244763e68db07cef80065e70ba2ce9ea1d15efb910f70b8e
|
|
BLAKE2b-256 checksum How to use checksums |
6b579e7bda8b0be3b69350f4d625c1ddda561cd6ccbc46db3fbf399ae9b004cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 27, 2026.
Transparency logSecurity for casual-llm 0.8.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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for casual_llm-0.8.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 27, 2026.
Transparency logA 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.