Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/avanov/typeit
Infer Python types from JSON data, use them for auto serialisation and parsing
https://github.com/avanov/typeit
colander deserialization json mypy parser parsing pyrsistent python python3 serialization structured-data typechecking typing
Last synced: 6 days ago
JSON representation
Infer Python types from JSON data, use them for auto serialisation and parsing
- Host: GitHub
- URL: https://github.com/avanov/typeit
- Owner: avanov
- License: mit
- Created: 2018-06-17T02:51:03.000Z (over 6 years ago)
- Default Branch: develop
- Last Pushed: 2023-10-27T19:35:52.000Z (about 1 year ago)
- Last Synced: 2024-10-30T10:21:08.133Z (16 days ago)
- Topics: colander, deserialization, json, mypy, parser, parsing, pyrsistent, python, python3, serialization, structured-data, typechecking, typing
- Language: Python
- Homepage: https://typeit.readthedocs.io/en/develop/
- Size: 272 KB
- Stars: 13
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
.. _badges:
.. image:: https://github.com/avanov/typeit/workflows/CI/badge.svg?branch=develop
:target: https://github.com/avanov/typeit/actions?query=branch%3Adevelop.. image:: https://coveralls.io/repos/github/avanov/typeit/badge.svg?branch=develop
:target: https://coveralls.io/github/avanov/typeit?branch=develop.. image:: https://requires.io/github/avanov/typeit/requirements.svg?branch=master
:target: https://requires.io/github/avanov/typeit/requirements/?branch=master
:alt: Requirements Status.. image:: https://readthedocs.org/projects/typeit/badge/?version=latest
:target: http://typeit.readthedocs.org/en/latest/
:alt: Documentation Status.. image:: http://img.shields.io/pypi/v/typeit.svg
:target: https://pypi.python.org/pypi/typeit
:alt: Latest PyPI ReleaseTypeit
------**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:
.. code-block:: bash
$ echo '{"first-name": "Hello", "initial": null, "last_name": "World"}' | typeit gen
The snipped above produces output similar to this:
.. code-block:: python
from typing import Any, NamedTuple, Optional, Sequence
from typeit import TypeConstructorclass Main(NamedTuple):
first_name: str
initial: Optional[Any]
last_name: stroverrides = {
Main.first_name: 'first-name',
}mk_main, serialize_main = TypeConstructor & overrides ^ Main
Use these functions to construct and serialize your payloads:
.. code-block:: python
payload = {"first-name": "Hello", "initial": None, "last_name": "World"}
data = mk_main(payload)
assert isinstance(data, Main)
assert serialize_main(data) == payloadDocumentation
-------------Documentation is hosted on ReadTheDocs: https://typeit.readthedocs.io/en/develop/
Test framework
--------------Run existing test suite with
.. code::
$ make test
Changelog
---------See `CHANGELOG `_.