Skip to main content

Reliability primitives for Python applications.

Project description

RelPrim

Reliability primitives for external operations in Python.

RelPrim is a production resilience SDK that helps developers build reliable integrations with AI providers, APIs and external services.

Status

🚧 Early development.

RelPrim is currently in active development and APIs may change before the first stable release.

Installation

pip install relprim

Quickstart

import asyncio

from relprim import (
    CircuitBreaker,
    RetryPolicy,
    TimeoutPolicy,
    async_operation,
    fallback_chain,
)


class TemporaryProviderError(Exception):
    pass


async def call_primary_provider(prompt: str) -> str:
    # Replace this with an OpenAI, Gemini, HTTP, payment or any other external call.
    raise TemporaryProviderError("primary provider temporarily unavailable")


async def call_fallback_provider(prompt: str) -> str:
    # Replace this with a secondary provider, backup API or local implementation.
    return f"Fallback response for: {prompt}"


async def main() -> None:
    circuit_breaker = CircuitBreaker(
        name="primary_provider",
        failure_threshold=3,
        recovery_timeout_seconds=30,
        record_failure_on=(TemporaryProviderError,),
    )

    result = await (
        async_operation("generate_response", call_primary_provider)
        .with_circuit_breaker(circuit_breaker)
        .with_retry(
            RetryPolicy(
                max_attempts=3,
                retry_on=(TemporaryProviderError,),
            )
        )
        .with_timeout(TimeoutPolicy(seconds=10))
        .with_fallbacks(
            fallback_chain(
                ("fallback_provider", call_fallback_provider),
            )
        )
        .run("Write a short product summary")
    )

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


asyncio.run(main())

What RelPrim provides

RelPrim focuses on reliability primitives for operations that cross process, network or provider boundaries.

Current primitives:

  • Retry policies
  • Exponential backoff with jitter
  • Async timeout enforcement
  • Async fallback chains
  • Async circuit breakers
  • Async resilient operation API
  • Structured execution reports
  • Operation results
  • Typed execution errors

Planned primitives:

  • Validation
  • Idempotency
  • Rate limit handling
  • Structured events
  • SQLite event store
  • OpenTelemetry exporter

Why operation and fallback names matter

RelPrim uses explicit operation and fallback names for observability.

async_operation("generate_response", call_primary_provider)

fallback_chain(
    ("fallback_provider", call_fallback_provider),
)

These names appear in execution reports and will later be used by structured events, persistent execution history and OpenTelemetry integration.

What RelPrim is not

RelPrim is not a workflow engine, agent framework, task queue, chatbot framework or AI provider wrapper.

It is a reliability SDK for external operations.

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.4.0.tar.gz (22.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.4.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: relprim-0.4.0.tar.gz
  • Upload date:
  • Size: 22.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.4.0.tar.gz
Algorithm Hash digest
SHA256 53a650039c021cc53bac9738b518bba4132459c1ed3190eeafd2ce2583b85b99
MD5 e8ee4def4cebe7e026c7ba2074b2436b
BLAKE2b-256 802b088446a2178392103143b2f7468c5a0ee5229dfeb13005a5c3860875873f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: relprim-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 19.0 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6f39f9199ad1f3ed1b77bdcf98f1d0bab76c98fdccd50d56b2e8b78461fcd2a
MD5 9541e8a5d090c2c0bd509182d955ada6
BLAKE2b-256 795c99d4466ea910784e1102fb93c270b1a09bf0193a34e3e51ff434c3013f47

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