typedclasses
Python classes with types validation at runtime. (Experimental & Under Development)
Installation
You can install this library using Python's favorite, pip package manager.
pip install -U typedclasses
How it works
Using typedclasses, you can create classes in dataclasses-like manner i.e using type annotations and library will enforce types for
that class at runtime. Here's an example:
import typing
from typedclasses import TypedClass
class User(TypedClass):
id: int
name: str
email: typing.Optional[str] = None
Parameters will be validated when initialising above class. Since email has a default value set, It is optional to pass
it as a parameter while instansiating:
>>> User(id=1, name="foobar") # runs fine
>>> User(id="1", name="foobar")
TypeError: Parameter 'id' must be an instance of <class 'int'>, <class 'str'> is unsupported.
This library also provides validation for various generic types from typing module:
class Foo(TypedClass):
x: typing.Union[str, int]
Foo(x="a") # ok
Foo(x=1) # ok
Foo(x=True) # invalid
List of all types supported from typing module can be found in the documentation.
Metadata
Release files for typedclasses 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| typedclasses-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for typedclasses-0.0.1-py3-none-any.whl |
Release files / typedclasses-0.0.1-py3-none-any.whl
| Download URL | typedclasses-0.0.1-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
00490ee7f36d75d79ac452401a24d26dcac8092915e2ffa070b4c2b6effeed8d
|
|
BLAKE2b-256 checksum How to use checksums |
f37fff4a2e8ecf4356c66de0ccc2cc533ffced138fc3ea3dc0ad3fc646dda092
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.7
|
Security for typedclasses 0.0.1
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.