Skip to main content

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

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.1

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

Source distribution (sdist)

Source distribution for plural 0.7.1
File Size Uploaded
plural-0.7.1.tar.gz 278.1 kB Details

Built distribution (wheel)

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

Total release size: 432.7 kB

Release files / plural-0.7.1.tar.gz

Download URL plural-0.7.1.tar.gz
Size 278.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c3848840636182f1c82e282825dc68d91ffe562e25496e42f0957527190ad739
BLAKE2b-256 checksum
How to use checksums
0cec91d2087852cf0a7ecd9f739cf9fa93189356e6b9b8969a8ac42e2d8cf369
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

Release files / plural-0.7.1-py3-none-any.whl

Download URL plural-0.7.1-py3-none-any.whl
Size 154.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62de58199b33a033259c43ed789ea9ad4bd905eff0bf7d6c2b0a0d437471b794
BLAKE2b-256 checksum
How to use checksums
3eb7bec5b5903e9745356f2e7bb53e58ff0d3f4c483ee82578a724f746fa0824
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

Release history Release notifications | RSS feed

0.17.1

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.3

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

This release

0.7.1 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

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