The HTTPX library is a powerful and user-friendly HTTP client for Python. In this guide, we'll walk through installing HTTPX and making your first request.
Installing HTTPX
To install HTTPX, you'll need Python 3.6 or higher. The easiest way is via pip:
pip install httpx
This will download the latest version of HTTPX from PyPI and handle all the dependencies.
If you want to install a specific version, you can add
pip install httpx==0.23.0
You can also install HTTPX from source if you want the bleeding edge development version.
Making Your First Request
With HTTPX installed, we can start making requests:
import httpx
response = httpx.get('https://www.example.com')
print(response.text)
This sends a GET request to example.com and prints the response body.
Some key things to note:
Going Further
This just scratches the surface of what's possible with HTTPX. Some other ideas:
The HTTPX documentation covers all this and more. The library prioritizes an easy-to-use API with powerful functionality underneath.
So give HTTPX a try on your next Python project! Installing it is simple with pip, and you'll appreciate the elegant API when making HTTP requests.