Skip to main content

Tools for generating Python models from JSON Schema documents.

Project description

Build Status Documentation Status

Statham

statham is a Python Model Parsing Library for JSON Schema. Read the documentation.

This project includes tools for writing and generating extensible Python classes based on JSON Schema documents.

Example Model Definition

statham can be used to write JSON Schema documents and their corresponding application-level models in one go:

from typing import List

from statham.schema.elements import Array, Integer, Object, String
from statham.schema.property import Property


class Choice(Object):
    choice_text: str = Property(String(maxLength=200), required=True)
    votes: int = Property(Integer(default=0))


class Poll(Object):
    question: str = Property(String(), required=True)
    choices: List[Choice] = Property(Array(Choice), required=True)

Generating python classes

Alternatively, Python models may be generated automatically from an existing schema:

statham --input http://example.com/schema.json

Command-line arguments

Required arguments:
  --input INPUT    Specify the path to the JSON Schema to be generated.

                   If the target schema is not at the root of a document, specify the
                   JSON Pointer in the same format as a JSON Schema `$ref`, e.g.
                   `--input path/to/document.json#/definitions/schema`


Optional arguments:
  --output OUTPUT  Output directory or file in which to write the output.

                   If the provided path is a directory, the command will derive the name
                   from the input argument. If not passed, the command will write to
                   stdout.

  -h, --help       Display this help message and exit.

Installation

This project requires Python 3.6+ and may be installed using pip:

pip install statham-schema

Compatibility

See Compatibility for information regarding the currently supported JSON Schema draft and exceptions.

Development

  1. Clone the repository: git clone git@github.com:jacksmith15/statham-schema.git && cd statham-schema
  2. Initialise git submodules: git submodule update --init --recursive
  3. Install the requirements: pip install -r requirements.txt -r requirements-test.txt
  4. Run pre-commit install
  5. Run the tests: bash run_test.sh -c -a

This project uses the following QA tools:

  • PyTest - for running unit tests.
  • PyLint - for enforcing code style.
  • MyPy - for static type checking.
  • Travis CI - for continuous integration.
  • Black - for uniform code formatting.

Documentation is written using Sphinx.

License

This project is distributed under the MIT license.

statham

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

statham-schema-0.15.1.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statham_schema-0.15.1-py3-none-any.whl (43.7 kB view details)

Uploaded Python 3

File details

Details for the file statham-schema-0.15.1.tar.gz.

File metadata

  • Download URL: statham-schema-0.15.1.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for statham-schema-0.15.1.tar.gz
Algorithm Hash digest
SHA256 ca0ea9e3201ab56cbb2c9b6095da91e02e1705c380f81933b71b7942d768c959
MD5 9db731c52f26b9455dd60abf10cf7000
BLAKE2b-256 142f9e6fab2f761fa317fc8968cec8eb53967a627c2ed5373a738ede063814a8

See more details on using hashes here.

File details

Details for the file statham_schema-0.15.1-py3-none-any.whl.

File metadata

  • Download URL: statham_schema-0.15.1-py3-none-any.whl
  • Upload date:
  • Size: 43.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for statham_schema-0.15.1-py3-none-any.whl
Algorithm Hash digest
SHA256 598c8e770c8b2bf7e94a7ad7db37cc1b8d97023db87dac16ec0ade7e75f9a4ce
MD5 2ed1c79b008a2986e7c81868593adfb4
BLAKE2b-256 ff4c3cd681e8b3192b41456fbf2f1b83e27033466084ed0f3daa4274d9234fde

See more details on using hashes here.

Supported by

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