Skip to main content

request-session

Versions Code style: black

request-session is an HTTP library built on top of requests that makes your life 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.

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. Run pip install tox-battery to install a plugin which fixes this silliness.

Release files for request-session 0.16.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for request-session 0.16.6
File Size Uploaded
request_session-0.16.6.tar.gz 39.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for request-session 0.16.6
File Interpreter ABI Platform
request_session-0.16.6-py3-none-any.whl Python 3 none any Details

Total release size: 53.6 kB

Release files / request_session-0.16.6.tar.gz

Download URL request_session-0.16.6.tar.gz
Size 39.8 kB
Tags Source
SHA-256 checksum
How to use checksums
feb9ed9302a947903c7d8e5571a7741589f48b379ce289cef2323661ddc69bd4
BLAKE2b-256 checksum
How to use checksums
76ef59753404e19dddc4f2951d56d19334f850960507b578cbb1cba2b4df7fe7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / request_session-0.16.6-py3-none-any.whl

Download URL request_session-0.16.6-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65683e6dddf225229ee64e9dc512b23fc020c0a22ca36612eef5e7acdf95f413
BLAKE2b-256 checksum
How to use checksums
9ae1d224dc68771b3309428783ba90d601ac29d8d7d54550a082a8f2295da17c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.16.6 This release

2 release files

0.16.4

2 release files

0.16.3

2 release files

0.16.2

2 release files

0.16.1

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.8

2 release files

0.9.7

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page