Library for converting yaml structures to Python objects, based on a predefined object hierarchy schema.
Project description
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()
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file woning-wattle-0.4.1.tar.gz.
File metadata
- Download URL: woning-wattle-0.4.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15c4f72d95429643bad0e6fbcb862417125e0dd14715c2439433906a7d2056a6
|
|
| MD5 |
96420994396041a02f73122d84bee7d9
|
|
| BLAKE2b-256 |
592309e423c646e0e94c179f9ee1d96beb39bdf3e68937e3622b65919f7f1c1f
|
File details
Details for the file woning_wattle-0.4.1-py3-none-any.whl.
File metadata
- Download URL: woning_wattle-0.4.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce872ca771768b641245c44ea12ecf16bfeff0beedc34fc71405456cda9259bc
|
|
| MD5 |
24a5459c3c658266a2097bc3d160174f
|
|
| BLAKE2b-256 |
a9d9034f07cc8547a5e060b3fe92b7108da7769d4d06f3666d1a70b8425d6539
|