Python aiohttp client
Project description
aiohttp client
What is the difference from aiohttp.Client?
It is simpler and as a Requests
Install:
pip install aio-clients
Example:
Base reqeust:
import asyncio
from aio_clients import Http, Options
async def main():
r = await Http().get('https://google.com', o=Options(is_json=False, is_close_session=True))
print(f'code={r.code} body={r.body}')
asyncio.run(main())
Async reqeust
import asyncio
import aiohttp
from aio_clients import Http, Options
async def on_request_start(session, trace_config_ctx, params):
print("Starting request")
async def on_request_end(session, trace_config_ctx, params):
print("Ending request")
async def main():
trace_config = aiohttp.TraceConfig()
trace_config.on_request_start.append(on_request_start)
trace_config.on_request_end.append(on_request_end)
http = Http(
host='https://google.com/search',
option=Options(trace_config=trace_config, is_json=False),
)
r = await asyncio.gather(
http.get(q_params={'q': 'test'}),
http.get(q_params={'q': 'hello_world'}),
http.get(q_params={'q': 'ping'}),
)
print(f'status code={[i.code for i in r]} body={[i.body for i in r]}')
await http.close()
asyncio.run(main())
Multipart reqeust:
import asyncio
from aio_clients import Http, Options
from aio_clients.multipart import Easy, Form, File, Writer
async def main():
with Easy('form-data') as form:
form.add_form(Form(key='chat_id', value=12345123))
form.add_form(Form(key='audio', value='hello world'))
form.add_form(File(key='file', value=b'hello world file', file_name='test.py'))
r = await Http(option=Options(is_close_session=True, is_json=False)).post(
'http://localhost:8081',
form=form,
)
writer = Writer()
await form.write(writer)
print(f'code={r.code} body={r.body}')
print(f'full body:\n{writer.buffer.decode()}')
asyncio.run(main())
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
aio_clients-2.1.0.tar.gz
(6.0 kB
view details)
Built Distribution
File details
Details for the file aio_clients-2.1.0.tar.gz
.
File metadata
- Download URL: aio_clients-2.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e15ab3450ce64d877ea0d4426147d6b2149e5d9beaac18bb1d38977223fdf7d1 |
|
MD5 | 5894aeabf96d7fb2e6b4d3f51ef60902 |
|
BLAKE2b-256 | e579a08cd1d01df2a1c4b5a9a92f0f18dbc6906cf30cb097544f1bcc988e1b29 |
File details
Details for the file aio_clients-2.1.0-py3-none-any.whl
.
File metadata
- Download URL: aio_clients-2.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19f95dc90694db1904b4ae145fd42cc55cc3f66f74641266619b286df743b650 |
|
MD5 | 79e6c27072172f1dbb0aa2beeaf9d179 |
|
BLAKE2b-256 | 2f6509297298b3e25d69afcd7440ec0066bef6d2b1a31e1391a9fd35a1e41758 |