Skip to main content

Lightweight Python asyncio HTTP/1.1 client.

Project description

lowhaio CircleCI Test Coverage

A lightweight Python asyncio HTTP/1.1 client. No additional tasks are created; all code is in a single module; and other than the standard library only a single dependency is required, aiodnsresolver.

Connections are DNS-aware, in that they are only re-used if they match a current A record for the domain.

Installation

pip install lowhaio

Usage

The API is streaming-first: for both request and response bodies, asynchronous iterators are used.

import os
from lowhaio import Pool

request, _ = Pool()

path = 'my.file'
content_length = str(os.stat(path).st_size).encode()
async def file_data():
    with open(path, 'rb') as file:
        for chunk in iter(lambda: file.read(16384), b''):
            yield chunk

code, headers, body = await request(
    b'POST', 'https://example.com/path',
    params=(), headers=((b'content-length': content_length),), body=file_data,
)
async for chunk in body:
    print(chunk)

However, there are helper functions streamed and buffered when this isn't required or possible.

from lowhaio import Pool, streamed, buffered

request, _ = Pool()

content = b'some-data'
content_length = b'9'
code, headers, body = await request(
    b'POST', 'https://example.com/path',
    params=(), headers=((b'content-length': content_length),), body=streamed(content),
)

response = await buffered(body)

Headers

The only header automatically added to requests is the host header, which is the idna/punycode-encoded domain name from the requested URL.

Exceptions

Exceptions raised are subclasses of HttpError. If a lower-level exception caused this, it is set in the __cause__ attribute of the HttpError

Exceptions before any data is sent are instances of HttpConnectionError, and after data is sent, HttpDataError. This is to make it possible to know if non-idempotent requests can be retried.

Scope

The scope of the core functions is restricted to:

  • (TLS) connection opening, closing and pooling;
  • passing and receiving HTTP headers and streaming bodies;
  • decoding chunked responses;
  • raising exceptions on timeouts.

This is to make the core behaviour useful to a reasonable range of uses, but to not include what can be added by layer(s) on top. Specifically not included:

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

lowhaio-0.0.70.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lowhaio-0.0.70-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file lowhaio-0.0.70.tar.gz.

File metadata

  • Download URL: lowhaio-0.0.70.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.22.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for lowhaio-0.0.70.tar.gz
Algorithm Hash digest
SHA256 6ee400587cc7ac21cdbc5a9a03d9f6c0022c7cb675ba2c8014b99671b08d6bef
MD5 565bbf1b0e29ed383da7139ed76fa0a8
BLAKE2b-256 e3d5038bf32f1c744dd303819c912be83131145ac950834ec11e94a8e5dd41f9

See more details on using hashes here.

File details

Details for the file lowhaio-0.0.70-py3-none-any.whl.

File metadata

  • Download URL: lowhaio-0.0.70-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.22.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for lowhaio-0.0.70-py3-none-any.whl
Algorithm Hash digest
SHA256 059a2f82fe332ee8612665a28eedd658188aa92d821f8cd15944d26199b12f71
MD5 b34afd6d1f4e74b989f847c20a99c994
BLAKE2b-256 4f883b988ec9e44190c2f99904c0bfd90de8284ff9d39449834880292709b001

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