Skip to main content

asynchttp is an almost drop in replacement for httplib2 that provides asynchronous http request behavior.

asynchttp uses python threading and Queues and provides callback mechanisms to allow de-serialization and process to happen in the background (worker threads) as well. You can queue up arbitrary numbers of requests and a specified maximum number of workers will process each request in turn.

There are two known differences between straight httplib2 and asynchttp:

  • exceptions are thrown when the response and/or content is accessed. since sending the request and receiving the response is happening in the background exceptions won’t be thrown during the call to request.

  • content (returned from request) is an object rather than a plain string. This is required since the content isn’t actually known until the background worker has completed the request, the returned content is a “promise” object of sorts. It defines a __str__ method that should in most cases cause the object to behave as required, but unfortunately there may be times when you have to str(content) to force it in to a string to get the desired behavior. (a side note, but content should really be a buffer/io object rather than a plain string in the first place.)

Example

A simple example making a single request (not that interesting):

>>> from asynchttp import Http
>>> http = Http()
>>> url = 'http://proximobus.appspot.com/agencies.json'
>>> response, content = http.request(url)
# http.request will return immediately and response and content will be
# "promise" objects that will block (if necessary) when accessed. you
# could/should continue to do other work or send off more requests here and
# when you're ready...
>>> print response.status
200
# if the request had already completed in the background the status code
# would immediately print. if not the script would block until the work had
# completed and then print.

See the examples directory for more detailed/interesting examples.

Logging

Asynchronous code can be a pain to debug so asynchttp is pretty aggressive when it comes to logging. If you’re trying to track things down your best bet is probably to turn on debug logging, at least for the asynchttp logger, and to use a format that includes the the time and thread id or name.

Adding the following snippet to your app should do the trick:

import logging

fmt = '%(asctime)s %(thread)d %(name)s %(levelname)-8s %(message)s'
logging.basicConfig(level=DEBUG, format=format)

Metadata

Release files for asynchttp 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asynchttp 0.0.4
File Size Uploaded Provenance
asynchttp-0.0.4.tar.gz 4.6 kB Without provenance Details

Release files / asynchttp-0.0.4.tar.gz

Download URL asynchttp-0.0.4.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
92f375f935790ab641508bb6285163ffd89cf528095cc93d99ee253a86086a84
BLAKE2b-256 checksum
How to use checksums
f6a0dd8f751c63b0484f0680fb7444184c953c2150b1fdbd948d6f29cb6d194c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for asynchttp 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.4 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page