Skip to main content

Types for HTTP requests and responses

Project description

HTTP types in Python


Types for HTTP request and response.

Requires Python >= 3.6.


pip install http-types


Creating objects by hand

You can create typed Request and Response objects directly by listing arguments:

from http_types import Request, Response, RequestBuilder

req = Request(method="get",
              query={"id": ["1"]},
              headers={})  # Valid `Request` object, passes type-checking

res = Response(status_code=200, body="OK", headers={})  # Valid `Response` object, passes type-checking

invalid_req = Request(method="get")  # Fails type-checking, missing arguments
invalid_res = Response(body=1, ...)  # Fails type-checking, wrong type for `body`

Creating objects via helper methods

from http_types import RequestBuilder, ResponseBuilder, RequestResponseBuilder

# Create Request object from URL
url = ""
req = RequestBuilder.from_url(url)  # Validated Request object

# Create request object from dictionary
req_obj = { 'method': 'get', 'body': 'body', ... }
req = RequestBuilder.from_dict(req_obj)

Validating objects

from http_types import RequestBuilder, ResponseBuilder

req = Request(...)
RequestBuilder.validate(req)  # Validate `Request` object

res = Response(...)
ResponseBuilder.validate(res)  # Validate `Response` object


Local development

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

Running tests

Run pytest tests/ or python test.

Configuration for pytest is found in pytest.ini file.

Running type-checking

Install pyright and run pyright --lib or python typecheck.

Configuration for pyright is found in pyrightconfig.json file.

Automated tests

See .circleci/config.yml.

Publishing package

  1. Bump the version in if the version is the same as in the published package. Commit and push.
  2. Run python test, python typecheck and python dist to check everything works
  3. To build and upload the package, run python upload. Insert PyPI credentials to upload the pacakge 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.1
Filename, size File type Python version Upload date Hashes
Filename, size http_types-0.0.1-py2.py3-none-any.whl (5.3 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size http-types-0.0.1.tar.gz (5.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page