Types for HTTP requests and responses
Project description
HTTP types in Python
Types for HTTP request and response.
Requires Python >= 3.6.
Installation
pip install http-types
Usage
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",
host="api.github.com",
path="/user/repos?id=1",
pathname="/user/repos",
protocol="https",
query={"id": ["1"]},
body="",
bodyAsJson="",
headers={}) # Valid `Request` object, passes type-checking
res = Response(statusCode=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, HttpExchangeBuilder
# Create Request object from URL
url = "https://api.github.com/v1/repos?id=1"
req = RequestBuilder.from_url(url) # Validated Request object
# Create request object from dictionary
req_obj = {
'host': 'api.github.com',
'protocol': 'https',
'method': 'get',
'path': '/v1/users', # pathname inferred automatically
'query': {}
}
req = RequestBuilder.from_dict(req_obj) # `body`, `pathname`, and `headers` are optional
Validating objects
from http_types import RequestBuilder, ResponseBuilder
req = Request(...)
RequestBuilder.validate(req) # Validate `Request` object
res = Response(...)
ResponseBuilder.validate(res) # Validate `Response` object
Development
Local development
- Create a new virtual environment.
- Install dependencies:
pip install --upgrade -e '.[dev]'
Running tests
Run pytest tests/ or python setup.py test.
Configuration for pytest is found in pytest.ini file.
Running type-checking
Install pyright and run pyright --lib or python setup.py typecheck.
Configuration for pyright is found in pyrightconfig.json file.
Automated tests
See .circleci/config.yml.
Publishing package
- Bump the version in setup.py if the version is the same as in the published package. Commit and push.
- Run
python setup.py test,python setup.py typecheckandpython setup.py distto check everything works - To build and upload the package, run
python setup.py upload. Insert PyPI credentials to upload the pacakge toPyPI. The command will also rungit tagto 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file http-types-0.0.5.tar.gz.
File metadata
- Download URL: http-types-0.0.5.tar.gz
- Upload date:
- Size: 6.7 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.41.1 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ad284225f8bfe717e793250936ed6d5349a77b4f432aa9adeef44b3eeb21e7a
|
|
| MD5 |
1f29a0e0b1a6a55b20a5edb922373df6
|
|
| BLAKE2b-256 |
971a3200ce7aff14ce34ca8244b2e73fedecea8e891b3a8875aa47754123930f
|
File details
Details for the file http_types-0.0.5-py2.py3-none-any.whl.
File metadata
- Download URL: http_types-0.0.5-py2.py3-none-any.whl
- Upload date:
- Size: 7.1 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.41.1 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9d4fd4f8355c9bf28cc2505c57d93e8c2ba9001b29a06ede0b5faa48c35b92a
|
|
| MD5 |
58d65f2019db25d2513d058b81c2b906
|
|
| BLAKE2b-256 |
13a136a6f2d6dc9e039104381616b8e0ae3f8da92fb8b480462ee328d6c1a454
|