Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

typeit brings typed data into your project

Project description Requirements Status Documentation Status Latest PyPI Release


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 is hosted on ReadTheDocs:

Test framework

Run existing test suite with

$ pytest



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for typeit, version
Filename, size File type Python version Upload date Hashes
Filename, size typeit- (33.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size typeit- (29.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page