Skip to main content

Python HTTP requests on steroids

Project description

request-session

Versions Code style: black

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.

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.

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

request_session-0.16.1.tar.gz (38.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

request_session-0.16.1-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file request_session-0.16.1.tar.gz.

File metadata

  • Download URL: request_session-0.16.1.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

Hashes for request_session-0.16.1.tar.gz
Algorithm Hash digest
SHA256 6e994f0bd5b258312d1df54d4100fdbbb618ffab1736a149aee34e57e46f1409
MD5 c2832075be9db6277dfcf8d9d703a309
BLAKE2b-256 f721013e9a85525107ab2c46cca7798ad3628ddca6060b3af70544b7e8de2d52

See more details on using hashes here.

File details

Details for the file request_session-0.16.1-py3-none-any.whl.

File metadata

File hashes

Hashes for request_session-0.16.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b5b384f164398b23f8cc0e30254ed26207ab54497e82ad0c2aa2bda4fe2c75b
MD5 f81fa8c760373829f9245c7aa603c98a
BLAKE2b-256 e86e0f3e58f3460a74633098002146dbe7d3ed67d26c8cc57ec21cf118075288

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page