HTTP request/response parser for python in C
C Python Makefile
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
examples Fixed examples/ for Python3 Nov 15, 2015
http_parser Add types dependency. May 15, 2016
testing fix pyparser as well Aug 30, 2013
.gitignore prepare testing and add failing tests Jan 30, 2013
.travis.yml Added Python 3.4 and PyPy 3 to the build matrix. Dec 12, 2014
LICENSE I just realized we were in 2013... Aug 30, 2013 add a TODO. Jul 27, 2012
Makefile use setuptools to install http_parser. Apr 2, 2012
README.rst I just realized we were in 2013... Aug 30, 2013
THANKS update THANKS Aug 30, 2013 add a TODO. Jul 27, 2012
requirements.txt add travis file Feb 9, 2013
requirements_dev.txt add cython to the requirements Aug 30, 2013 bump to 0.8.0 Feb 9, 2013
tox.ini prepare testing and add failing tests Jan 30, 2013



HTTP request/response parser for Python compatible with Python 2.x (>=2.6), Python 3 and Pypy. If possible a C parser based on http-parser from Ryan Dahl will be used.

http-parser is under the MIT license.

Project url:

Build Status


  • Python 2.6 or sup. Pypy latest version.
  • Cython if you need to rebuild the C code (Not needed for Pypy)


$ pip install http-parser

Or install from source:

$ git clone git://
$ cd http-parser && python install

Note: if you get an error on MacOSX try to install with the following arguments:

$ env ARCHFLAGS="-arch i386 -arch x86_64" python install


http-parser provide you parser.HttpParser low-level parser in C that you can access in your python program and http.HttpStream providing higher-level access to a readable,sequential io.RawIOBase object.

To help you in your day work, http-parser provides you 3 kind of readers in the reader module: IterReader to read iterables, StringReader to reads strings and StringIO objects, SocketReader to read sockets or objects with the same api (recv_into needed). You can of course use any io.RawIOBase object.

Example of HttpStream


#!/usr/bin/env python
import socket

from http_parser.http import HttpStream
from http_parser.reader import SocketReader

def main():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(('', 80))
        s.send("GET / HTTP/1.1\r\nHost:\r\n\r\n")
        r = SocketReader(s)
        p = HttpStream(r)
        print p.headers()
        print p.body_file().read()

if __name__ == "__main__":

Example of HttpParser:

#!/usr/bin/env python
import socket

# try to import C parser then fallback in pure python parser.
    from http_parser.parser import HttpParser
except ImportError:
    from http_parser.pyparser import HttpParser

def main():

    p = HttpParser()
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    body = []
        s.connect(('', 80))
        s.send("GET / HTTP/1.1\r\nHost:\r\n\r\n")

        while True:
            data = s.recv(1024)
            if not data:

            recved = len(data)
            nparsed = p.execute(data, recved)
            assert nparsed == recved

            if p.is_headers_complete():
                print p.get_headers()

            if p.is_partial_body():

            if p.is_message_complete():

        print "".join(body)


if __name__ == "__main__":

You can find more docs in the code (or use a doc generator).


2011-2013 (c) Benoît Chesneau <>