Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aio-clients

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aio-clients

Python aiohttp client

  • 2.1.0
  • PyPI
  • Socket score

Maintainers
1

aiohttp client

Tests Published Coverage Status PyPi version PyPI - Python Version PyPI - Downloads PyPI - License

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())

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc