Async http client
Project description
aiosonic - lightweight Python asyncio http client
Very fast, lightweight 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 105.53 ms",
"aiosonic cyclic": "1000 requests in 104.08 ms",
"aiohttp": "1000 requests in 184.51 ms",
"requests": "1000 requests in 1644.21 ms"
}
aiosonic is 74.84% faster than aiohttp
aiosonic is 1457.99% faster than requests
aiosonic is -1.38% faster than aiosonic cyclic
This is a very basic, dummy test, machine dependant. If you look for performance, test and compare your code with this and other packages like aiohttp.
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.8
- PyPy>=3.8
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 (Sometimes not).
- HTTP2 (BETA) when using the correct flag
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())
print('success')
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
TODO'S
- HTTP2
- Get
- Request with data sending
- Do a aiosonic release with stable http2
- Better documentation
- International Domains and URLs (idna + cache)
- Basic/Digest Authentication
- Requests using a http proxy
- Sessions with Cookie Persistence
- Elegant Key/Value Cookies
Development
Install packages with poetry
Reference: https://python-poetry.org/docs/
poetry install
It is advised that you should install poetry in a serparate virtualenv (I suggest to install it with apt/pacman/etc.), other than the one you may use for development in aiosonic.
I do configure poetry with poetry config virtualenvs.in-project true
so it uses a virtualenv created in .venv/
, in aiosonic folder.
Running tests
poetry run py.test
Contribute
- Fork
- create a branch
feature/your_feature
- commit - push - pull request
Thanks :)
Contributors
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 Distribution
File details
Details for the file aiosonic-0.22.0.tar.gz
.
File metadata
- Download URL: aiosonic-0.22.0.tar.gz
- Upload date:
- Size: 23.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2391930c097376f02381be07630779cfdde829b14891ddd24faad91a0924e717 |
|
MD5 | cbefc35b68363443ec8139af117d8d89 |
|
BLAKE2b-256 | f8402748a03955a900b976175876d9161782b0ac503ab9ffb9a7877ceec489e3 |
File details
Details for the file aiosonic-0.22.0-py3-none-any.whl
.
File metadata
- Download URL: aiosonic-0.22.0-py3-none-any.whl
- Upload date:
- Size: 26.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cb920f17e5c3fb2ece0f6e5bbc9f1f303cbe4cef8d217ba96ff87709d4a92a4 |
|
MD5 | e38ee7d4e1f8c39176bab6d9c99cb8ad |
|
BLAKE2b-256 | 6eb447f2f8516f8d469e33d55c836fd3de1dc52654146a591e93e2bafa544190 |