Skip to main content

HTTP for Humans that do right

Project description

better-requests:
HTTP for Humans that do right

A good design makes it intuitive and convenient to do right, better-requests is a wrapper for requests that makes default behaviors right.

  • Default value of timeout is 30s (configurable) instead of forever, no need to specify timeout explicitly everywhere.
  • Non-successful responses raise by default, no need to call raise_for_status explicitly everywhere.

Usage

Write this:

>>> import better_requests as requests
>>> r = requests.get('https://www.python.org')
>>> 'Python is a programming language' in r.content
True

Instead of:

>>> import requests
>>> 
>>> # You need to explicity specify timeout everywhere, or, BOOM!
... r = requests.get('https://www.python.org', timeout=30)
>>>
>>> # And explicity check status_code before reading content, everywhere, or, BOOM!
... r.raise_for_status()
>>>
>>> # And do things finally after all the ceremonies
... 'Python is a programming language' in r.content
True

When you need to configure default timeout, either set it globally:

>>> import better_requests as requests
>>> requests.Session.default_timeout = 5
>>>
>>> r = requests.get('https://www.python.org')
>>> 'Python is a programming language' in r.content
True

Or per session:

>>> import better_requests as requests
>>> with requests.Session() as s:
>>>     s.default_timeout = 5
>>>     s.get('https://httpbin.org/get')

It works just as expected.

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

better-requests-1.0.1.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

better_requests-1.0.1-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

Supported by

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