SlimX is a slim, intuitive, lightweight Python library for calling LLMs and building LLM systems.
It is intentionally designed around two clearly separated APIs:
- High-level API (
slimx) — “1‑minute productivity”:llm(...),.stream(...),.json(...), tools, retries. - Low-level API (
slimx.low) — “systems builder primitives”: explicitClient,ChatRequest,Message, provider registry, middleware.
SlimX also supports multiple providers (OpenAI, Anthropic, Ollama) and provider plugins (3rd-party providers without modifying core).
On Debian/Ubuntu you may hit externally-managed-environment (PEP 668) if you try to use system pip.
Use uv, which manages an isolated environment cleanly.
git clone https://github.com/slimx-ai/slimx.git
cd slimx
uv sync --all-extrasunzip slimx_v0_4.zip
cd slimx_v0_4
uv sync --all-extras
uv run python examples/quickstart_openai.py
uv syncreadspyproject.tomland (optionally)uv.lock. Ifuv.lockis present and committed, installs are reproducible.
export OPENAI_API_KEY="..."
# optional:
export OPENAI_BASE_URL="https://api.openai.com/v1"export ANTHROPIC_API_KEY="..."
# optional:
export ANTHROPIC_BASE_URL="https://api.anthropic.com"
export ANTHROPIC_VERSION="2023-06-01"export OLLAMA_BASE_URL="http://localhost:11434"from slimx import llm
m = llm("openai:gpt-4.1-nano", temperature=0.2)
res = m("Write a haiku about fog and streetlights.")
print(res.text)Streaming:
for ev in m.stream("Tell a short story in 5 lines."):
if ev.type == "token":
print(ev.text, end="", flush=True)
print()Tools (auto-loop):
from slimx import llm, tool
@tool
def add(a: int, b: int) -> int:
"Add two integers."
return a + b
m = llm("openai:gpt-4.1-nano", tools=[add], tool_runtime="auto")
print(m("What is 12 + 30?").text)Structured output:
from dataclasses import dataclass
from slimx import llm
@dataclass
class City:
name: str
country: str
m = llm("openai:gpt-4.1-nano")
res = m.json("Paris is in France.", schema=City)
print(res.data)This bundle includes GitHub Actions:
- CI (
.github/workflows/ci.yml) - Docs deploy to GitHub Pages (
docs.yml) - PyPI publish on tag (
publish.yml)
See README.md and docs/ for details.