Utils for HTTP requests using the requests library
Project description
Http Utils
A simple requests session wrapper.
Installation
pip install pip install git+git://github.com/juntossomosmais/http-utils.git
Configuration process
If needed you can provide some settings as environment variables.
HTTP_RETRIES=3
HTTP_BACKOFF_FACTOR=0.1
HTTP_STATUS_FORCELIST=
HTTP_TIMEOUT=30
Usage
The basic usage is to call the request_session as a context manager.
from http_utils.session import request_session
def awesome_request():
with request_session() as request:
response = request.get(url="https://www.some-awesome-service.com")
return response
This will add:
- A retry mechanism of 3 attempts for status codes
(defined in the
HTTP_RETRIESvariable or as thetotalparameter) - A backoff factor for each retry in seconds
(defined in the
HTTP_BACKOFF_FACTORvariable or as thebackoff_factorparameter) - A list of status to force retries
(defined in the
HTTP_STATUS_FORCELISTvariable or as thestatus_forcelistparameter) - A list of allowed methods to request
(Defined as ["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE"] methods by default or as the
allowed_methodsparameter) - A list of hooks
(The default hooks used are the
raise_for_statusand a DEBUG level log for the response body, header and status code)
Helpers
There are also some helper functions that can be used to parse the response object
-
get_response_body: Attemps to return a parsed json response body, returning the response text if it can't.
-
convert_header_to_meta_key: Converts the Django Http Request META header to be separated with a
-instead of_
Tests
In order to execute tests, execute the following:
docker-compose up -d tests
This will run the tests in the python 3.9.4, 3.8.5, 3.7.5, 3.6.9 tox environments
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file http_utils-0.1.5.tar.gz.
File metadata
- Download URL: http_utils-0.1.5.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.19 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfe7d4c4d9f3a24154caf345fc72302ed77b85d85d58df71d2c50b89f081ae99
|
|
| MD5 |
88e017b90c9fed8a3913d1c7778100ca
|
|
| BLAKE2b-256 |
10f05ecfd9b49a1e3d9df80c09f3f803b05ed79d7728d7adae7913e2b4431034
|
File details
Details for the file http_utils-0.1.5-py3-none-any.whl.
File metadata
- Download URL: http_utils-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.19 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35c1ec7634754e7d9a075ce98093b9abb1c3cfc3a3c0fea99c7d436252992c31
|
|
| MD5 |
13d2033ddb38b4f8348851069ee87586
|
|
| BLAKE2b-256 |
98d496de25b7c4bfb31f1cbedb9a86f7d6307d59752e3f36e7bcada773ab1b62
|