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
, andDELETE
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.
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
File details
Details for the file request_session-0.16.2.tar.gz
.
File metadata
- Download URL: request_session-0.16.2.tar.gz
- Upload date:
- Size: 38.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e227d014efc35f903c65378caf4fbecab10f54122533a76df16d49cfa4f2db5 |
|
MD5 | f7818e9424b2ccdecf083c466cc910d6 |
|
BLAKE2b-256 | 497bed26cd2a909bfc8efc97ac7be87eeae78a7514eaf13ad0f75dc12996814f |
File details
Details for the file request_session-0.16.2-py3-none-any.whl
.
File metadata
- Download URL: request_session-0.16.2-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ce01c57a5fff2631058846bc318c63d86d74f1e3f5ff81bb10d435e20f5af71 |
|
MD5 | 2b4da5cf867445bc61f4c196f08b8fca |
|
BLAKE2b-256 | 15a00786933f3a01c85f8b2451b974c1290fff0d7b65b420de077ed59a32acc4 |