Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Parsing headers from string or dictionary

Project description


Parsing headers from string or dictionary


Install and update using pip_:

.. code-block:: text

$ pip install parserheader

parserheader supports Python 2 and newer, Python 3 and newer, and PyPy.

.. _pip:


What does it look like? Here is an example of a simple parserheader program:

.. code-block:: python

import parserheader


def setHeaders():
    ph = parserheader.parserheader()
    header_str = """
        POST /upload/ HTTP/1.1
        Connection: keep-alive
        Content-Length: 1220
        Cache-Control: max-age=0
        Upgrade-Insecure-Requests: 1
        Content-Type: application/x-www-form-urlencoded
        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
        Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
        Accept-Encoding: gzip, deflate
        Accept-Language: en-US,en;q=0.9,id;q=0.8
        Cookie: PHPSESSID=41a0f0ac4545d3f5ba9a4ba415b777e9
    headers = ph.parserHeader(header_str)
    print("headers =", headers)
    return headers


And what it looks like when run:

.. code-block:: text

$ python 
headers = {'Origin': '', 'Content-Length': '1220', 'Accept-Language': 'en-US,en;q=0.9,id;q=0.8', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'keep-alive', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36', 'Host': '', 'Referer': '', 'Cache-Control': 'max-age=0', 'Cookie': 'PHPSESSID=41a0f0ac4545d3f5ba9a4ba415b777e9', 'Upgrade-Insecure-Requests': '1', 'Content-Type': 'application/x-www-form-urlencoded'}


  • Python 2.7 +, Python 3.x
  • Windows, Linux


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for parserheader, version 0.29
Filename, size File type Python version Upload date Hashes
Filename, size parserheader-0.29-py2.py3-none-any.whl (8.3 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size parserheader-0.29.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page