Skip to main content

Async LLM benchmarking library with protocol-based extensibility

Project description

promptum

Python 3.13+ Async License: MIT

Test LLMs Like a Pro.

Stop writing boilerplate to test LLMs. Start getting results.


What's This?

A dead-simple Python library for testing LLM providers. Write tests once, run them across any model, get structured results.

session = Session(provider=client, name="my_test")
session.add_test(Prompt(
    name="basic_math",
    prompt="What is 2+2?",
    model="gpt-3.5-turbo",
    validator=Contains("4")
))
report = await session.run()

That's it. No setup. No config files. Just results.


Why You Need This

Before promptum:

# Custom API client for each provider
openai_client = OpenAI(api_key=...)
anthropic_client = Anthropic(api_key=...)

# Manual validation logic
if "correct answer" not in response:
    failed_tests.append(...)

# Track metrics yourself
latency = end_time - start_time
tokens = response.usage.total_tokens

# Write your own retry logic
for attempt in range(max_retries):
    try:
        response = client.chat.completions.create(...)
        break
    except Exception:
        sleep(2 ** attempt)

After promptum:

report = await session.run()
summary = report.get_summary()  # Metrics captured automatically

Quick Start

pip install promptum  # (or: uv pip install promptum)
export OPENROUTER_API_KEY="your-key"
import asyncio
from promptum import Session, Prompt, OpenRouterClient, Contains

async def main():
    async with OpenRouterClient(api_key="your-key") as client:
        session = Session(provider=client, name="quick_test")

        session.add_test(Prompt(
            name="basic_math",
            prompt="What is 15 * 7? Reply with just the number.",
            model="openai/gpt-3.5-turbo",
            validator=Contains("105")
        ))

        report = await session.run()
        summary = report.get_summary()

        print(f"✓ {summary.passed}/{summary.total} tests passed")
        print(f"⚡ {summary.avg_latency_ms:.0f}ms average")
        print(f"💰 ${summary.total_cost_usd:.6f} total cost")

asyncio.run(main())

Run it:

python your_script.py

What You Get

  • 100+ Models via OpenRouter - One client for OpenAI, Anthropic, Google, and more
  • Smart Validation - ExactMatch, Contains, Regex, JsonSchema, or write your own
  • Automatic Retries - Exponential/fixed-delay backoff with configurable attempts
  • Metrics Tracking - Latency, tokens, cost - automatically captured
  • Async by Default - Run 100 tests in parallel without breaking a sweat
  • Type Safe - Full type hints, catches errors before runtime
  • Zero Config - No YAML files, no setup scripts, just Python

Real Example

Compare GPT-4 vs Claude on your tasks:

import asyncio
from promptum import Session, Prompt, Contains, Regex, OpenRouterClient

async def main():
    async with OpenRouterClient(api_key="your-key") as client:
        session = Session(provider=client, name="model_comparison")

        session.add_tests([
            Prompt(
                name="json_output_gpt4",
                prompt='Output JSON: {"status": "ok"}',
                model="openai/gpt-4",
                validator=Regex(r'\{"status":\s*"ok"\}')
            ),
            Prompt(
                name="json_output_claude",
                prompt='Output JSON: {"status": "ok"}',
                model="anthropic/claude-3-5-sonnet",
                validator=Regex(r'\{"status":\s*"ok"\}')
            ),
            Prompt(
                name="creative_writing",
                prompt="Write a haiku about Python",
                model="openai/gpt-4",
                validator=Contains("Python", case_sensitive=False)
            ),
        ])

        report = await session.run()

        # Side-by-side model comparison
        for model, model_report in report.group_by(lambda r: r.test_case.model).items():
            summary = model_report.get_summary()
            print(f"{model}: {summary.pass_rate:.0%} pass rate, {summary.avg_latency_ms:.0f}ms avg")

asyncio.run(main())

Use Cases

🔬 Model Evaluation - Compare GPT-4, Claude, Gemini on your specific tasks 🎯 Prompt Engineering - Test 100 prompt variations, find what works ⚡ Latency Testing - Measure real-world response times across providers 💰 Cost Analysis - Track spending per model/task before production 🔄 Regression Testing - Ensure model updates don't break your prompts 📊 A/B Testing - Data-driven model selection for your product


Requirements

  • Python 3.13+
  • An OpenRouter API key (or implement your own provider)

That's it. No Docker, no complex setup.


Why Protocol-Based?

Most libraries force inheritance:

class MyProvider(BaseProvider):  # Tightly coupled
    def generate(self): ...

We use protocols (structural typing):

class MyProvider:  # No inheritance needed
    async def generate(self) -> tuple[str, Metrics]:
        # Your implementation
        return response, metrics

# It just works
session = Session(provider=MyProvider())

Cleaner. More flexible. More Pythonic.


Contributing

Found a bug? Want a feature? PRs welcome!

# Development setup
git clone https://github.com/deyna256/promptum.git
cd promptum
just sync       # Install dependencies
just test       # Run tests

# Development commands
just lint       # Check code style
just format     # Format code
just typecheck  # Type checking

License

MIT - do whatever you want with it.


⭐ Star on GitHub | 🐛 Report Bug | 💡 Request Feature

Made for developers who value their time.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

promptum-0.0.5.tar.gz (32.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

promptum-0.0.5-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file promptum-0.0.5.tar.gz.

File metadata

  • Download URL: promptum-0.0.5.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for promptum-0.0.5.tar.gz
Algorithm Hash digest
SHA256 9cac7fe189aa3b041abb933a9e209e88bd25a41d75efd60b361f7bf42712eadb
MD5 5b5d53f5fa005b5e06842af71de837c9
BLAKE2b-256 004f109951b8703c14722dcfcf1c1af704aeec402fd3f5800cb04df94fe1fbdc

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptum-0.0.5.tar.gz:

Publisher: publish.yml on deyna256/promptum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file promptum-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: promptum-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for promptum-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f81121791dd928d152224913460d94a5560222bb34ed8cbeceafc7a1e9238f2f
MD5 26e75f7bf2f3d7aeb9a0475494a7195f
BLAKE2b-256 104d5a4c1cbde6a446f8849773e0e672844586bad98729f1a020a0ab166d1cf5

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptum-0.0.5-py3-none-any.whl:

Publisher: publish.yml on deyna256/promptum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page