HTTP client library for gevent
Project description
geventhttpclient
A high performance, concurrent HTTP client library for python using gevent.
gevent.httplib
support was removed in gevent 1.0, geventhttpclient now provides that missing functionality.
geventhttpclient uses a fast http parser, written in C.
geventhttpclient has been specifically designed for high concurrency, streaming and support HTTP 1.1 persistent connections. More generally it is designed for efficiently pulling from REST APIs and streaming APIs like Twitter's.
Safe SSL support is provided by default. geventhttpclient depends on the certifi CA Bundle. This is the same CA Bundle which ships with the Requests codebase, and is derived from Mozilla Firefox's canonical set.
As of version 2.1, only Python 3.9+ is fully supported (with prebuilt wheels).
A simple example:
#!/usr/bin/python
from geventhttpclient import HTTPClient
from geventhttpclient.url import URL
url = URL('http://gevent.org/')
http = HTTPClient(url.host)
# issue a get request
response = http.get(url.request_uri)
# read status_code
response.status_code
# read response body
body = response.read()
# close connections
http.close()
httplib compatibility and monkey patch
geventhttpclient.httplib module contains classes for drop in replacement of httplib connection and response objects. If you use httplib directly you can replace the httplib imports by geventhttpclient.httplib.
# from httplib import HTTPConnection
from geventhttpclient.httplib import HTTPConnection
If you use httplib2, urllib or urllib2; you can patch httplib to use the wrappers from geventhttpclient. For httplib2, make sure you patch before you import or the super calls will fail.
import geventhttpclient.httplib
geventhttpclient.httplib.patch()
import httplib2
High Concurrency
HTTPClient has connection pool built in and is greenlet safe by design. You can use the same instance among several greenlets.
#!/usr/bin/env python
import gevent.pool
import json
from geventhttpclient import HTTPClient
from geventhttpclient.url import URL
# go to http://developers.facebook.com/tools/explorer and copy the access token
TOKEN = '<go to http://developers.facebook.com/tools/explorer and copy the access token>'
url = URL('https://graph.facebook.com/me/friends')
url['access_token'] = TOKEN
# setting the concurrency to 10 allow to create 10 connections and
# reuse them.
http = HTTPClient.from_url(url, concurrency=10)
response = http.get(url.request_uri)
assert response.status_code == 200
# response comply to the read protocol. It passes the stream to
# the json parser as it's being read.
data = json.load(response)['data']
def print_friend_username(http, friend_id):
friend_url = URL('/' + str(friend_id))
friend_url['access_token'] = TOKEN
# the greenlet will block until a connection is available
response = http.get(friend_url.request_uri)
assert response.status_code == 200
friend = json.load(response)
if 'username' in friend:
print('%s: %s' % (friend['username'], friend['name']))
else:
print('%s has no username.' % friend['name'])
# allow to run 20 greenlet at a time, this is more than concurrency
# of the http client but isn't a problem since the client has its own
# connection pool.
pool = gevent.pool.Pool(20)
for item in data:
friend_id = item['id']
pool.spawn(print_friend_username, http, friend_id)
pool.join()
http.close()
Streaming
geventhttpclient supports streaming. Response objects have a read(N) and readline() method that read the stream incrementally. See src/examples/twitter_streaming.py for pulling twitter stream API.
Here is an example on how to download a big file chunk by chunk to save memory:
#!/usr/bin/env python
from geventhttpclient import HTTPClient, URL
url = URL('http://127.0.0.1:80/100.dat')
http = HTTPClient.from_url(url)
response = http.get(url.query_string)
assert response.status_code == 200
CHUNK_SIZE = 1024 * 16 # 16KB
with open('/tmp/100.dat', 'w') as f:
data = response.read(CHUNK_SIZE)
while data:
f.write(data)
data = response.read(CHUNK_SIZE)
Benchmarks
The benchmark does 10000 get requests against a local nginx server in the default
configuration with a concurrency of 10. See benchmarks
folder. The requests per
second for a couple of popular clients is given in the table below.
HTTP Client | RPS |
---|---|
GeventHTTPClient | 7181.2 |
Urllib3 | 2847.5 |
Httpx | 1682.9 |
Requests | 1186.4 |
Linux(x86_64), Python 3.11.6 @ Intel i7-7560U
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for geventhttpclient-2.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5ff6f1c69d095f17d8a5ae3177d50bac4ef29da31d9840fd08ec5a3bb9a4d19 |
|
MD5 | 2f85616a7d76d4da1d2088297085a412 |
|
BLAKE2b-256 | 81eee5dacbf1ac9558f354b6bbb055b90b1a0544f39a715a295260a852d14164 |
Hashes for geventhttpclient-2.1.1-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3466efce8a7734165d0279d811fa433b50a27840ce4ea0632328e442dde6a334 |
|
MD5 | 3737131928cbcb6431b45a5b371b673c |
|
BLAKE2b-256 | 41660bf0314357a946e935e0da37e300620ef68505342024edcf88469b92955e |
Hashes for geventhttpclient-2.1.1-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ecd9fe3bd3936e717d91ccc76fbb9a67bb41f51d410cf3b3c589336125484b1 |
|
MD5 | 76af67fcd2520e2a66d073f3bdf8000a |
|
BLAKE2b-256 | 2d481a05f2a1de1a75e3b72ab2ce2542a57158afdc5ba2f4139e469d721233ef |
Hashes for geventhttpclient-2.1.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69091efb52925b5c147e84587659954c9553889ca832a1da37f86fdaf8c51012 |
|
MD5 | d5c53b6cfccd7c5d27cee46079a60fbb |
|
BLAKE2b-256 | e8b9e658dc0317474deb17f9c5cf41bcd6dd09ae1dd3247d0adb1f672e8e0442 |
Hashes for geventhttpclient-2.1.1-pp39-pypy39_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0954f36796a7a759beaf3da78f60ded67c0eecc0299aad0c3f416891fe99e116 |
|
MD5 | cbbd204039f3cc17f3c217d98d6f26a5 |
|
BLAKE2b-256 | 75f1ddd734405cafd57610ccd31c31775f45f3548b74c7c3697459937696c7a4 |
Hashes for geventhttpclient-2.1.1-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51036b94dbeedbc174d635768162337e148c43c0077ec27236b402ea8fe53df3 |
|
MD5 | 843da3abc4776fd2f36558c36f3286f4 |
|
BLAKE2b-256 | ddc86d4d2c76ffebfc3f42f1e36aa5815afd573e3cc7ee2f6f157347d053f8da |
Hashes for geventhttpclient-2.1.1-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17ef01d56c461312ef446624570b45f800b74989f4626339014f13a32f9bdb83 |
|
MD5 | 32fa5584a3eada1da8b1df503e17cebf |
|
BLAKE2b-256 | c37c3f2970e8ba20642d22ca26668efd1e004833554189feeeea84d22609ca55 |
Hashes for geventhttpclient-2.1.1-cp312-cp312-musllinux_1_1_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc8ab7ee6de97eb5265625ff6470fc4ecee90bfb020514601f41ff19415aa1eb |
|
MD5 | fbf7627ebf75348969809c8dde883783 |
|
BLAKE2b-256 | 8011dadcdd2f67b845120cd150792297e6b83fe6c77a791e0b188ca742d2ebc4 |
Hashes for geventhttpclient-2.1.1-cp312-cp312-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb02e0410e7ab546f9462a32efee40a9e2c984e0f7adb7b14bce22c99268be9c |
|
MD5 | 531168d158496de496a0e624ccd5cad4 |
|
BLAKE2b-256 | 1e666e0311ed5f8299d1b149ebbee8688afec937334bbfd7848304430d1de56b |
Hashes for geventhttpclient-2.1.1-cp312-cp312-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0085e5438db7e04a1ce55c34d9ce6cb6107d65e5143adce19c1b58ff77c37707 |
|
MD5 | e1d71a7ca96f3aa47b3a8dfc48d1fa66 |
|
BLAKE2b-256 | 133be9d8b2c6e2668109891fbd860dde1dfc5c37466b80eb49340b7771e2326a |
Hashes for geventhttpclient-2.1.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bb1a459de3177b6c0b531ea38d0ef8cbcb1e566963022e00b1c5df0fd275410 |
|
MD5 | 523070e616bf28e89f86e354c6592d1e |
|
BLAKE2b-256 | 640dc190b190fbb3634a74fcde23ffdacd6ccfa2e9ecb40183f276982a7ea8c5 |
Hashes for geventhttpclient-2.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df2c8528f1d9559b9eb69e0e59c631603ec183a59888423a08d6b821f028e13a |
|
MD5 | f8f3d00fde817e479f1270ebcc803603 |
|
BLAKE2b-256 | 64ca09faf34b664952f38a34abc3bfd8c012828bcd65c38bab0ced9f7995c5ac |
Hashes for geventhttpclient-2.1.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16535b05c1ebb5927e47e2175f5c092ad586c8c7bb3cc25425bc4df5608d1b3f |
|
MD5 | ae28abad2c181948053a0ee0b3b1cdea |
|
BLAKE2b-256 | 8fba2a94b6fc4dab73e720d2d54226d10f9b4115090061df1ee0e8a7bf485964 |
Hashes for geventhttpclient-2.1.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 573f43cb10ea77f153290a0a036d119c65b259a0a6ddaef1235b604a22eee9c6 |
|
MD5 | 841ce8b83deec4aca8aeac8299aed98b |
|
BLAKE2b-256 | 50da473f148aa2ad48ba4ee4003afda487c47c03c1aa121a6bdfcd30786632a7 |
Hashes for geventhttpclient-2.1.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a35123133c6802016e45807dd480fd17aff61fc993f992fe2ca6407c5a7dc80 |
|
MD5 | a23b0e2f1b24d2de1a786bfca123d133 |
|
BLAKE2b-256 | 47cddedf0236c0dba4d6f139dfd13fc7688eb73fae9f1e88f0df15a281a7ff6c |
Hashes for geventhttpclient-2.1.1-cp311-cp311-musllinux_1_1_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d60e2cd2175779a186c9107fac1a43a05b1acf4d454678b2f0e890a6b68917a5 |
|
MD5 | e790dd9d70a0781d1c158e1fe306ddf9 |
|
BLAKE2b-256 | 3a2de1aea5842477f7fa48d08cc33a007ce8a00bb5cb1236d366a10e02c2d05b |
Hashes for geventhttpclient-2.1.1-cp311-cp311-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17b6e8fb98e8ca0ae51edd121feba99652a4aa56346ef3f2a11de0bbd77c41de |
|
MD5 | 4b24962d33288f81437c320a68e655f5 |
|
BLAKE2b-256 | 6ed75e00fc644d445b52b257fbd0878d71acab30dd0c226da77899a6920a471d |
Hashes for geventhttpclient-2.1.1-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d93c87809265409e16365beea22a249d36772aaf44c0fc11e5d36233ace913cc |
|
MD5 | b6680585b8a09705bfe62b51008c776c |
|
BLAKE2b-256 | e611f5188d6eb5f2994495fc70f64dfa359b35cc123825679ab671642e07a88a |
Hashes for geventhttpclient-2.1.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a11efde43e5b9accb89642f16aa7f73c42a740e4e857a1db8cfee1307502cdb0 |
|
MD5 | f52cdd7d5666f64244b126e29c5a8229 |
|
BLAKE2b-256 | d59a7fa78d5ad77b77d62382ae1c1f8786daee3abc78e2af40660f351f4c0bee |
Hashes for geventhttpclient-2.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dc8fc0a6ecf63be21c9d37a51d2df30582bad79deab4fe1acab5effe37f0881 |
|
MD5 | 6dd6cae71f929bb51c8a486720f38074 |
|
BLAKE2b-256 | 5a5aa3d23ae96ee2d2711728b5ee0ab082277228326384814126cf82f1f64f5f |
Hashes for geventhttpclient-2.1.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c695d8056df07592b1fa4dcc54a20b3e28ab2f2ee1e0b01965e42b0a612fd72d |
|
MD5 | 62c605431c3b5b537108e300dd9aa50a |
|
BLAKE2b-256 | d4ca5bdb88b91818681214be76ff5349fae896f5e9b6925f1cc1b8a09727438c |
Hashes for geventhttpclient-2.1.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 948a86b0186304ea237daa1f9db8e498cd2aa8e0a139364f82095a329a714b37 |
|
MD5 | fb52e75b463860f681d43744d7080d0f |
|
BLAKE2b-256 | 26d608bb594fb714fca765ac9932b920d9d9a1374bfc8952c9667a73c678ea30 |
Hashes for geventhttpclient-2.1.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14c82fbcfefb85cc7ce6fc29d66e44c49444c9454b1e7945e7e4cc5a7cd48d64 |
|
MD5 | 23d45eafc237202e63312b25d7ae206d |
|
BLAKE2b-256 | f681e6f05d725d9fe80b9d441d5679fd4668406c0f15dcd052ea79a7e72e8f5a |
Hashes for geventhttpclient-2.1.1-cp310-cp310-musllinux_1_1_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8a3c3e9d2899637f559c9ac3b8d83c99fd08e5ade9132de8f65b0ce93dbc356 |
|
MD5 | 44e9eca9b8804d1b576b4175e8fd2511 |
|
BLAKE2b-256 | f29cb74658e5476a6dbbdf9fb515b5b03c1f3966fb7049c38f358674fde536cb |
Hashes for geventhttpclient-2.1.1-cp310-cp310-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed6156fecd094081f8d494b8e7e05c3565b55e36e968c9dccd8a7513bdfa5d14 |
|
MD5 | ea1619ff9b31804400dda579085e0e30 |
|
BLAKE2b-256 | 71ade3d65d407f48c1e6bb457037d8a67ef42e1a23d54de28a5992f61d14c2a3 |
Hashes for geventhttpclient-2.1.1-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a119d98962b53f616c3ee9ae76edda9bf8fac725340992f9cfe3bc626a74e0a |
|
MD5 | 8fbfc6f94fc44cd802ca7b271748b1a3 |
|
BLAKE2b-256 | 43bb9a0f07606962687a44f8d6570a639b668d221fe3ddc8d2810e96de3093dc |
Hashes for geventhttpclient-2.1.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3595338b3db0665ab80df2a8cbf3cc011b3dc24d57cd464ad48054a3cad69bed |
|
MD5 | 477f5ee1285442efd6b32d33fc00b745 |
|
BLAKE2b-256 | 2c51424f183f3555d7c4284e536f0bd2b42335e4462fd7263cf4f5a81685a70e |
Hashes for geventhttpclient-2.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af5b38d09f923ec8884c409afec19a357a17f2ec5b54520203b0bab04119a070 |
|
MD5 | 880d980f0de34f30e77ffc464634c6d7 |
|
BLAKE2b-256 | e4cef3eeb47a70cbf1f2e4aaadb277ac3b7647e152ca2592ed126edd10700754 |
Hashes for geventhttpclient-2.1.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a178e0de4f1f255e3feb5eb5d16913f249f43d0e345851e9e21bbaeff6eeda0 |
|
MD5 | b2b29e896d94c60912b5f419e818bdda |
|
BLAKE2b-256 | 97c4d4ccb57e6cb6098830d73c9c15fe60f997001923315dc56b14f952f126c1 |
Hashes for geventhttpclient-2.1.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 229fbd0f7f0e9661931eac42f0b2f895b8597393ef363a88420a1315e3bbb161 |
|
MD5 | b8420570b050ae30585a70b6c61eaf67 |
|
BLAKE2b-256 | 422e0ba221d810a41cc180af1394cf9da7e2510605b9603051fa5f475313d4c6 |
Hashes for geventhttpclient-2.1.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19be262f1b7d56da09617f40f80278ee37c9e2eeff8f9f837ea23a1a505b1a56 |
|
MD5 | 4d1d9d67264019ee2ab88213d039a69d |
|
BLAKE2b-256 | e43d8f14817324a5f9db8d5f0e2d5ceede2d7f07c3b91df3bbd99100176deb2e |
Hashes for geventhttpclient-2.1.1-cp39-cp39-musllinux_1_1_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12ebb5b931fcb6e3020237f1bf2c10309bbe9475a6f8eaa0b21b5a2d3a560c7d |
|
MD5 | dff9bbed997a011daf52f4c38bb11d1e |
|
BLAKE2b-256 | cc2b1000b4254d16dd4e9e96cbfc8ab9028e8309b671cb190d2ab2b8fc70f57b |
Hashes for geventhttpclient-2.1.1-cp39-cp39-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fe3626fb0e5194e9affdc43284eed583eb0c116f612607b64bb99328d327991 |
|
MD5 | 0631f75ed2a9750fc1d019d2046e1d80 |
|
BLAKE2b-256 | 43ede39ee87277d656079c73ac6e7922303f37d66dfe07ed44ae0a88eb12003a |
Hashes for geventhttpclient-2.1.1-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2be70e3b55a11bcf25a27d60f04c1853c9b2f290501050eaa82b085b944c8e09 |
|
MD5 | 117af124e355eeb12d3336d806bf8a13 |
|
BLAKE2b-256 | 89f90c11873bfba955d2b34cba55d0848da778510927cc36a8e7bbbee4076448 |
Hashes for geventhttpclient-2.1.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1346535081e9debcac26bed23b374eddc3ea7a479a08e7225129ecc264d5fb10 |
|
MD5 | 33f0c5715080223232dc04040e645e12 |
|
BLAKE2b-256 | f63aee514fb37c8576ac7c2d48959d37627eb6a03a851d7fb51ba51862a29200 |
Hashes for geventhttpclient-2.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c72fdf5115d882b375c83390c00753326c6d5342427c22b1b0d9ec6d5261bd9 |
|
MD5 | 82d8ccacd04b34e19af9bebd0a8e4bb8 |
|
BLAKE2b-256 | b221cba73e1f458c6441c98b60afe1db16340c6bf93b11a1df29f5230fd64e78 |
Hashes for geventhttpclient-2.1.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba2dba25615ec00a0070e9480efe1ad0e349e1cdf9e216556e4c57374217f3ea |
|
MD5 | b31f635e834770147a0f08f9d11f5bd4 |
|
BLAKE2b-256 | e529a0a1c80306be0aee096ef8e1d0766bff0410b21987f4ec5f19a6ff2e82a9 |
Hashes for geventhttpclient-2.1.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 185d65295fb36b8a5f748fcb521a2d2c9db706efadde558f1ce8a2b1b2ffab65 |
|
MD5 | 50876d5270c944e8acf220770db9d41d |
|
BLAKE2b-256 | f788befb294c7045ef65845dbf76bc17ed93c164e868dfe7b4e470709e187e1b |