Skip to main content

Types for HTTP requests and responses

Project description

HTTP Types in Python

CircleCI PyPi License

Python (3.6 or later) library to read and write records of HTTP exchanges in the HTTP types format.


pip install http-types

Writing HTTP exchanges

Using HttpExchangeWritera recording of HTTP traffic can be serialised for use with any program that can handle the HTTP Types format:

request = RequestBuilder.from_dict({
        "host": "",
        "protocol": "https",
        "method": "get",
        "pathname": "/v1/users",
        "query": {"a": "b", "q": ["1", "2"]},

response = ResponseBuilder.from_dict({
        "statusCode": 200,
        "headers": {"content-type": "text/plain"},
        "body": "(response body string)",

exchange = HttpExchange(request=request, response=response)

with tempfile.TemporaryFile(mode="w") as output:
    writer = HttpExchangeWriter(output)

# Serialize to dictionary
as_dict = HttpExchangeWriter.to_dict(exchange)
# Serialize to JSON string
as_str = HttpExchangeWriter.to_json(exchange)

Reading HTTP exchanges

With HttpExchangeReader recordings in the HTTP Types format can be read for processing:

for exchange in HttpExchangeReader.from_jsonl(input_file):
    assert exchange.request.method == HttpMethod.GET
    assert exchange.request.protocol == Protocol.HTTPS
    assert exchange.response.statusCode == 200


Initial setup:

  1. Create a new virtual environment.
  2. Install dependencies: pip install --upgrade -e '.[dev]'

To test, run python test, which will:

  • Enforce code formatting using black.
  • Test with pytest, configured in pytest.ini.
  • Type check with mypy.
  • Enforce style guide with flake8, configured in .flake8.


  1. Bump the version in if the version is the same as in the published package. Commit and push.
  2. Run python test and python dist to check that everything works.
  3. To build and upload the package, run python upload. Insert PyPI credentials to upload the package to PyPI. The command will also run git tag to tag the commit as a release and push the tags to remote.

To see what the different commands do, see Command classes in

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 http-types, version 0.0.18
Filename, size File type Python version Upload date Hashes
Filename, size http_types-0.0.18-py2.py3-none-any.whl (8.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size http-types-0.0.18.tar.gz (8.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page