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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file better-requests-1.0.1.tar.gz.

File metadata

  • Download URL: better-requests-1.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for better-requests-1.0.1.tar.gz
Algorithm Hash digest
SHA256 328abf6e2a424b115ec32f416b6ed814df967cbfaff23ced12d7c59371642cb9
MD5 a0030199fd2e89ee0781c1060c452d4d
BLAKE2b-256 6a0849ddf6faefd3e7abafa7b188422f82e8666cb3224eb63ba3385e85ee721d

See more details on using hashes here.

File details

Details for the file better_requests-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: better_requests-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for better_requests-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 611939908b50b63adc771f0241f47793db2866c5a4832f94606f1a54189d39e0
MD5 0a2d173a89fa01c18f80a635ddfccb72
BLAKE2b-256 1bef5db1d787a250f0c853c8450527f4a24c702bddcc91d7418f0ec5a54b5ac2

See more details on using hashes here.

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