Coder Social home page Coder Social logo

kenaco / request-session Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kiwicom/request-session

0.0 0.0 0.0 5.99 MB

Python HTTP requests on steroids ๐Ÿ’ช

Home Page: https://kiwicom.github.io/request-session/

License: MIT License

Python 100.00%

request-session's Introduction

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.

request-session's People

Contributors

aexvir avatar lucas03 avatar batisteo avatar jarosevcik avatar jayvdb avatar kenaco avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.