Skip to content
Fast HTTP parser
Python Shell Makefile
Branch: master
Clone or download

Latest commit

elprans Fix httptools.__all__
While looking at #52, I noticed that `httptools.__all__` is incorrect
and doesn't actually include everything that is exported by the module,
which might entice the users to import from the private submodule

Fixes: #52
Latest commit 9340d32 Feb 9, 2020


Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Restore Python 3.5 support Feb 7, 2020
httptools Fix httptools.__all__ Feb 29, 2020
tests Testing via Github Actions Feb 5, 2020
vendor Bump http-parser to v2.9.0 Feb 25, 2019
.gitignore Testing via Github Actions Feb 5, 2020
.gitmodules Add Travis CI Apr 25, 2016
LICENSE Add http-parser binding Oct 29, 2015 Add http-parser binding Oct 29, 2015
Makefile Add release workflow Feb 5, 2020 Use just "Tests" for the test workflow Feb 5, 2020
pytest.ini Add a default config for py.test May 7, 2016 Restore Python 3.5 support Feb 7, 2020


httptools is a Python binding for the nodejs HTTP parser.

The package is available on PyPI: pip install httptools.


httptools contains two classes httptools.HttpRequestParser, httptools.HttpResponseParser and a function for parsing URLs httptools.parse_url. See unittests for examples.

class HttpRequestParser:

    def __init__(self, protocol):

        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``

        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


  1. Clone this repository with git clone --recursive

  2. Create a virtual environment with Python 3.5: python3.5 -m venv envname

  3. Activate the environment with source envname/bin/activate

  4. Install Cython with pip install cython

  5. Run make and make test.



You can’t perform that action at this time.