Async http client
Project description
aiosonic - a Python asyncio http client
Very fast Python asyncio http client
Here is some documentation.
There is a performance script in tests folder which shows very nice numbers
» python tests/performance.py
doing tests...
{
"aiosonic": "1000 requests in 110.03 ms",
"aiosonic cyclic": "1000 requests in 332.10 ms",
"aiohttp": "1000 requests in 427.31 ms",
"requests": "1000 requests in 4915.04 ms",
"httpx": "1000 requests in 638.04 ms"
}
aiosonic is 288.36% faster than aiohttp
aiosonic is 4367.04% faster than requests
aiosonic is 201.83% faster than aiosonic cyclic
aiosonic is 479.89% faster than httpx
You can perform this test by installing all test dependencies with pip install -e ".[test]"
and doing python tests/performance.py
in your own machine
Requirements:
- Python>=3.6
Features:
- Keepalive and smart pool of connections
- Multipart File Uploads
- Chunked responses handling
- Chunked requests
- Connection Timeouts
- Automatic Decompression
- Follow Redirects
- Fully type annotated.
- 100% test coverage.
Installation
pip install aiosonic
Usage
import asyncio
import aiosonic
import json
async def run():
client = aiosonic.HttpClient()
# ##################
# Sample get request
# ##################
response = await client.get('https://www.google.com/')
assert response.status_code == 200
assert 'Google' in (await response.text())
# ##################
# Post data as multipart form
# ##################
url = "https://postman-echo.com/post"
posted_data = {'foo': 'bar'}
response = await client.post(url, data=posted_data)
assert response.status_code == 200
data = json.loads(await response.content())
assert data['form'] == posted_data
# ##################
# Posted as json
# ##################
response = await client.post(url, json=posted_data)
assert response.status_code == 200
data = json.loads(await response.content())
assert data['json'] == posted_data
# ##################
# Sample request + timeout
# ##################
from aiosonic.timeout import Timeouts
timeouts = Timeouts(
sock_read=10,
sock_connect=3
)
response = await client.get('https://www.google.com/', timeouts=timeouts)
assert response.status_code == 200
assert 'Google' in (await response.text())
await client.shutdown()
print('success')
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
TODO'S
- HTTP2
- Get
- Request with data sending
- Better documentation
- International Domains and URLs (idna + cache)
- Requests using a http proxy
- Basic/Digest Authentication
- Sessions with Cookie Persistence
- Elegant Key/Value Cookies
Development
Install packages with pip-tools:
pip install pip-tools
pip-compile
pip-compile test-requirements.in
pip-sync requirements.txt test-requirements.txt
Contribute
- Fork
- create a branch
feature/your_feature
- commit - push - pull request
Thanks :)
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
aiosonic-0.9.3b1.tar.gz
(142.8 kB
view hashes)
Built Distributions
Close
Hashes for aiosonic-0.9.3b1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bb7c84285eb1d9ce3b72b300fae08134479e9dec90a9ae8b43d8d553b072e7a |
|
MD5 | 7da9266add64d7ba96c70b04670dec4f |
|
BLAKE2b-256 | 32912d1fc7eca069aa84a5c52cd338d52e96ec1996fc4f71269ff0e8d52fc74f |
Close
Hashes for aiosonic-0.9.3b1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45ca68b988436719f0386051b92277b30e12a94180aaa2f39ebee16da5f8402e |
|
MD5 | 3dbe43c23c1bc7c01905e735a0a4c018 |
|
BLAKE2b-256 | 9f0883d80fc35ced47ec6d9f692d2cedd717dd588984822b962edff6a3b49a1e |
Close
Hashes for aiosonic-0.9.3b1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aee8807369d276eadac3297607ae11306db0f45a9c6911b978090ac2c886fe7 |
|
MD5 | 199fd310276f0c0f6d77f4f3b1342ada |
|
BLAKE2b-256 | fef8bd035e2f84619f57db434caf5816da71fe6a901f0514d8be2e5ea21b52ea |