typeit brings typed data into your project
Project description
Typeit
typeit brings typed data into your project.
Start using it by automatically 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
$ pytest
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-0.22.0.tar.gz
(24.0 kB
view hashes)
Built Distribution
typeit-0.22.0-py3-none-any.whl
(27.9 kB
view hashes)