Plural
Unified LLM routing with first-class traces, environments, and benchmarks.
Plural is for builders putting AI into products. Start with an OpenRouter-style multi-provider router. Keep going with the thing OpenRouter does not give you: a single Trace object shared by production traffic and RL-style environments — so you can understand prompts, build datasets, run benchmarks, and eventually autoroute to the best model for your data.
flowchart LR
App[Your app] --> Client[Plural]
Env[Environment] --> Client
Client --> Trace[Trace]
Trace --> TraceDataset[TraceDataset / Dataset]
TraceDataset --> Training[Training / export]
TaskDataset[TaskDataset] --> Bench[Benchmark]
Env --> Bench
Install
pip install plural
# optional OpenTelemetry exporter
pip install "plural[otel]"
Quickstart
Set PLURAL_API_KEY, then use the client like the OpenAI SDK:
export PLURAL_API_KEY=plural-...
from plural import Client, Message
client = Client()
assert client.is_authenticated()
response = client.chat(
model="openai/gpt-4o-mini",
messages=[Message(role="user", content="Hello from plural")],
models=["anthropic/claude-sonnet-4"], # optional fallbacks
)
print(response.text)
client.close()
# Traces → .plural/traces.jsonl
Sync a local environment, trace, or benchmark report with client.push(x).
env.push(client) is an alias. Create hosted agents with
client.agents.create(...) — they are not pushable. A project API key already
knows the project; an account key needs project= or PLURAL_PROJECT.
Optional BYOK (pass your own upstream keys explicitly):
import os
from plural import Client
client = Client(providers={"openai": os.environ["OPENAI_API_KEY"]})
Four pillars
| Pillar | What you get |
|---|---|
| Router | Sync/async chat + streaming, fallbacks, retries, cost accounting, model catalog |
| Tracing | JSONL / SQLite / OTel sinks, redaction, sampling, late labels, attempt history |
| Environments | Versioned Environment subclass + tools + scorers → one episode Trace |
| Benchmarks | Environment × models → markdown/JSON report with win rates |
Environments in 30 seconds
from plural import Environment, TaskData
env = Environment(name="support-triage", version="0.1.0")
@env.tool
def lookup_order(order_id: str) -> dict:
"""Look up an order."""
return {"status": "shipped"}
@env.scorer(weight=1.0)
def ok(rollout) -> float:
return 1.0 if "shipped" in (rollout.response.text or "").lower() else 0.0
@env.tasks
def tasks():
yield TaskData(task_id="1", input="Where is order A?")
rollout = env.rollout(next(env.iter_tasks()), client, model="openai/gpt-4o-mini")
print(rollout.trace.outcome)
Tool environments use the built-in action dispatch. For scalar or custom text
actions, override apply_action() and return ActionResult; step() remains
framework-owned so lifecycle and trace invariants are always recorded.
Docs
Full documentation: concept pages, guides, and generated API reference.
- Trace schema stability:
schemas/trace.v1.json - Routing walkthrough:
examples/routing/(also under docs → Guides)
Development
uv sync --group dev --group docs
uv run pytest -m "not live"
uv run ruff check .
uv run mypy src/plural
uv run mkdocs build --strict
License
Apache-2.0
Release files for plural 0.7.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| plural-0.7.2.tar.gz | 281.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| plural-0.7.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 436.7 kB
Release files / plural-0.7.2.tar.gz
| Download URL | plural-0.7.2.tar.gz |
|---|---|
| Size | 281.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8c7b354e0b03ec37f5a083fcca8aa4ace65ee81c392df9cc5bcc7e81ff40fd1
|
|
BLAKE2b-256 checksum How to use checksums |
2e0a89e6c847527b9ce30c2033c4cc438fe04fa51c779ed58130acfc8e0c372d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 2, 2026.
Transparency logRelease files / plural-0.7.2-py3-none-any.whl
| Download URL | plural-0.7.2-py3-none-any.whl |
|---|---|
| Size | 155.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a5b295c362d885a55e95828ad2e6c10a6899393bd1139b6d7fa1b414b855978d
|
|
BLAKE2b-256 checksum How to use checksums |
8c279ef6b209ba98b304649bc8991cf62a2b8f4faff849e4ac4f0febd3b4a3c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 2, 2026.
Transparency log