Skip to main content

Tool to generate Python types based on TypedDict from a JSON Schema

Project description

JSON Schema generate Python types

Tools to generate Python types based on TypeDict from a JSON schema

Quick start

install:

python3 -m pip install --user jsonschema-gentype

Convert a JSON schema to a Python file contains the types:

jsonschema-gentype --json-schema=<JSON schema> --python=<destination Python>

Docker

You can also run it with Docker:

docker run --rm --user=$(id --user) --volume=$(pwd):/src camptocamp/jsonschema-gentypes

Config file

You can also write a config file named jsonschema-gentypes.yaml with:

headers: >
    # Automatically generated file from a JSON schema
# Used to correctly format the generated file
callbacks:
    - - black
    - - isort
generate:
    - # JSON schema file path
      source: jsonschema_gentypes/schema.json
      # Python file path
      destination: jsonschema_gentypes/configuration.py
      # The name of the root element
      root_name: Config
      # Argument passed to the API
      api_arguments:
          additional_properties: Only explicit
      # Rename an element
      name_mapping: {}

And just run:

jsonschema-gentype

Limitations

Requires Python 3.8

See the issues with label "limitation".

Contribute

The code should be formatted with isort and black.

The code should be typed.

The prospector tests should pass.

The code should be tested with pytests.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

jsonschema_gentypes-0.9.3-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file jsonschema_gentypes-0.9.3-py3-none-any.whl.

File metadata

  • Download URL: jsonschema_gentypes-0.9.3-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5

File hashes

Hashes for jsonschema_gentypes-0.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6a4ae561dc9eb6d2ce641c319c2b8f585d2e58e7df8735bf155622d2715ed89e
MD5 ebcea3f5d39237a071efdc225e520128
BLAKE2b-256 355b1e7c0397b60459f9eb38dd059189381f84a029fa85c2f2715003b2ac6ec0

See more details on using hashes here.

Provenance

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