Skip to main content

Async http client

Project description

Build Status Azure Build Status Coverage Status PyPI version Documentation Status Gitter

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.56 ms",
 "aiosonic cyclic": "1000 requests in 207.75 ms",
 "aiohttp": "1000 requests in 357.19 ms",
 "requests": "1000 requests in 4274.21 ms",
 "httpx": "1000 requests in 800.98 ms"
}
aiosonic is 223.05% faster than aiohttp
aiosonic is 3765.79% faster than requests
aiosonic is 87.90% faster than aiosonic cyclic
aiosonic is 624.45% 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
  • Sessions with Cookie Persistence
  • Basic/Digest Authentication
  • 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

  1. Fork
  2. create a branch feature/your_feature
  3. commit - push - pull request

Thanks :)

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

aiosonic-0.7.2.tar.gz (16.7 kB view details)

Uploaded Source

File details

Details for the file aiosonic-0.7.2.tar.gz.

File metadata

  • Download URL: aiosonic-0.7.2.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.7

File hashes

Hashes for aiosonic-0.7.2.tar.gz
Algorithm Hash digest
SHA256 8a9c60157717da88af03ddb06ec767246f9b200128cbe0232db00e3bc1dd9974
MD5 924a236b7b5ed0c6e9e0324e884ca200
BLAKE2b-256 2264c953e9f00c04b394ec4a9b9e0d094021ca99faa4c945e0f550dc2dc5ed5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page