pyhystrix
A library to patch requests package in order to add following functionalities by default:
- Connection and Read timeouts
- Retries on connection failure
- Circuitbreaking
- Adding unique
x-request-idin request header if not provided
NOTE:: 0.0.2 supports python2.7 and >= 0.0.3 supports python3 only.
Installation
pip3 install pyhystrix
Usage
Before making any request, just call Init():
import requests
import pyhystrix
requests.get("http://abc.xyx") // No functionalities of pyhystrix
pyhystrix.Init()
requests.get("http://abc.xyx") // pyhystrix is attached to all requests
Default Configurations can be changed in 2 ways:
-
Setting following env variables:
PHY_CONNECT_TIMEOUT: connection timeout in secPHY_READ_TIMEOUT: read timeout in secondsPHY_MAX_RETRIES: max number of retries for connection failurePHY_CIRCUIT_FAIL_THRESHOLD: Number of failed requests after which circuit will be open and further requests on the same url will not be allowed.PHY_CIRCUIT_ALIVE_THRESHOLD: Number of failed requests on open circuit to make it half_open (Described below)PHY_CIRCUIT_DELAY: Number of seconds after which open circuit will be half_open.
-
parameters in request itself:
max_tries(int): overridesPHY_MAX_RETRIES, some rules related to it are follows:max_tries=0: will cause no retries, fail on first failure.- If a positive value is passed for non
GETrequests, they will be retried too in case received status is instatus_forcelist.
status_forcelist: list of http status, retry if the returned status is one of these. default is[500]onGET.timeout: same as timeout in requestsbackoff_factor: delay in each retry will be affected by this using following formula:{backoff factor} * (2 ^ ({number of total retries} - 1)). Default =0.5sec
More Examples
GETwith retry on multiple failure status codes:
import requests
import pyhystrix
pyhystrix.Init()
request.get("http://abc.xyz", status_forcelist=[501, 502, 403])
putwith retry on response status =500or501
request.put("http://abc.xyz", max_tries=3, status_forcelist=[500, 502])
NOTE: All type of requests will be retried in case of ConnectionError
Circuit Breaker States
- OPEN : No requests will be allowed
- HALF_OPEN : Only one request will be allowed
- CLOSE : All requests will be allowed.
NOTE : State transitions:
CLOSE --> OPEN --> HALF_OPEN --> CLOSE/OPEN
To know more about circuit breaker pattern, click here
Metadata
Release files for pyhystrix 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyhystrix-1.0.0.tar.gz | 7.1 kB | Without provenance | Details for pyhystrix-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyhystrix-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for pyhystrix-1.0.0-py3-none-any.whl |
Total release size: 15.8 kB
Release files / pyhystrix-1.0.0.tar.gz
| Download URL | pyhystrix-1.0.0.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e279136373afbcad9e8a5468f38190a15bcd75212eface80e0cf36d6ca07b8b
|
|
BLAKE2b-256 checksum How to use checksums |
c3bf2bc63e0d68a5e6a033932b9d5a723bf71d50d606b6668a4f19012f091124
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
|
Release files / pyhystrix-1.0.0-py3-none-any.whl
| Download URL | pyhystrix-1.0.0-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ccf7b7e4f6a7da48c5aef11418c51f7dd1c66d9dd4255321967c29518e112f0
|
|
BLAKE2b-256 checksum How to use checksums |
828147196ebef948d44fa0c4a526c3e1754b5794b75a6c13b70330f72fc067fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
|
Security for pyhystrix 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.