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.

Installation

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": "api.github.com",
        "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)
    writer.write(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

Development

Initial setup:

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

To test, run python setup.py test, which will:

Publishing

  1. Bump the version in setup.py if the version is the same as in the published package. Commit and push.
  2. Run python setup.py test and python setup.py dist to check that everything works.
  3. To build and upload the package, run python setup.py 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 setup.py.

Project details


Download files

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

Source Distribution

http-types-0.0.12.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

http_types-0.0.12-py2.py3-none-any.whl (7.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file http-types-0.0.12.tar.gz.

File metadata

  • Download URL: http-types-0.0.12.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.10

File hashes

Hashes for http-types-0.0.12.tar.gz
Algorithm Hash digest
SHA256 5dde5c902044603d6aeae8a15643ae4f1e2c6554f954642b1299111d9544b069
MD5 2a6141c5feb470c391d238012607e81d
BLAKE2b-256 5634357d58a8de2463f4fc9c18bc49ecaae0977261091597ba48fb352ffb22e3

See more details on using hashes here.

File details

Details for the file http_types-0.0.12-py2.py3-none-any.whl.

File metadata

  • Download URL: http_types-0.0.12-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.10

File hashes

Hashes for http_types-0.0.12-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 daded604220020a79090a286f7f898ef229e71a09f17adfb60270d739d3d820d
MD5 06f4121a1bbe4c297f957c4db00f14e4
BLAKE2b-256 a78dad1f256e4a30fdc9d88675714136d2791b5e7be92e1ab13dc9578e4172fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page