pyheaderparse Documentation

PyPI version Python versions License: MIT Documentation Status

pyheaderparse is a robust, production-ready HTTP header and cookie parser library for Python.

Features

  • Complete Header Parsing - Parse all standard HTTP headers including Content-Type, Accept, Cache-Control, and more

  • Cookie Support - Full cookie parsing with multiple extraction methods

  • Kwargs Support - Create and modify headers/cookies using keyword arguments

  • Client Hints - Parse modern Sec-CH-UA-* headers

  • Type Safety - Full type hints for IDE support

  • Zero Dependencies - No external dependencies required

  • CLI Tool - Command-line interface for quick parsing

  • Method Chaining - Fluent API for easy manipulation

Quick Installation

pip install pyheaderparse

Quick Example

from parser_header import HeaderParser, CookieParser

# Parse raw headers
raw = """content-type: application/json
content-length: 1024
cookie: session=abc123; user=john
"""
parser = HeaderParser(raw)
print(parser.content_type)  # 'application/json'
print(parser.get_cookies_as_dict())  # {'session': 'abc123', 'user': 'john'}

# Or create from kwargs
parser = HeaderParser(content_type='application/json', user_agent='MyApp/1.0')

Table of Contents

Development

Indices and tables