Throttling, flow controlling StreamReader for aiohttp
Project description
Throttling, flow controlling StreamReader for aiohttp
Requirements
Python >= 3.3
License
aiothrottle is offered under the GPL v3 license.
Source code
The latest developer version is available in a github repository: https://github.com/panda73111/aiothrottle
Usage
import functools
import aiohttp
import aiothrottle
# setup the rate limit
kbps = 200
partial = functools.partial(
aiothrottle.ThrottledStreamReader, rate_limit=kbps * 1024)
aiohttp.client_reqrep.ClientResponse.flow_control_class = partial
# download a large file without blocking bandwidth
response = aiohttp.request("GET", "http://example.com/largefile.zip")
with open("largefile.zip", "wb") as file:
read_next = True
while read_next:
# read 1 MB chunks
chunk = response.content.read(2**20)
file.write(chunk)
read_next = len(chunk) != 0
response.close()
# unset the rate limit
aiohttp.client_reqrep.ClientResponse.flow_control_class = (
aiohttp.streams.FlowControlStreamReader)
CHANGES
0.1.0 (08-01-2015)
Initial release with basic throttling functionality
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
aiothrottle-0.1.0.zip
(5.7 kB
view hashes)
Built Distribution
aiothrottle-0.1.0-py3.4.egg
(6.7 kB
view hashes)