Simple wrapper for aiohttp. Designed for my own use but might be useful to others.
Project description
aiohttphelper
Context
The purpose of this package is to make a simple wrapper for aiohttp/calls in order to use it in my personnal / professional projects.
It will make one or several calls using the same session and coroutines.
Requirements
Installation / Dependencies
pip install aiohttphelper
The following dependencies will also be installed
aiohttp[speedups]==3.6.2
Usage
First import the module:
import aiohttphelper
You have 4 functions avilable to you:
aiohttphelper.get(calls, headers, **kwargs)
aiohttphelper.put(calls, headers, **kwargs)
daiohttphelper.post(calls, headers, **kwargs)
aiohttphelper.delete(calls, headers, **kwargs)
Calls is a list of the urls to request. In case of put/post you need to provide a tuple (url, data):
aiohttphelper.put((url, data), headers, **kwargs)
They all return the same thing:
[response.text(), response.status]
As it's build in top of aiohttp **kwargs is used to pass parameters to the request. Look at the documentation for more details.
:warning: !Be carefull the default timeout for the session is 5 minutes, but you can override it:
aiohttphelper.get('dummy_url', headers='dummy_headers', timeout="10000")
Error Handling
By default all the calls that does not succed will raise an error:
aiohttp.client_exceptions.ClientResponseError
If you want to carry on with the calls even if one fails you need to pass raise_for_status=False
as an argument.
If you do so the result will contain the response text and response status in any successfull request.
References
aiohttp Licence Copyright 2013-2020 aiohttp maintainers
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
Built Distribution
Hashes for aiohttphelper-1.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 976a649c413b7c4535b6cf1bf2e474f32588ff5b3184b4938fb1cf1326fcdedf |
|
MD5 | 2f188a0bd12623d7c9d8efd90bf10431 |
|
BLAKE2b-256 | fc5cdacf26631c8b767a33334cb33283dc820b26206593a172b786164abda670 |