Skip to content

An asynchronous requests. requests + asyncio.:star2:

Notifications You must be signed in to change notification settings

HuberTRoy/asrequests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AsRequests: Asyncio + Requests.

AsRequests allow you to use Requests with asyncio to make asynchronous HTTP Requests easily.

Usage:

Usage is simple:

from  asrequests import AsRequests

urls = [
    'http://nodomain/',
    'https://github.com',
    'https://www.python.org/'
]

Send them all the same time.

>>> with AsRequests() as ar:
            for i in urls:
                ar.get(i)
...
>>>print(ar.result)
[<Response [200]>, ErrorRequest(url='http://nodomain/', text='', ...), <Response [200]>]

Using like requests:

from asrequests import asrequests

async def get_http():
        for i in urls:
            response = await asrequests.get(i)
            print(response)

....
asyncio.run_until_complete(get_http)

===
<Response [200]>
ErrorRequest(url='http://nodomain/', text='', ...)
<Response [200]>

Use callback:

>>> def my_callback(result):
            if not result.get(error_info, False):
                print("This url '{url}' is connectable.".format(result.url))
            else:
                print("This url '{url}' is unconnectable.".format(result.url))
>>> with AsRequests(callback=my_callback) as ar:
            for i in urls:
                ar.get(i)
...
This url 'https://github.com/' is connectable.
This url 'http://nodomain/' is unconnectable.
This url 'https://www.python.org/' is connectable.
>>>

Installation.

Installation is easy with pip:

$ pip install asrequests
✨🍰✨

About

An asynchronous requests. requests + asyncio.:star2:

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages