Skip to main content

Resilient decorators that return Result types instead of throwing exceptions

Project description

resilient-result

PyPI version Python 3.8+ License: MIT

Pure resilience mechanisms with beautiful Result types.

from resilient_result import retry, timeout, Result

@retry(attempts=3)
@timeout(10.0)
async def call_api(url: str) -> str:
    return await http.get(url)

result: Result[str, Exception] = await call_api("https://api.example.com")
if result.success:
    print(result.data)  # Clean success
else:
    print(f"Failed: {result.error}")  # No exceptions thrown

Why resilient-result? Pure mechanisms over domain patterns, Result types over exceptions, orthogonal composition.

📖 Full API Reference

Installation

pip install resilient-result

Core Features

Pure Mechanism Composition

from resilient_result import retry, timeout, circuit, rate_limit

# Orthogonal composition - each decorator handles one concern
@retry(attempts=3)           # Retry mechanism
@timeout(10.0)               # Time-based protection  
@circuit(failures=5)         # Circuit breaker protection
@rate_limit(rps=100)         # Rate limiting mechanism
async def critical_operation():
    return await external_service()

Result Types Over Exceptions

from resilient_result import Result, Ok, Err

# Clean error handling - no try/catch needed
result = await call_api("https://api.example.com")
if result.success:
    process(result.data)
else:
    log_error(result.error)

Advanced Composition

from resilient_result import compose, resilient

# Manual composition - right to left
@compose(
    circuit(failures=3),
    timeout(10.0), 
    retry(attempts=3)
)
async def robust_operation():
    return await external_service()

# Pre-built patterns
@resilient.api()       # timeout(30) + retry(3)
@resilient.db()        # timeout(60) + retry(5)
@resilient.protected() # circuit + retry

Parallel Operations

from resilient_result import Result

# Collect multiple async operations
operations = [fetch_user(1), fetch_user(2), fetch_user(3)]
result = await Result.collect(operations)

if result.success:
    users = result.data  # All succeeded
else:
    print(f"First failure: {result.error}")

Custom Error Handling

async def smart_handler(error):
    if "rate_limit" in str(error):
        await asyncio.sleep(60)
        return None  # Continue retrying
    return False     # Stop retrying

@retry(attempts=5, handler=smart_handler)
async def api_with_intelligent_backoff():
    return await rate_limited_api()

License

MIT - Build amazing resilient systems! 🚀

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

resilient_result-0.3.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

resilient_result-0.3.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file resilient_result-0.3.1.tar.gz.

File metadata

  • Download URL: resilient_result-0.3.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.10 Darwin/24.5.0

File hashes

Hashes for resilient_result-0.3.1.tar.gz
Algorithm Hash digest
SHA256 287bc2640bd628366cfc68a81ddd05a7146cd3dcf94eaf5dc0dd10ddd3230c9b
MD5 5d3a9d0ea72994b682962263d94686a3
BLAKE2b-256 b8cfa2422a8cf52e0892e6e3543e7f2683a58919990d6afc215a441822d7ca31

See more details on using hashes here.

File details

Details for the file resilient_result-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: resilient_result-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.10 Darwin/24.5.0

File hashes

Hashes for resilient_result-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9205adbf3e7f0d09c80dc3d671e24015e7ba01969f973d9b28c809fe92e8009f
MD5 51beb40cc588a68df770ee5f78699a7f
BLAKE2b-256 e40226015bc57c23530c43eb6ff18d0a21c75abef79a59db0f87c50a0d27a988

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