Project Purpose
HTTPX is a next-generation HTTP client library for Python, designed for developers who need to perform HTTP requests. It supports both synchronous and asynchronous APIs, HTTP/1.1 and HTTP/2 protocols, and includes an integrated command-line client. The library aims to provide a robust and flexible solution for making HTTP requests, with features like connection pooling, cookie persistence, and SSL verification.
Tech Stack
- Languages: Python
- Frameworks/Libraries:
- httpcore for transport implementation (pyproject.toml)
- certifi for SSL certificates (pyproject.toml)
- idna for internationalized domain name support (pyproject.toml)
- click for command-line interface (httpx/_main.py)
- rich for terminal output formatting (httpx/_main.py)
- Build Tools: Hatchling (
pyproject.toml)
Architecture
The project follows a modular architecture, with the main functionality encapsulated in the httpx directory. This directory contains various modules responsible for different aspects of HTTP request handling, such as authentication, configuration, and content management. The project is structured to allow both synchronous and asynchronous operations, with a focus on extensibility and maintainability.
Key Modules
httpx/_api.py: Provides the main API functions for making HTTP requests.httpx/_auth.py: Handles authentication mechanisms.httpx/_config.py: Manages configuration settings for HTTP requests.httpx/_content.py: Deals with content encoding and decoding.httpx/_decoders.py: Implements response content decoders.httpx/_exceptions.py: Defines custom exceptions for error handling.httpx/_main.py: Contains the command-line interface implementation.httpx/_models.py: Defines data models for requests and responses.httpx/_status_codes.py: Maps HTTP status codes to descriptive names.httpx/_urls.py: Handles URL parsing and manipulation.
Entry Points
- The main entry point for the command-line interface is the
main function in httpx/_main.py. - The library's API is exposed through the
httpx/__init__.py file, which imports and re-exports functions and classes from various modules.
Notable Concerns
- Unimplemented Digest Authentication Feature — The
DigestAuth class in httpx/_auth.py contains a TODO comment indicating that the auth-int quality of protection (qop) for digest authentication is not yet implemented. This could lead to incomplete authentication handling if auth-int is required by a server. (severity: medium)
How to Get Started
```bash
git clone https://github.com/encode/httpx.git
cd httpx
```
- Install the dependencies using Hatchling:
```bash
hatch install
```
- Run the tests to ensure everything is set up correctly:
```bash
hatch run pytest
```
- Start using the library in your Python scripts or through the command-line interface.