Python HTTP requests on steroids
Project description
request-session
request-session
is an HTTP library built on top of requests
that makes your live easier by retrying whenever a request fails,
logs the results or even sends metrics and traces to DataDogHQ.
RequestSession also measures the time of the request.
Use RequestSession
to create a client module for accessing a group of resources
served on a common endpoint with default values valid for all or
most of the calls you need to make. For your convenience,
some defaults are already provided.
Usage
To install request-session
, use pip:
pip install request-session
from request_session import RequestSession
client = RequestSession(
host="https://jobs.kiwi.com",
max_retries=4, # how many times to retry in case server error occurs
raise_for_status=True, # raise an exception if failed on every attempt
)
response = client.get(
path="/",
sleep_before_repeat=1, # how many seconds to wait untill next try
request_category="jobs", # what to log to stdout/stderr
)
Benefits of using RequestSession
- Retry: It is possible to configure a retry in case of request failure.
- Logs: Result of the request can also be logged to
stdout
. - Metrics: On each call you make to
GET
,POST
,PUT
,PATCH
, and DELETE` methods, several metrics are sent to your datadog client - duration of the request, how many requests were sent, outcome of the request (a DataDog integration is needed). - Tracing:
RequestSession
can send tracing info to DataDog (an APM integration is needed).
You can find more details about RequestSession
's benefits and examples in
the official documentation.
Contributing
Create a merge request and assign it to Josef Podaný for review.
How to run test
To run all tests you just need to run the command tox
.
Note that tox doesn't know when you change the
requirements.txt
and won't automatically install new dependencies for test runs. Runpip install tox-battery
to install a plugin which fixes this silliness.
Project details
Release history Release notifications | RSS feed
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
Hashes for request_session-0.10.0.post1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5e4560f4852564647e84a4bf514b438d62cefdb7301dbc6ccb1b307586cb424 |
|
MD5 | 621970e4241ca4c8835ae4113968bd54 |
|
BLAKE2b-256 | 045f0b57f98f5794421e3275fe2a8bb2512b3fb5e4132c5f02114ac3beeec25c |
Hashes for request_session-0.10.0.post1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbfe5fe9b14374ec8a6e348fc150e02223ba7c078842070975a91278f34d21bd |
|
MD5 | 6460f937acf2698393e537ff2f0c719d |
|
BLAKE2b-256 | 81a00e6dddd35764f38765227c2249f87a740fa72af8c53255e17829b95b9ffb |