{"id":20710115,"url":"https://github.com/oxylabs/httpx-vs-requests-vs-aiohttp","last_synced_at":"2025-09-27T11:30:27.684Z","repository":{"id":224064573,"uuid":"762252541","full_name":"oxylabs/httpx-vs-requests-vs-aiohttp","owner":"oxylabs","description":"See how HTTPX, Requests, and AIOHTTP libraries compare for sending network requests and find out which one may fit your case better.","archived":false,"fork":false,"pushed_at":"2024-02-23T13:09:54.000Z","size":12,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-17T02:09:48.465Z","etag":null,"topics":["aiohttp","httpx","httpx-client","httpx-vs-aiohttp","httpx-vs-requests","python-requests","requests","requests-module","requests-vs-aiohttp","send-request"],"latest_commit_sha":null,"homepage":"https://oxylabs.io/blog/httpx-vs-requests-vs-aiohttp","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oxylabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-23T11:50:34.000Z","updated_at":"2024-10-29T12:38:09.000Z","dependencies_parsed_at":"2024-02-23T15:39:41.873Z","dependency_job_id":null,"html_url":"https://github.com/oxylabs/httpx-vs-requests-vs-aiohttp","commit_stats":null,"previous_names":["oxylabs/httpx-vs-requests-vs-aiohttp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fhttpx-vs-requests-vs-aiohttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fhttpx-vs-requests-vs-aiohttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fhttpx-vs-requests-vs-aiohttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fhttpx-vs-requests-vs-aiohttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oxylabs","download_url":"https://codeload.github.com/oxylabs/httpx-vs-requests-vs-aiohttp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234429243,"owners_count":18831240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aiohttp","httpx","httpx-client","httpx-vs-aiohttp","httpx-vs-requests","python-requests","requests","requests-module","requests-vs-aiohttp","send-request"],"created_at":"2024-11-17T02:09:54.551Z","updated_at":"2025-09-27T11:30:27.677Z","avatar_url":"https://github.com/oxylabs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTTPX vs Requests vs AIOHTTP\n\n[![Oxylabs promo code](https://raw.githubusercontent.com/oxylabs/product-integrations/refs/heads/master/Affiliate-Universal-1090x275.png)](https://oxylabs.io/pages/gitoxy?utm_source=877\u0026utm_medium=affiliate\u0026groupid=877\u0026utm_content=httpx-vs-requests-vs-aiohttp-github\u0026transaction_id=102f49063ab94276ae8f116d224b67)\n\n[![](https://dcbadge.limes.pink/api/server/Pds3gBmKMH?style=for-the-badge\u0026theme=discord)](https://discord.gg/Pds3gBmKMH) [![YouTube](https://img.shields.io/badge/YouTube-Oxylabs-red?style=for-the-badge\u0026logo=youtube\u0026logoColor=white)](https://www.youtube.com/@oxylabs)\n\n[HTTPX](https://www.python-httpx.org/) is a modern HTTP client for Python that aims to provide a more enjoyable and powerful experience for making HTTP requests. It was created to add support for asynchronous programming and has quickly gained popularity in the Python community due to its feature-rich API and good performance. In this article, we'll compare HTTPX to two other popular HTTP clients for Python: Requests and AIOHTTP.\n\nSee the full overview in our [blog post](https://oxylabs.io/blog/httpx-vs-requests-vs-aiohttp) where we delve deeper into each library.\n\n- [How HTTPX compares to the Requests module](#how-httpx-compares-to-the-requests-module)\n- [An overview of AIOHTTP](#an-overview-of-aiohttp)\n- [HTTPX vs AIOHTTP](#httpx-vs-aiohttp)\n- [Performance Comparison of AIOHTTP and HTTPX](#performance-comparison-of-aiohttp-and-httpx)\n- [Comparison of HTTPX vs Requests vs AIOHTTP](#comparison-of-httpx-vs-requests-vs-aiohttp)\n- [Conclusion](#conclusion)\n\n## How HTTPX compares to the Requests module\n\nSee this comparison table of the key differences between the requests and httpx libraries:\n\n| Feature         | Requests       | HTTPX  |\n| :------------- | :-------------:| :-----:|\n| Async compatibility | ❌         | ✅     |\n| HTTP/2 support      | ❌         | ✅     |\n| Automatic decoding  | ✅         | ✅     |\n| Size                | ✅         | ❌     |\n| Performance         | ✅         | ✅🚀   |\n\nBefore running the below examples, open up your terminal and install the required libraries:\n```bash\npython -m pip install requests httpx aiohttp asyncio\n```\n\nBelow are syntax differences between the two. The following code uses the Requests library to send a GET request:\n```python\nimport requests\nresponse = requests.get(\"https://example.com\")\nprint(response.text)\n```\n\nThe equivalent code uses the HTTPX library:\n```python\nimport httpx\nresponse = httpx.get(\"https://example.com\")\nprint(response.text)\n```\n\nAlternatively, you can create an `httpx` client object and use its `get` method:\n```python\nclient = httpx.Client()\nresponse = httpx.get(\"https://example.com\")\n```\n\nIf you want to send a `POST` request using the requests library, use the post method instead of get as follows:\n```python\nresponse = requests.post(\"https://httpbin.org/post\", data= {\"name\": \"John\", \"age\": 30})\n```\n\nThe syntax using HTTPX is very similar:\n```python\nresponse = client.post(\"https://httpbin.org/post\", data={\"name\": \"John\", \"age\": 30})\n```\n\nThe two libraries are used almost identically in simple synchronous situations. The important difference is that HTTPX allows you to write **asynchronous** code as follows:\n```python\nimport httpx\nimport asyncio\n\nasync def main():\n    async with httpx.AsyncClient() as client:\n        response = await client.get(\"https://example.com\")\n        print(response.text)\n\nasyncio.run(main())\n```\nHTTPX also includes automatic decoding of JSON and other common formats, which can save developers time and effort when working with responses that include structured data.\n\nSee the following example:\n```python\nimport httpx\nresponse = httpx.get(\"http://httpbin.org/get\")\ndata = response.json()\nprint(data[\"headers\"][\"User-Agent\"])\n```\nThe site `http://httpbin.org/get` returns a JSON response.\n\nIn comparison, the requests library syntax is almost identical:\n```python\nimport requests\nresponse = requests.get(\"http://httpbin.org/get\")\ndata = response.json()\nprint(data[\"headers\"][\"User-Agent\"])\n```\nDo note that there is a new version of the HTTP protocol called HTTP/2, which provides far more efficient transport and better performance. If you want to read more about HTTP/2, see this [detailed document](https://http2-explained.haxx.se/). Importantly, HTTPX offers support for HTTP/2 while Requests doesn’t.\n\nTo utilize HTTP/2 with the HTTPX library, first, install the optional HTTP/2 component using the pip command:\n```bash\npip install 'httpx[http2]'\n```\n\nNext, set the optional `http2` flag to `True` when you create an instance of the client as follows:\n```python\nclient = httpx.Client(http2=True)\nresponse = client.get(\"https://example.com\")\nprint(response.http_version) # Prints HTTP/2\n```\n## An overview of AIOHTTP\nLike HTTPX, AIOHTTP supports standard HTTP methods. It also includes support for cookies, redirects, and custom headers. AIOHTTP is particularly well-suited for making HTTP requests in high-concurrency environments due to its async-first design and efficient use of resources.\n\nHere is an example of making an asynchronous `GET` request using AIOHTTP:\n```python\nimport aiohttp\nimport asyncio\n\nasync def main(): \n    async with aiohttp.ClientSession() as session: \n            async with session.get(\"https://example.com\") as response: \n                print(await response.text())\n\nasyncio.run(main())\n```\n\nAIOHTTP also supports making asynchronous `POST` requests and other HTTP methods similarly. Here is an example of making a `POST` request with AIOHTTP:\n```python\nimport aiohttp\nimport asyncio\n\nasync def main(): \n    async with aiohttp.ClientSession() as session: \n            async with session.post(\"http://httpbin.org/post\", data={\"key\": \"value\"}) as response: \n                print(await response.text())\n\nasyncio.run(main())\n```\n\nIf you want to learn more about AIOHTTP, we highly recommend reading [Asynchronous Web Scraping with AIOHTTP](https://oxylabs.io/blog/asynchronous-web-scraping-python-aiohttp).\n\n## HTTPX vs AIOHTTP\nSee the complete comparison in our [blog post](https://oxylabs.io/blog/httpx-vs-requests-vs-aiohttp#httpx-vs-aiohttp). The major differences of HTTPX and AIOHTTP can be summed up with this table:\n\n| Feature         | HTTPX       | AIOHTTP  |\n| :------------- | :-------------:| :-----:|\n| Async compatibility | ✅         | ✅     |\n| HTTP/2 support      | ✅         | ❌     |\n| Performance         | ✅         | ✅🚀   |\n\n## Performance Comparison of AIOHTTP and HTTPX\nTo compare the performance of AIOHTTP and HTTPX, we can build a simple program that sends multiple asynchronous `GET` requests to a website. Here is an example of such a program:\n```python\nimport asyncio\nimport time\nimport httpx\nimport aiohttp\n\nasync def main():\n    # Create clients for both the library\n    httpx_client = httpx.AsyncClient()\n    aiohttp_client = aiohttp.ClientSession()\n\n    try:\n        # Send 100 asynchronous GET requests using HTTPX\n        start_time = time.perf_counter()\n        tasks = [httpx_client.get(\"https://example.com\") for _ in range(100)]\n        await asyncio.gather(*tasks)\n        end_time = time.perf_counter()\n        print(f\"HTTPX: {end_time - start_time:.2f} seconds\")\n\n        # Send 100 asynchronous GET requests using AIOHTTP\n        start_time = time.perf_counter()\n        tasks = [aiohttp_client.get(\"https://example.com\") for _ in range(100)]\n        await asyncio.gather(*tasks)\n        end_time = time.perf_counter()\n        print(f\"AIOHTTP: {end_time - start_time:.2f} seconds\")\n    finally:\n        # Close client sessions\n        await aiohttp_client.close()\n        await httpx_client.aclose()\n\nasyncio.run(main())\n```\nHere are the results of running this code on a mac with an M1 processor and gigabit internet:\n\n**HTTPX**: `1.22` seconds\n\n**AIOHTTP**: `1.19` seconds\n\nIf we run the same code for `1000` requests, the numbers change significantly:\n\n**HTTPX**: `10.22` seconds\n\n**AIOHTTP**: `3.79` seconds\n\nAs we can see, AIOHTTP is faster than HTTPX in this case. However, it’s important to note that the performance difference between the two libraries may vary depending on the specific use case and hardware.\n\n## Comparison of HTTPX vs Requests vs AIOHTTP\n\n| Feature                   | HTTPX | Requests | AIOHTTP |\n|:---------------------------|:-------:|:----------:|:---------:|\n| Async compatible         | Yes   | No       | Yes     |\n| Sync compatible          | Yes   | Yes      | No      |\n| Automatic JSON decoding  | Yes   | Yes      | No      |\n| HTTP/2 support           | Yes   | No       | No      |\n| Cookies                   | Yes   | Yes      | Yes     |\n| Redirects                 | Yes   | Yes      | Yes     |\n| Authentication            | Yes   | Yes      | Yes     |\n| Custom headers            | Yes   | Yes      | Yes     |\n| Streaming responses       | No    | No       | No      |\n| Size                      | Large | Smaller  | Smaller |\n| Performance               | Good  | Good     | Excellent |\n\n## Conclusion\nUltimately, the choice of an HTTP client library will depend on the specific needs of your project. Requests may be the best choice if you need a simple and easy-to-use library. If you need a more feature-rich library with async support, HTTPX could be a better fit.\n\nIt's worth noting that HTTPX and AIOHTTP are not the only options for making HTTP requests in Python. Many other libraries are available, each with its own features and trade-offs. Some other popular choices include http.client, urllib3, and httplib2.\n\nAlso, if you would like to try an all-in-one web scraping solution, check our [Web Scraper API](https://oxylabs.io/products/scraper-api/web) to gather real-time public information from most websites. Claim your **7-day free trial** and see for yourself whether it fits your needs.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxylabs%2Fhttpx-vs-requests-vs-aiohttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foxylabs%2Fhttpx-vs-requests-vs-aiohttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxylabs%2Fhttpx-vs-requests-vs-aiohttp/lists"}