Python aiohttp client
Project description
aiohttp client
What is the difference from aiohttp.Client?
It is simpler and as a Requests
Install beta:
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.0.0.tar.gz
(5.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aio_clients-2.0.0.tar.gz.
File metadata
- Download URL: aio_clients-2.0.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1042-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3079b6a69d301fbb9a8737fd4e17074887336e038574f116ec4a46dbfa092da1
|
|
| MD5 |
f8d32128825e3e9970f3a4aa8420f2ab
|
|
| BLAKE2b-256 |
b9bc8535b3318a1563aa23d20e746a6027853ead6f4c751f0abd1189c2c5e287
|
File details
Details for the file aio_clients-2.0.0-py3-none-any.whl.
File metadata
- Download URL: aio_clients-2.0.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1042-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cc1930c4ed8510cf3f047ef2178c1a591fd57bdd5ce7544ddda21c0a9dfbbe9
|
|
| MD5 |
e8b516bebc769ac1f9d958e8278ad15d
|
|
| BLAKE2b-256 |
f303853b9da5f7036ea5eb2ca85868ef089e88074314191ac12c16582f68284b
|