Convert JSON Schema into Python Class
Project description
json-schema-to-class
Convert JSON Schema into Python Class
Installation
Need Python 3.6+.
pip install json-schema-to-class
Usage
For example, convert tests/test_schema.json into Python class:
# generate & highlight
json-schema-to-class tests/test_schema.json --indent 2 | pygmentize
# or generate to file
json-schema-to-class tests/test_schema.json -o tests/schema_build.py
Get tests/schema_build.py
as follow:
from typing import List
class WarmUp:
def __init__(self, values: dict = None):
values = values if values is not None else {}
self.start: float = values.get("start", 0.0)
self.steps: int = values.get("steps", 0)
class LrSchedulerConfig:
def __init__(self, values: dict = None):
values = values if values is not None else {}
self.lr_mode: str = values.get("lr_mode", 'cos')
self.base_lr: float = values.get("base_lr", None)
self.target_lr: float = values.get("target_lr", 0.0002)
self.decay_factor: float = values.get("decay_factor", 0.1)
self.milestones: List[float] = values.get("milestones", [0.3, 0.6, 0.9])
self.lr_decay: float = values.get("lr_decay", 0.98)
self.warm_up = WarmUp(values=values.get("warm_up"))
class LrSchedulerConfigs:
def __init__(self, values: list = None):
values = values if values is not None else []
self.items: List[LrSchedulerConfig] = [
LrSchedulerConfig(values=value) for value in values
]
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
Built Distribution
Close
Hashes for json-schema-to-class-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3878e1b8e24aa9b49b35f8e6ee907dcb9ba71c01869f2e726d9161a3144c2e44 |
|
MD5 | 23b559693ebf1729c3b058774db72d69 |
|
BLAKE2b-256 | 25a1cbeab17da9dfa0843e950ddceeb57879141253760d99aba3cfc68a7a8fb2 |
Close
Hashes for json_schema_to_class-0.2.0-py3.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66d9a5d797655798d5da954db5db9047c2c0b0279ecac243ef15d21305425d5d |
|
MD5 | f297addf1a311b90f92b2cc6e27c2d3e |
|
BLAKE2b-256 | de1cf8f973b6b1c6177b8a61b64c175dc1ac4249065c7ecfc6af021682c8cdbe |