https://github.com/yandex-qatools/yamb
YAml Meta Binding microframework
https://github.com/yandex-qatools/yamb
Last synced: 7 months ago
JSON representation
YAml Meta Binding microframework
- Host: GitHub
- URL: https://github.com/yandex-qatools/yamb
- Owner: yandex-qatools
- License: other
- Created: 2014-10-07T11:12:52.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-12-17T16:44:33.000Z (almost 11 years ago)
- Last Synced: 2025-01-12T17:13:06.715Z (9 months ago)
- Language: Python
- Size: 148 KB
- Stars: 2
- Watchers: 8
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
yamb
====.. image:: https://travis-ci.org/yandex-qatools/yamb.svg?branch=master
:alt: Build Status
:target: https://travis-ci.org/yandex-qatools/yamb/YAml Meta Binding microframework
Define schema for YAML documents a-la SQLAlchemy to read, write and manipulate data like a python object.
Basic example
=============.. code:: python
from yamb import Literal, Nested, Collection, YAMBObject
class Address(YAMBObject):
city = Literal(default='New York')
street = Literal()class Person(YAMBObject):
name = Literal()
phone = Literal()
address = Nested(Address)def lives_close_to(self, another_person):
return self.address.city == another_person.address.cityclass Phonebook(YAMBObject):
title = Literal()
people = Collection(Person)friends = Phonebook(title='Friends', people=[])
friends.people.append(Person(name='Sue', phone='+12345', address=Address(street='Some blvd')))
sam = Person(name='Sam', phone='+123456', address=Address(city='London', street='Picadilly'))
friends.people += [sam]with open('friends.yml', 'w') as f:
f.write(friends._dump())parsed = Phonebook._load(open('friends.yml'))
assert parsed.title == 'Friends'
assert parsed.people[0].address.city == 'New York'
assert parsed.people[1].name == 'Sam'