typeit brings typed data into your project
Project description
Typeit
typeit infers Python types from a sample JSON/YAML data, and provides you with the tools for serialising and parsing it. It also provides you with smart constructors for arbitrarily nested data structures. The library works superb on Python 3.7 and above.
Start using it by generating types for your JSON payloads:
$ echo '{"first-name": "Hello", "initial": null, "last_name": "World"}' | typeit gen
The snipped above produces output similar to this:
from typing import Any, NamedTuple, Optional, Sequence
from typeit import TypeConstructor
class Main(NamedTuple):
first_name: str
initial: Optional[Any]
last_name: str
overrides = {
Main.first_name: 'first-name',
}
mk_main, serialize_main = TypeConstructor & overrides ^ Main
Use these functions to construct and serialize your payloads:
payload = {"first-name": "Hello", "initial": None, "last_name": "World"}
data = mk_main(payload)
assert isinstance(data, Main)
assert serialize_main(data) == payload
Documentation
Documentation is hosted on ReadTheDocs: https://typeit.readthedocs.io/en/develop/
Test framework
Run existing test suite with
$ make test
Changelog
See CHANGELOG.
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
typeit-3.11.0.0.tar.gz
(29.6 kB
view hashes)
Built Distribution
typeit-3.11.0.0-py3-none-any.whl
(34.5 kB
view hashes)
Close
Hashes for typeit-3.11.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d182c233bfd18ab0fe9c8b64841ac837d42a3fe7f68f794aab5e7b849b12936a |
|
MD5 | 7cd2d30afaee4c21b2825c45b8240ac0 |
|
BLAKE2b-256 | 9833b0f9873ad6061df37d3a3dbb00812d617316da2b8b85caf077a156acb422 |