Package: aioreq
Aioreqis a Python asynchronous HTTP client library. It is built on top of TCP sockets and implements the HTTP protocol entirely on his own.DocumentationClick hereInstallFrompypi$pipinstallaioreqFromGitHub$gitclonehttps://github.com/karosis88/aioreq
$pipinstall./aioreqAioreqcan be used as a Python library or as a command-line tool to make HTTP requests.Basic UsagePython>>>importaioreq>>>response=aioreq.get("http://127.0.0.1:7575/")>>>response.status200>>>content_type=response.headers["content-type"]# Case insensitive>>>response.contentb'Hello World'or in async context>>>importasyncio>>>>>>asyncdefmain():...asyncwithaioreq.Client()asclient:...response=awaitclient.get("http://127.0.0.1:7575")...returnresponse>>>asyncio.run(main())<Response 200 OK>CLIAioreqcli tools are very similar tocurl, so if you've used curl before, you should have no trouble.$aioreqhttp://127.0.0.1:7575/cli_doc
HelloWorldWhen performing HTTP requests, there are a few options available.--method -XSpecify HTTP method--verbose -vShow HTTP request headers--include -iInclude HTTP response headers--output -oOutput file--headers -HSend custom headers--data -dHTTP POST data--user-agent -ASet User-Agent headerHere are some examples of requests.$aioreqhttp://127.0.0.1:7575$aioreqhttp://127.0.0.1:7575/cli_doc-d"Bob"-XPOST
UserBobwascreated!
$aioreqhttp://127.0.0.1:7575/cli_doc-o/dev/null

$aioreqhttp://127.0.0.1:7575/cli_doc-v-H"custom-header: custom-value"\"second-header: second-value"========REQUESTHEADERS========user-agent:python/aioreq
accept:*/*
custom-header:custom-value
second-header:second-value
accept-encoding:gzip;q=1,deflate;q=1HelloMiddlewaresAioreqnow supports 'middleware' power.The first steps with middlewareAioreq provides default middlewares to each client.
We can see that middlewares by importing 'default_middlewares'  variable.>>>importaioreq>>>aioreq.middlewares.default_middlewares('RetryMiddleWare','RedirectMiddleWare','CookiesMiddleWare','DecodeMiddleWare','AuthenticationMiddleWare')The first item on this list represents the first middleware that should handle our request (i.e. theclosest middleware to our client), while the last index represents theclosest middleware to the server.We can pass our modified middlewares tuple to the Client to override the default middlewares.>>>client=aioreq.Client(middlewares=aioreq.middlewares.default_middlewares[2:])This client will no longer redirect or retry responses.Also, because aioreq stores middlewares in Client objects as linked lists, we can simply change the head of that linked list to skip the first middleware.>>>client=aioreq.Client()>>>client.middlewares.__class__.__name__'RetryMiddleWare'>>>>>>client.middlewares=client.middlewares.next_middleware>>>client.middlewares.__class__.__name__'RedirectMiddleWare'>>>>>>client.middlewares=client.middlewares.next_middleware>>>client.middlewares.__class__.__name__'CookiesMiddleWare'or>>>client=aioreq.Client()>>>client.middlewares=client.middlewares.next_middleware.next_middleware>>># alternative for client = aioreq.Client(middlewares=aioreq.middlewares.default_middlewares[2:])Create your own middlewares!All 'aioreq' middlewares must be subclasses of the classmiddlewares.MiddleWareMiddleWare below would add 'test-md' header if request domain iswww.example.com>>>importaioreq>>>>>>classCustomMiddleWare(aioreq.middlewares.MiddleWare):...asyncdefprocess(self,request,client):...ifrequest.host=='www.example.com':...request.headers['test_md']='test'...returnawaitself.next_middleware.process(request,client)...>>>client=aioreq.Client()>>>client.middlewares=CustomMiddleWare(next_middleware=client.middlewares)Our CustomMiddleWare will now be the first middleware (i.e. closest to the client). Because 'aioreq' middlewares are stored as linked lists, this pattern works (i.e. same as linked list insert method).Alternatively, we can alter the list of middlewares that the client receives.>>>client=aioreq.Client(middlewares=(CustomMiddleWare,)+aioreq.middlewares.default_middlewares)>>>client.middlewares.__class__.__name__'CustomMiddleWare'SSL/TLSAioreq supports three attributes related to this topic.check_hostnameChecks whether the peer cert hostname matches the server domain.verify_modeSpecifies whether the server certificate must be verified.keylog_filenameFile location for dumping private keysYou can also set the environment variableSSLKEYLOGFILEinstead of specifyingkeylog_filename.You can use a tool likewiresharkto decrypt yourHTTPStraffic if you have a file with the private keys.Example:$exportSSLKEYLOGFILE=logsThen just run aioreq.$aioreqhttps://example.com
$ls-l
total8-rw-r--r--1useruser406Dec517:19logsNow, the 'logs' file contains keylogs that can be used to decrypt your TLS/SSL traffic with a tool such as 'wireshark'.Here are a few examples of how to manage the SSL context for your requests.importaioreqdont_verify_cert=aioreq.get("https://example.com",verify_mode=False)verify_and_dump_logs=aioreq.get("https://example.com",verify_mode=True,keylog_filename="logs")default_configs=aioreq.get("https://example.com",verify_mode=True,check_hostname=True)AuthenticationIf theauthparameter is included in the request, Aioreq will handle authentication.There are two types of authorization that aioreq can handle.Digest AuthorizationBasic AuthorizationIf the incoming response status code is401and the header containswww-authorization,aioreqwill attempteachof the schemes until authorization is complete.>>>importaioreq>>>importasyncio>>>asyncdefsend_req():...asyncwithaioreq.Client()ascl:...returnawaitcl.get('http://httpbin.org/basic-auth/foo/bar',auth=('foo','bar'))>>>resp=asyncio.run(send_req())>>>resp.status200Parameterauthshould be a tuple with two elements: login and password.Authentication is enabled byAuthenticationMiddleWare, so exercise caution when managing middlewares manually.BenchmarksIn this benchmarks, we compareaioreqandhttpxduring 999 asynchronous requests, without cachingYou can run these tests on yourlocal machine; the directory `aioreq/benchmarkscontains all of the required modules.$ cd benchmarks
$ ./run_tests
Benchmarks
---------------------------
aioreq benchmark
Total time: 2.99
---------------------------
httpx benchmark
Total time: 7.60Supported FeaturesAioreqsupport basic features to work withHTTP/1.1.More functionality will be available in future releases.This is the latest version features.Keep-Alive (Persistent Connections)MiddlewaresKeylogsAuthenticationCookiesAutomatic accepting and decoding responses. UsingAccept-EncodingheaderHTTPS support, TLS/SSL VerificationRequest Timeouts