Skip to main content

An HTTP package for metering and managing async requests.

Project description

Tempo

Asynchronous wrapper for HTTP requests.

Installation

pip install tempo-async

Usage

import tempo

url = 'https://via.placeholder.com'
num_reqs = 100

requests = [ # map in any request parameters: url, query params, HTTP method, etc.
  tempo.RequestConfig(url=url) for _ in range(num_reqs)
]

if __name__ == '__main__':
  tempo.run(requests, rate=10) # fetch 100 cat pictures, 10 a second

Take it a step further by collecting the responses,

import tempo

url = 'https://via.placeholder.com'
num_reqs = 100

### cat picture bucket
catpics = []
###

requests = [ # map in any request parameters: url, query params, HTTP method, etc.
  tempo.RequestConfig(url=url) for _ in range(num_reqs)
]

if __name__ == '__main__':
  tempo.run(requests, collector=catpics, rate=10) # indicated `catpics` should store response
  print(f'Pictures stored in list: {len(catpics)}')

… and adding any number of processing functions to handle responses.

import tempo

url = 'https://via.placeholder.com'
num_reqs = 100
catpics = []

requests = [ # map in any request parameters: url, query params, HTTP method, etc.
  tempo.RequestConfig(url=url) for _ in range(num_reqs)
]

### processors
def say_hi(res) -> None:
  # returns None so does not affect final processed response sent to collectors
  print('Hello cat!')
 
def get_body(res) -> str:
  # since it returns a value, this processor changes the final output of `tempo.run`
  body = res.text
  return body
###

if __name__ == '__main__':
  # process the requests in order of listed processors
  tempo.run(requests, collector=catpics, rate=10, processors=[say_hi, get_body])
  # processors' return values affect output sent to collectors
  print(f'Type of stored result: {type(catpics[0])}') # str, not Response object

Contributing

Submit a pull request! Contributions are welcome!

Please write test coverage for your changes and run tox to test for backwards compatibility among the supported Python versions.

TODOS

Open an issue, create a branch, and submit a PR. (Tests for everything!)

  • Handle collection of results as a return value of the run function.
  • Decorator for basic async request function accepting iterator of request arguments.
  • Accept plain Python dictionaries and JSON in addition to RequestConfig objects for requests mapping.
  • Logging.
  • Exception handling.
  • GitHub Actions.
  • Retries with various back-off algorithms and HTTP response header search for 429 causes.
  • Generator option for run function.
  • Allow collector argument to be an iterable, a function passed a response / processed response object, or a file out. Maybe even stdout.
  • Like processors, allow multiple collectors (eg. file, queue).
  • Local database for keeping track of requests and their status, for retry and interrupts.
  • Asynchronous processor support.
  • Handle streaming responses.
  • CLI
  • Documentation page. Also, good docstrings.
  • Test coverage tracking.

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

tempo-async-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

tempo_async-0.1.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file tempo-async-0.1.1.tar.gz.

File metadata

  • Download URL: tempo-async-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.0 Windows/10

File hashes

Hashes for tempo-async-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d355c6c7a18f7818d4aa598e5e9656641aff710c50669355e60b2e799cb7e66d
MD5 912424203622bd6996c1a389e2345b93
BLAKE2b-256 5f2031bd36e35f49adeaf55dc182f411ddca0d86883019b87d94477ad5309839

See more details on using hashes here.

File details

Details for the file tempo_async-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tempo_async-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.0 Windows/10

File hashes

Hashes for tempo_async-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9b2c943f9da81bb0fa24a12e734623bc39afd4f104680b6a6d62230cc966bd25
MD5 e81edd1859645fb03d3d141d874b6e71
BLAKE2b-256 c74df7b5f6c5745e116048e661f305914873b1c36beeb3e6110978a2811b9106

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