Tools for generating Python models from JSON Schema documents.
Project description
Statham Schema
statham
is a Python DSL for JSON Schema. Read the documentation.
This project includes tools for writing and generating extensible Python classes based on JSON Schema documents.
Example DSL Definition
The DSL can be used to write JSON Schema documents and their corresponding application-level models in one go:
from typing import List
from statham.dsl.elements import Array, Integer, Object, String
from statham.dsl.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, DSL 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
Development
- Clone the repository:
git clone git@github.com:jacksmith15/statham-schema.git && cd statham-schema
- Install the requirements:
pip install -r requirements.txt -r requirements-test.txt
- Run
pre-commit install
- 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.
Project details
Release history Release notifications | RSS feed
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.11.0.tar.gz
(34.5 kB
view hashes)
Built Distribution
Close
Hashes for statham_schema-0.11.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0819d798fc693da2f34e010b4e0247716e9bffb5b63d8073d937abe36fc52425 |
|
MD5 | cd78a5208c33e637d6fc4c92bd577dd5 |
|
BLAKE2b-256 | 63b05556e40ce879ea249380cefaea3cfb492b6e33ae82195432595b96d2b5a0 |