Skip to content
/ dtc Public

Generate Python Dataclasses without writting them !

Notifications You must be signed in to change notification settings

jgirardet/dtc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

https://travis-ci.org/jgirardet/dtc.svg?branch=master https://ci.appveyor.com/api/projects/status/ffd44ndqx713yuhd/branch/master?svg=true

DTC :"Generate Dataclasses without writting them !"

Warning

This is an alpha version

Basic Usage

Dataclass instance lazy building from json

>>> import dtc
>>> JSON = b"""{"flooat": 12.564, "boolean": true, "integer": 12}"""
>>> my_class = dtc.from_json(JSON)
>>> my_class
Base(flooat=12.564, boolean=True, integer=12)
>>> from dataclasses import *
>>> is_dataclass(my_class)
True
>>> JSON = b"""[{"flooat": 12.4, "boolean": true, "integer": 1}, {"flooat": 12.564, "boolean": true, "integer": 12},{"flooat": 1.4, "boolean": false, "integer": 0}]"""
# parse from json object or list
>>> dtc.from_json(JSON)
    [Base(flooat=12.4, boolean=True, integer=1), Base(flooat=12.564, boolean=True, integer=12), Base(flooat=1.4, boolean=False, integer=0)]

Get dataclass implementation code

>>> my_class = dtc.from_json(JSON)

>>> code = dtc.format_class(my_class)
>>> print(code)
@dataclass
class Base:
    flooat: float
    boolean: bool
    integer: int

# Et Voilà !

About

Generate Python Dataclasses without writting them !

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published