freshcrate
Home > Frameworks > httptools

httptools

A collection of framework independent HTTP protocol utils.

Description

![Tests](https://github.com/MagicStack/httptools/workflows/Tests/badge.svg) httptools is a Python binding for the nodejs HTTP parser. The package is available on PyPI: `pip install httptools`. # APIs httptools contains two classes `httptools.HttpRequestParser`, `httptools.HttpResponseParser` (fulfilled through [llhttp](https://github.com/nodejs/llhttp)) and a function for parsing URLs `httptools.parse_url` (through [http-parse](https://github.com/nodejs/http-parser) for now). See unittests for examples. ```python class HttpRequestParser: def __init__(self, protocol): """HttpRequestParser protocol -- a Python object with the following methods (all optional): - on_message_begin() - on_url(url: bytes) - on_header(name: bytes, value: bytes) - on_headers_complete() - on_body(body: bytes) - on_message_complete() - on_chunk_header() - on_chunk_complete() - on_status(status: bytes) """ def get_http_version(self) -> str: """Return an HTTP protocol version.""" def should_keep_alive(self) -> bool: """Return ``True`` if keep-alive mode is preferred.""" def should_upgrade(self) -> bool: """Return ``True`` if the parsed request is a valid Upgrade request. The method exposes a flag set just before on_headers_complete. Calling this method earlier will only yield `False`. """ def feed_data(self, data: bytes): """Feed data to the parser. Will eventually trigger callbacks on the ``protocol`` object. On HTTP upgrade, this method will raise an ``HttpParserUpgrade`` exception, with its sole argument set to the offset of the non-HTTP data in ``data``. """ def get_method(self) -> bytes: """Return HTTP request method (GET, HEAD, etc)""" class HttpResponseParser: """Has all methods except ``get_method()`` that HttpRequestParser has.""" def get_status_code(self) -> int: """Return the status code of the HTTP response""" def parse_url(url: bytes): """Parse URL strings into a structured Python object. Returns an instance of ``httptools.URL`` class with the following attributes: - schema: bytes - host: bytes - port: int - path: bytes - query: bytes - fragment: bytes - userinfo: bytes """ ``` # Development 1. Clone this repository with `git clone --recursive git@github.com:MagicStack/httptools.git` 2. Create a virtual environment with Python 3: `python3 -m venv envname` 3. Activate the environment with `source envname/bin/activate` 4. Run `make` and `make test`. # License MIT.

Release History

VersionChangesUrgencyDate
0.7.1Imported from PyPI (0.7.1)Low4/21/2026
v0.7.1This is identical to 0.7.0 whose CI failed uploadingLow10/10/2025
v0.7.0Changes ======= * Modernize packaging and fix CI (#130) Drop Python 3.8, add Python 3.14 Use Cython 3.1.0 Bump llhttp to 9.3.0 (by @ngoldbaum @Carreau @fantix in 59bf94fc for #129) * Static Type-checking for httptools (#100) (by @Vizonex @KRRT7 in b55f5fe2 for #100)Low10/10/2025
v0.6.4Fixes ===== * Include Cython source files in sdist (by @mgorny in 2287a95a for #115)Low10/16/2024
v0.6.3Fixes ===== * Fix missing CR is some tests (by @mgorny in 21a199d3 for #112) * Bump bundled llhttp to 9.2.1 Fixes CVE-2024-27982 (by @elprans in 560bd9ea for #113)Low10/16/2024
v0.6.2Fixes ===== * Fix build and run tests on Python 3.13 (#107) (by @jameshilliard @tacaswell @fafanoulele @fantix in ad9765b3 for #98 #104)Low10/14/2024
v0.6.1Changes ======= * Explicit Python 3.12 support and build wheels, change min version to 3.8 (#95) (by @tiptenbrink in 25f412bd for #95) * Do not install the *.c sources in wheels (#73) (by @hroncok in b2fc5bdf for #73)Low10/16/2023
v0.6.0Changes ======= * Bump bundled llhttp to 8.1.1 Fixes CVE-2023-30589 (by @fantix in 6c6812a for #91)Low7/6/2023
v0.5.0UPDATE: The bundled copy of llhttp in this release is vulnerable to CVE-2023-30589, please update to use 0.6.0 instead. Changes ======= * Bump bundled llhttp to 6.0.9 fixes CVE-2022-32213, CVE-2022-32214, CVE-2022-32215 (by @nlsj1985 in 56d6a163 for #83) * Test and build against Python 3.11 (by @elprans in 509cd149 for #84)Low9/13/2022
v0.4.0Changes ======= * Bump bundled http-parser to 2.9.4 and llhttp to 6.0.6 fixes CVE-2021-22959 & CVE-2021-22960 (by @elprans in 4d5dddd3 for #77)Low2/22/2022
v0.3.0This release has no functional changes, only packaging: Python 3.5 is EOL, so wheels are no longer built, and Python 3.10 has been added to the roster along with aarch64 wheels on Linux and universal2 wheels on macOS. Changes: * Use cibuildwheel to build release wheels (by @elprans in 2f57b6b7)Low8/10/2021
v0.1.1Restore Python 3.5 support (#48).Low4/26/2021
v0.1.2# Bug Fixes * Fix `httptools.__all__` (by @elprans in 9340d321 for #52) # Build * Add Python 3.9 in the build/test matrix (by @b0g3r in e2d1a464 for #62)Low4/26/2021
v0.2.0# New Features * Swap http-parse to llhttp (by @victoraugustolls and @fantix in 63b5de2b for #56) # Bug Fixes * Fix `httptools.__all__` (by @elprans in 9340d321 for #52) # Build * Add Python 3.9 in the build/test matrix (by @b0g3r in e2d1a464 for #62)Low4/23/2021
v0.1.0No functional changes from 0.0.13, except the new release flow and binary wheels.Low2/5/2020

Dependencies & License Audit

Loading dependencies...

Similar Packages

pre-commitA framework for managing and maintaining multi-language pre-commit hooks.v4.6.0
azure-core-tracing-opentelemetryMicrosoft Azure Azure Core OpenTelemetry plugin Library for Pythonazure-template_0.1.0b6187637
spdx-toolsSPDX parser and tools.0.8.5
lacesDjango components that know how to render themselves.0.1.2
django-tasksA backport of Django's built in Tasks framework0.12.0