Skip to main content

A rewrite of the famous requests library with better defaults and certificate handling

Project description

PyPI version

begs

A rewrite of the famous requests library with better defaults and certificate handling

begs is a from-scratch rewrite of the python request library. It is API-compatible with requests, but has some improvements.

Why you should consider using begs over requests:

  • It is much lighter. While requests (314 KB) depends on urllib3 (660 KB), certifi (257 KB), idna (467 KB) and charset-normalizer (220 KB), begs has no dependencies and is less than 20 KB, making it a great choice for use in packages where size matters.

  • The requests library does not support using the built-in system certificate store - relying instead on the hard-coded ssl certificates in the certifi library. This makes distribution to systems located behind SSL-proxy firewalls with self-signed certificates a nightmare. begs supports the system certificate store by default, and makes appending additional certificates to the trusted CA list a breeze.

  • The requests library has a long-standing issue of allowing users to shoot themselves in the foot by not providing a default timeout. begs has a very reasonable 30 second timeout which can be adjusted as-needed.

  • begs also supports various retry options, and will even automatically retry in situations where it can be determined that a retry would be safe and idempotent (such as a 503 response to a POST, or a 500 response to a GET)

"begs" is a play on words - a more aggressive form of "requests". (to beg vs to request) because by default, the begs library will automatically retry certain requests if they fail for certain reasons. More on that below.

Getting Started:
import begs # or even "import begs as requests"

begs.get('http://microsoft.com')

It's that easy!

More Examples:
import begs

# auto-decode json
req = begs.post('https://httpbin.org/post', data={'foo': 'bar'}, params={'me': 'you'})
print(req.json())

# get the response body as text
req = begs.get('https://httpbin.org/ip')
print(req.text)

# get the resonse headers as a dict
req = begs.get('https://google.com')
print(req.headers)
Adding a trusted Certificate Authority:
import begs

# this will set a ssl context for all future begs requests
begs.default_ssl_context.load_verify_locations('badssl-ca.cer')

# would normally raise an ssl exception, but won't now.
result = begs.get('https://untrusted-root.badssl.com/')

#################################################################################################

import ssl
custom_context = ssl.create_default_context() # you can also specify your own ssl context per-request
result = begs.get('https://untrusted-root.badssl.com/', ssl_context=custom_context)
Retries:
import begs

# this request will fail after 4 attempts (0 seconds, 1 second, 2 seconds, 4 seconds)
# getaddrinfo failed exception
begs.get('http://something-that-doesnt-exist.internal', retries=3, retry_delay=1, retry_backoff=2, force_retry=True)

by default retries=1 and force_retry=False which means it will instantly retry up to one time for any safe and idempotent request (like a 500 response to a GET, a timeout to a GET, a 503 response to a POST, etc). You can alter the retry options per-request as above, or you can set the defaults at the module-level like so:

import begs

begs.default_retries = 3
begs.default_retry_delay = 1
begs.default_retry_backoff = 2

begs.get('http://something-that-doesnt-exist.internal')
Timeouts:

The default timeout is 30 seconds, but it can be altered at the module-level or per-request

import begs

begs.default_timeout = 60

begs.get('http://something-that-doesnt-exist.internal', timeout=45)
TODO:

Begs implements the most important things for working with most REST APIs, but is not feature-complete. The following major features remain unimplemented for now:

  • Cookies
  • AUTH: Basic, Digest
  • File Uploads (multipart/form-data)
  • Proxies

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

begs-0.1.9.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

begs-0.1.9-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file begs-0.1.9.tar.gz.

File metadata

  • Download URL: begs-0.1.9.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.9

File hashes

Hashes for begs-0.1.9.tar.gz
Algorithm Hash digest
SHA256 953231b23ae212ee489bcc607b90b77aa71ee7594090438a4cd6bca4292eb64b
MD5 be7f8d94a3ceb2b2fd35bf93f86895ae
BLAKE2b-256 0f92f48a0c9462edd38011ea0bdebcb0e63de8bd969522b36fdff88fe296581e

See more details on using hashes here.

File details

Details for the file begs-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: begs-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.9

File hashes

Hashes for begs-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 62a7b07adccccaa7d79d0887ca4e9a77ff6f24f69ce6e5e121b51d0df56539cc
MD5 7ddd37088845a74fc83dbdc9c23a832a
BLAKE2b-256 4df17a8df5a217ba829498cf5c9ed377c53d2c93693bd78b45afa85eb8deee1a

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