HTTPX is a fully featured HTTP client library for Python 3, which provides sync and async APIs, and support for both HTTP/1.1 and HTTP/2.
It is a drop-in replacement for the standard Python requests
library and provides additional features such as HTTP/2 support, HTTP/2 server push, connection pooling, thread-safe connection management, and more.
HTTPX is designed to be easy to use, flexible, and performant, making it a great choice for building web applications and APIs.
To use HTTPX, you first need to install it using pip:
pip install httpx
Then, you can import it and start making HTTP requests. Here’s an example:
import httpx
response = httpx.get("<https://www.example.com>")
print(response.status_code)
print(response.text)
You can also use HTTPX’s async API for async requests. Here’s an example:
import httpx
async def main():
async with httpx.AsyncClient() as client:
response = await client.get("<https://www.example.com>")
print(response.status_code)
print(response.text)
asyncio.run(main())
HTTPX also provides many additional features, such as support for timeouts, authentication, cookies, proxies, and more. Check out the official documentation for more information.