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.2.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.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyfaulttolerance-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 64dfb7c1493b4be5f2975996e42ff4c048510078cca09abb1d7c725bc99cd144
MD5 4bc530ccc67937d8d4dfea3c1a02a6cc
BLAKE2b-256 d698574c824b111f1cfdcf7b89bb02aee1d6fa15fb7b4fd2b83bbc2ba78237f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfaulttolerance-0.1.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyfaulttolerance-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 af27e8bb55148bafbbf4a8abd24d0fd3c7a206298dc62af6f14d070e737b8183
MD5 0071607092de25ee6485d77a68c61c5e
BLAKE2b-256 67e9ebd571baa8160e11eacd7e455fa73918d95eba99aeafd33df1e813e69a8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfaulttolerance-0.1.2-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