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 Plural, Message

client = Plural()
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 Plural

client = Plural(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.6.0

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.6.0
File Size Uploaded
plural-0.6.0.tar.gz 271.6 kB Details

Built distribution (wheel)

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

Total release size: 420.8 kB

Release files / plural-0.6.0.tar.gz

Download URL plural-0.6.0.tar.gz
Size 271.6 kB
Tags Source
SHA-256 checksum
How to use checksums
df15a2e02e4fcccfca27c015894cfef6978cbf1f87898dd38490ce681674c18d
BLAKE2b-256 checksum
How to use checksums
6cec8bd44a1d40ac67b7960b676af8fa526ab29b7a8495a5ca01340165516053
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 Aug 25, 2026.

Transparency log

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

Download URL plural-0.6.0-py3-none-any.whl
Size 149.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cafd163c3a4459c6ada3b2e93e95b176a42800fd22b86c783ef3332477ed9d49
BLAKE2b-256 checksum
How to use checksums
a341749af6afc8e20c23016c17e89a50485f57a2d7eb54ececff5ec574b6aeeb
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 Aug 25, 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

0.7.1

2 release files

0.6.1

2 release files

This release

0.6.0 This release

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