This is an attempt to bring some type safety to WSGI applications using Python’s new typing features (TypedDicts, Protocols). It seems to work OK but it’ll be full of gaps, holes, bugs, missteps, etc. I would not recommend depending on it.
This is implemented as a Python module, rather than MyPy stubs, as it represents a protocol things can satisfy rather than a set of types for something concrete.
This package came together during an exploration documented here: https://github.com/python/mypy/issues/7654
Define a callable application as a class:
class MyApplication(wsgitypes.Application[MyEnviron]):
def __call__(
self,
environ: Environ,
start_response: wsgitypes.StartResponse,
) -> wsgitypes.ResponseBody:
my_header = environ.get("REQUEST_METHOD", "")
return []
Environ should be type-safe:
class MyApplication(wsgitypes.Application):
def __call__(self, environ: Environ, start_response: wsgitypes.StartResponse) -> wsgitypes.ResponseBody:
environ["wsgi.input"] # Good
environ["wsgi.unpot"] # BORK! MyPy will catch this.
return []
You can define your own extensions to Environ using TypedDict inheritance, like so:
class MyEnviron(wsgitypes.Environ):
HTTP_X_MY_HEADER: t.Optional[str]
class MyApplication(wsgitypes.Application):
def __call__(self, environ: wsgitypes.Environ, start_response: wsgitypes.StartResponse) -> wsgitypes.Response:
environ = typing.cast(MyEnviron, environ)
environ.get("HTTP_X_MY_HEADER")
return []
Note that you need to use typing.cast to convert the incoming environ to your derived version. An attempt was made to use a type param for Environ, but it wasn’t viable: https://github.com/python/mypy/issues/7654
Metadata
Release files for wsgitypes 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wsgitypes-0.0.4.tar.gz | 4.9 kB | Without provenance | Details for wsgitypes-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wsgitypes-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for wsgitypes-0.0.4-py3-none-any.whl |
Total release size: 11.1 kB
Release files / wsgitypes-0.0.4.tar.gz
| Download URL | wsgitypes-0.0.4.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61d8594bb2ed254b03ae771caba95783c3f8d02911d36dc673e086d013ed2fef
|
|
BLAKE2b-256 checksum How to use checksums |
7748db5208fba0961b1cefa4cb95a656879a486e7a734b4db16122105aa50962
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.33.0 CPython/3.7.2
|
Release files / wsgitypes-0.0.4-py3-none-any.whl
| Download URL | wsgitypes-0.0.4-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bfe9df03ec37056c5f3f9e8771ef67baf1d8b801792e6b55b1842e1dbb76d15e
|
|
BLAKE2b-256 checksum How to use checksums |
8a691e875743ccd1d7a084020c4fb4449fd38456be5e132cfe7b25c85fb22092
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.33.0 CPython/3.7.2
|
Security for wsgitypes 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.