Skip to main content

Reliability primitives for Python applications.

Project description

RelPrim

CI PyPI version Python License

Reliability primitives for operations that cross process, network or provider boundaries.

RelPrim helps you wrap external calls with retries, timeouts, fallbacks, validation, circuit breakers, execution reports and structured events.

Install

pip install relprim

Wrap an external call in seconds

from relprim import resilient


async def call_gemini(prompt: str) -> str:
    return await gemini_client.generate(prompt)


@resilient(retries=3, timeout=10, fallback=call_gemini)
async def call_openai(prompt: str) -> str:
    return await openai_client.generate(prompt)


result = await call_openai("Write a short product summary")

print(result.value)
print(result.report.to_dict())

The decorated function returns an OperationResult[T], not a raw value. This keeps the business result and the execution report explicit.

Why RelPrim?

Most external calls start simple:

response = await openai.chat.completions.create(...)

But production systems need to answer harder questions:

  • What if the provider times out?
  • What if the response is temporarily unavailable?
  • What if the provider returns an invalid response?
  • What if the primary provider is down?
  • What if you need a fallback provider?
  • What if you need to debug what happened after the fact?

RelPrim gives you two levels of adoption.

Beginner-friendly decorator API:

@resilient(retries=3, timeout=10)
async def call_provider(prompt: str) -> str:
    return await provider.generate(prompt)

Advanced composition API:

result = await (
    async_operation("generate_response", call_provider)
    .with_retry(RetryPolicy(max_attempts=3))
    .with_timeout(TimeoutPolicy(seconds=10))
    .with_validation(validation_policy(...))
    .with_fallbacks(fallback_chain(("backup_provider", call_backup)))
    .run(prompt)
)

What RelPrim provides

Current primitives:

  • Resilient decorator API
  • Retry policies
  • Exponential backoff with jitter
  • Async timeout enforcement
  • Async fallback chains
  • Async circuit breakers
  • Validation policies
  • Callable validators
  • Structured events
  • Event emitters
  • No-op event sink
  • In-memory event sink
  • Async operation builder API
  • Structured execution reports
  • Operation results
  • Typed execution errors

Planned primitives:

  • SQLite event store
  • OpenTelemetry exporter
  • Idempotency helpers
  • Rate limit handling
  • JSON Schema validator adapter
  • Pydantic validator adapter

Examples

Practical examples are available in the examples directory:

If you run examples from a cloned repository, install RelPrim in editable mode first:

python -m pip install -e ".[dev]"
python examples/decorator_usage.py

Or run a single example without installing the package:

PYTHONPATH=src python examples/decorator_usage.py

Documentation

Design principles

RelPrim is intentionally small and explicit.

Core principles:

  • Reliability behavior should be visible in code.
  • Failure modes should be explicit.
  • Defaults should be safe for production use.
  • Primitives should be composable, not magical.
  • Observability should be built into the execution model.
  • Async execution should respect cancellation and timeout semantics.
  • The library should not hide side effects behind fake safety guarantees.
  • External integrations should be wrapped, not replaced.

RelPrim does not try to become a workflow engine. It provides the reliability layer that can be used inside your application, worker, service or orchestration system.

What RelPrim is not

RelPrim is not:

  • an AI provider SDK
  • an HTTP client
  • a workflow engine
  • a task queue
  • an observability backend
  • a replacement for provider-native SDKs
  • a replacement for Temporal, Celery or OpenTelemetry

It is a reliability layer for external operations.

Maintainer

Created and maintained by Bart Rozycki.

License

Apache License 2.0

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

relprim-0.7.0.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

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

relprim-0.7.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file relprim-0.7.0.tar.gz.

File metadata

  • Download URL: relprim-0.7.0.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for relprim-0.7.0.tar.gz
Algorithm Hash digest
SHA256 a4070d0b404be209f2e18b3e158214c196516c85b5904d10e98db2aefba5f9a6
MD5 2bf52c8bf63411355a24646b4d9a72c3
BLAKE2b-256 c3778873391dc2cd9dd735d41aee4346a68efb94ae934143e34bb376a69d208e

See more details on using hashes here.

File details

Details for the file relprim-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: relprim-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for relprim-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05b4d7d9c4b69b8e7d44e4c46f82f78facb5e6355068e6af3065326e3d53198a
MD5 ceb94e82f7501044f56147aa4b913a8f
BLAKE2b-256 4ce1c815a864c56d369a8fdfe0c323038dc0110a983ba235b91be4aa4690c9ca

See more details on using hashes here.

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