Skip to main content

Microframework de tolerância a falhas inspirado no SmallRye Fault Tolerance

Project description

PyFaultTolerance

codecov

Um microframework Python para tolerância a falhas assíncrona, inspirado no SmallRye Fault Tolerance.
Ideal para sistemas resilientes que utilizam asyncio ou FastAPI.


✨ Funcionalidades

  • @timeout_async: interrompe execução que exceder o tempo limite
  • 🔁 @retry_async: reexecuta em caso de falha, com controle de tentativas
  • 🧱 @bulkhead: limita concorrência simultânea (isolamento de chamadas)
  • 🔌 @fallback: define alternativa automática em caso de falha
  • 🚧 CircuitBreaker: previne chamadas para funções que falharam repetidamente
  • 📦 Exceções personalizadas com logs estruturados

📦 Instalação

Você pode instalar a biblioteca diretamente do PyPI:

pip install pyfaulttolerance

🚀 Uso

Timeout

from pyfaulttolerance.timeout import timeout, TimeoutException

@timeout(seconds=2)
def funcao_lenta():
    # código que pode demorar
    pass

Retry

from pyfaulttolerance.retry_async import retry_async

@retry_async(max_attempts=3, delay=1)
async def funcao_instavel():
    # código que pode falhar
    pass

Fallback

from pyfaulttolerance.fallback import fallback

async def alternativa():
    return "valor alternativo"

@fallback(alternativa)
async def funcao_principal():
    # código que pode falhar
    pass

Bulkhead

from pyfaulttolerance.bulkhead import bulkhead

@bulkhead(max_concurrent_calls=2)
async def tarefa():
    # código que deve ser limitado em concorrência
    pass

Circuit Breaker

from pyfaulttolerance.circuit_breaker import CircuitBreaker

cb = CircuitBreaker(failure_threshold=3, recovery_timeout=10)

@cb
async def funcao():
    # código que pode falhar
    pass


📄 Licença

Este projeto está licenciado sob a Licença MIT. Consulte o arquivo LICENSE para mais detalhes.

Para mais informações, visite o repositório oficial: https://github.com/gomesrocha/pyfaulttolerance

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

pyfaulttolerance-0.1.3.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

pyfaulttolerance-0.1.3-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file pyfaulttolerance-0.1.3.tar.gz.

File metadata

  • Download URL: pyfaulttolerance-0.1.3.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyfaulttolerance-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c510d116dbc02fb3453bb8f22726f0d090454c3c7e09b472effcee2d6b4ce41b
MD5 442f4430c314e0d5f26a3ffddce4253f
BLAKE2b-256 3c0866613b84bab09e5e67892805468e10aa98324b32a75111ff4718b47b0065

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfaulttolerance-0.1.3.tar.gz:

Publisher: python-publish.yml on gomesrocha/pyfaulttolerance

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

File details

Details for the file pyfaulttolerance-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pyfaulttolerance-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 38272bd8f93c4e0f357449a0c1fc57dc578d076710b7e9655f74a97f8b130a9f
MD5 d15708893ae052bbf0b4feaa1c2313e9
BLAKE2b-256 1dd43dbaef30ba3033f10f5ef58103fbdbebc35ea34e3d896374664197989723

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfaulttolerance-0.1.3-py3-none-any.whl:

Publisher: python-publish.yml on gomesrocha/pyfaulttolerance

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