Skip to main content

A thin wrapper for aiohttp client with Requests simplicity

Project description

aiohttp-requests

Behold, the power of aiohttp client with Requests simplicity:

import asyncio

import aiohttp
from aiohttp_requests import requests

async def main():
    response = await requests.get('https://api.github.com', auth=aiohttp.BasicAuth('user', 'password'))
    text = await response.text()
    json = await response.json()
    return response, text, json

r, text, json = asyncio.run(main())

>>> r
<ClientResponse(https://api.github.com/) [200 OK]>
>>> r.status
200
>>> r.headers['Content-Type']
'application/json; charset=utf-8'
>>> r.get_encoding()
'utf-8'
>>> text
'{"current_user_url":"https://api.github.com/user",...'
>>> json
{'current_user_url': 'https://api.github.com/user', ... }

Plus built-in concurrency control to do multiple requests safely:

async def main():
    # Pass in a list of urls instead of just one. Optionally pass in as_iterator=True to iterate the responses.
    responses = await requests.get(['https://api.github.com'] * 2, auth=aiohttp.BasicAuth('user', 'password'))
    print(responses)    # [<ClientResponse(https://...) [200 OK]>, , <ClientResponse(https://...) [200 OK]>]

    # It defaults to 10 concurrent requests. If you can handle more, then set it higher:
    requests.max_concurrency = 100

asyncio.run(main())

The requests object is just proxying get and other HTTP verb methods to aiohttp.ClientSession, which returns aiohttp.ClientResponse. To do anything else, read the aiohttp doc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp-requests-0.2.3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_requests-0.2.3-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp-requests-0.2.3.tar.gz.

File metadata

  • Download URL: aiohttp-requests-0.2.3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for aiohttp-requests-0.2.3.tar.gz
Algorithm Hash digest
SHA256 7937cc5dac857b0da3cebb36644a36d5e3473f66d75f436002510786dceac92f
MD5 2208dbe38c88dcbc8a3f7e70e0af0025
BLAKE2b-256 ed52c442fe4bffb57c34510eb575d87f19dda399f61616ec6f331582d08ec26d

See more details on using hashes here.

File details

Details for the file aiohttp_requests-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp_requests-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bf99f8c9b0f10f65a0ad0927ea55fa6948a3f4bfe9305114b6b91ab9c8c5336d
MD5 f421133ee78b85c4255825c4b9227296
BLAKE2b-256 0f20ebb002e691f4d6d92ac2418e2c9fcbac93edf9d9037fa16412351fdde040

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page