Python / Uvicorn Fundamentals Interview Questions
What are httptools and h11, and when would you choose each?
Uvicorn supports two HTTP parser implementations, selectable via the --http flag. The default auto setting picks httptools if installed (via the standard extras) or falls back to h11.
| Feature | h11 | httptools |
|---|---|---|
| Implementation | Pure Python (h11 library) | Cython bindings to llhttp (C parser) |
| Performance | Moderate | ~20-30% faster HTTP parsing |
| PyPy support | Yes | No - requires CPython |
| Standards compliance | Very strict - helpful for debugging | Production-grade |
| Error messages | More descriptive | Minimal |
| Install | Always available (default) | pip install httptools (included in uvicorn[standard]) |
# Auto - picks httptools if available (recommended for production) uvicorn main:app --http auto # Force httptools (fast, production) uvicorn main:app --http httptools # Force h11 (pure Python, debugging, PyPy) uvicorn main:app --http h11 # h11 also has a configurable buffer limit: # --limit-max-requests sets max request buffer size (h11 only) uvicorn main:app --http h11 --limit-max-requests 1000
Production recommendation: use httptools for its speed advantage. Use h11 when running on PyPy, in strict compliance testing environments, or when debugging malformed HTTP requests (h11's error messages are more descriptive).
More Related questions...