Skip to main content

python package dataclass utils

Project description

datclass

python dataclass nested & extra

扩展官方 dataclass,支持嵌套和额外字段

安装

pip install -U datclass
pip install git+ssh://git@github.com/foyoux/datclass.git
pip install git+https://github.com/foyoux/datclass.git

用法示例

from dataclasses import dataclass

from datclass import DatClass


@dataclass
class User(DatClass):
    name: str
    age: int


if __name__ == '__main__':
    user1 = User(name='foo', age=18)
    user1.to_file('user.json')
    user1.to_file('user.json', indent=4, ignore_none=True, sort_keys=True)

    user2 = User(**{'name': 'bar', 'age': 20})
    dict1 = user2.to_dict()
    dict2 = user2.to_dict(ignore_none=True)

    user3 = User.from_str('{"name": "baz", "age": 22}')
    dict3 = user3.to_str()
    dict4 = user3.to_str(indent=4, ignore_none=True)

    user4 = User.from_file('user.json')
    tuple4 = user4.to_tuple()

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

datclass-0.2.14.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

datclass-0.2.14-py3-none-any.whl (8.9 kB view hashes)

Uploaded Python 3

Supported by

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