Install Httpx using Python PIP
Last Updated :
27 Feb, 2024
When working on the internet or building websites, it's important to have good tools to ask for information. HTTPX is one of these tools, and a lot of people like it because it's fast, flexible, and has many features. This article will explain what HTTPX is and show you simple steps to put it on your computer.
What is HTTPX?
HTTPX is a fully featured HTTP client for Python 3, which provides synchronous and asynchronous request handling. It is built on top of the popular httpcore library and designed to be highly performant. HTTPX supports both synchronous and asynchronous programming paradigms, making it suitable for a wide range of applications.
Key features
- Asynchronous and synchronous support: HTTPX is designed to handle asynchronous requests efficiently using Python's
asyncio. However, it also provides a synchronous API for developers who prefer that style of programming. - Connection pooling: HTTPX comes with built-in connection pooling for increased performance when making multiple requests to the same server.
- WebSocket support: In addition to traditional HTTP requests, HTTPX supports WebSocket communication, making it versatile for various real-time applications.
Methods To Install Httpx in Python
Below, are the Methods To Install Httpx in Python.
- Install HTTPX Using Pip
- Install HTTPX CLI Using Pip
Install HTTPX Using pip
The most straightforward way to install HTTPX is using the pip package manager. Open your terminal or command prompt and run the following command:
pip install httpx

Or, to include the optional HTTP/2 support, use:
pip install httpx[http2]

To include the optional brotli decoder support, use:
pip install httpx[brotli]

Note: HTTPX requires Python 3.8+
Verify installation after installing httpx using above command.

If "import httpx" gets executed successfully in your python environment than it is installed in your system now.
Install HTTPX CLI Using Pip
Another way to install HTTPX is using the CLI pip package manager. Open your terminal or command prompt and run the following command:
pip install httpx[cli]

This now allows us to use HTTPX directly from the command line.
httpx --help
httpx request using CLICode Example
Do not name your file as htttpx.py while saving any python file which contains "import httpx" statement because when you try to import httpx, Python first looks in the current directory for a file named httpx.py, and it finds your script instead of the actual httpx library.
Python3
# File is saved as GFG.py
import httpx
async def main():
async with httpx.AsyncClient() as client:
response = await client.get('https://www.shravangoswami.com')
print(response.text)
# Run the async function
import asyncio
asyncio.run(main())
Enhance your coding skills with DSA Python, a comprehensive course focused on Data Structures and Algorithms using Python. Over 90 days, you'll explore essential algorithms, learn how to solve complex problems, and sharpen your Python programming skills. This course is perfect for anyone looking to level up their coding abilities and get ready for top tech interviews.
Join the Three 90 Challenge and commit to completing 90% of the course in 90 days to earn a 90% refund. It’s the perfect way to stay focused, track your progress, and reap the rewards of your hard work. Take the challenge and become a DSA expert in Python today