Giter Site home page Giter Site logo

json-schema-to-class's Introduction

json-schema-to-class Build Status codecov PyPI version

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

# generate code with __repr__ method
json-schema-to-class tests/test_schema.json --indent 2 --repr | pygmentize

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(list):
    def __init__(self, values: list = None):
        super().__init__()
        values = values if values is not None else []
        self[:] = [LrSchedulerConfig(value) for value in values]

json-schema-to-class's People

Contributors

sf-zhou avatar saroad2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.