Skip to main content

Library for converting yaml structures to Python objects, based on a predefined object hierarchy schema.

Given a schema of class hierarchy

from wattle import load_schema
from wattle.nodes import Nested, Value


class MessagePrinter:
    indent = Value(int)
    capitalize = Value(bool)

    def print(self, message):
        if self.indent:
            message = (" " * self.indent) + message
        if self.capitalize:
            message = message.upper()
        print(message)


class HelloWorld:
    message = Value(str)
    how_many_times = Value(int, default=25)
    printer = Nested(MessagePrinter)

    def print(self):
        for _ in range(self.how_many_times):
            self.printer.print(self.message)


if __name__ == '__main__':
    schema = load_schema(HelloWorld)
    root = schema.read('examples/hello_world/input.yml')
    root.print()

and the input yaml file

message: Hello world
how_many_times: 5
printer:
  indent: 4
  capitalize: yes

Will result in an already populated object

assert root.message == 'Hello world'
assert isinstance(root.printer, MessagePrinter)
root.print()

Metadata

Release files for woning-wattle 0.4.1

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

Source distribution (sdist)

Source distribution for woning-wattle 0.4.1
File Size Uploaded
woning-wattle-0.4.1.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for woning-wattle 0.4.1
File Interpreter ABI Platform
woning_wattle-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / woning-wattle-0.4.1.tar.gz

Download URL woning-wattle-0.4.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
15c4f72d95429643bad0e6fbcb862417125e0dd14715c2439433906a7d2056a6
BLAKE2b-256 checksum
How to use checksums
592309e423c646e0e94c179f9ee1d96beb39bdf3e68937e3622b65919f7f1c1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / woning_wattle-0.4.1-py3-none-any.whl

Download URL woning_wattle-0.4.1-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce872ca771768b641245c44ea12ecf16bfeff0beedc34fc71405456cda9259bc
BLAKE2b-256 checksum
How to use checksums
a9d9034f07cc8547a5e060b3fe92b7108da7769d4d06f3666d1a70b8425d6539
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

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