Skip to main content

typeit brings typed data into your project

Project description

https://github.com/avanov/typeit/workflows/CI/badge.svg?branch=develop https://coveralls.io/repos/github/avanov/typeit/badge.svg?branch=develop Requirements Status Documentation Status Latest PyPI Release

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


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.1.3.tar.gz (30.6 kB view details)

Uploaded Source

Built Distribution

typeit-3.11.1.3-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file typeit-3.11.1.3.tar.gz.

File metadata

  • Download URL: typeit-3.11.1.3.tar.gz
  • Upload date:
  • Size: 30.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for typeit-3.11.1.3.tar.gz
Algorithm Hash digest
SHA256 585bdb5d7b13a82ff3d842538b960e4b1f445d0c9c90863a2aec942d85600549
MD5 95ef8463871c41baa36721732ab56d92
BLAKE2b-256 4fc24453e98dd624feaa2f19aedb907701acc7024692f2dcf83df125bd5b7ba1

See more details on using hashes here.

File details

Details for the file typeit-3.11.1.3-py3-none-any.whl.

File metadata

  • Download URL: typeit-3.11.1.3-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for typeit-3.11.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 71df66c6d840f966ca25b2dbf643826d228b5ecb727de6ea174148daba71d45c
MD5 a09f81609a0f12ee27a1fc5f3ae0e8c4
BLAKE2b-256 5eb917236686e661428cc1a3a71b54b38cf338b261d892d93641dc1b2c37d3c1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page