Skip to main content

yamliz

Python's 3.7 dataclasses got maried with pyyaml.

Installation:

pip install yamliz

Usage example:

import dataclasses
import yamliz
from yamliz import fields

@dataclasses.dataclass
class Some(yamliz.Able):
    id: int = fields.Integer()
    mac: str = fields.MacAddress()
    ip: str = fields.IPv4()
    version: int = fields.Integer(default=411)

Now the Some object can be created as a pure python object (thanks to dataclass) it is equipped with __init__, __repr__, __eq__ and some other methods.

>>> obj = Some(123, 'aa:bb:cc:11:22:33', '192.168.11.6')
>>> obj
Some(id=123, mac='aa:bb:cc:11:22:33', ip='192.168.11.6', version=411)

>>> print(obj)
!iz/Some
id: 123
ip: 192.168.11.6
mac: aa:bb:cc:11:22:33
version: 411

It's attributes are regular python attributes:

>>> obj.id
123

>>> obj.mac
'aa:bb:cc:11:22:33'

>>> obj.ip
'192.168.11.6'

>>> obj.version = 0  # can be assigned
>>> print(repr(obj))
Ints(id=123, mac='aa:bb:cc:11:22:33', ip='192.168.11.6', version=0)

It can be also deserialized from yaml directly to the custom object:

>>> yaml_string = """
!iz/Some
id: 22001
ip: 12.13.14.15
mac: aa:bb:cc:11:22:33
version: 0
"""

>>> import yaml
>>> obj2 = yaml.load(yaml_string, Loader=yaml.Loader)
>>> repr(obj2)
Some(id=22001, mac='aa:bb:cc:11:22:33', ip='12.13.14.15', version=0)

To be further documented...

Metadata

Release files for yamliz 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yamliz 0.1.2
File Size Uploaded
yamliz-0.1.2.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yamliz 0.1.2
File Interpreter ABI Platform
yamliz-0.1.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 19.0 kB

Release files / yamliz-0.1.2.tar.gz

Download URL yamliz-0.1.2.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f191d409c9d7aa8bf141c5179d7b1c2bdff3c98b75befdb73dda6c10b133b8e3
BLAKE2b-256 checksum
How to use checksums
2d4028a6c9d8b622b644a9fccf321a50008f99017e831d8a171d66ec9946e978
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.3

Release files / yamliz-0.1.2-py2.py3-none-any.whl

Download URL yamliz-0.1.2-py2.py3-none-any.whl
Size 13.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b46a904bce40c058f01a3802dc538b6a4536a0ec03a293947906c8fd0a4142fb
BLAKE2b-256 checksum
How to use checksums
92f89ea780d407553017a1120e07dfbb7237e9edd0877b7a78f1afc817b1d34a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page