Skip to main content

yamb

Build Status

YAml Meta Binding microframework

Define schema for YAML documents a-la SQLAlchemy to read, write and manipulate data like a python object.

Basic example

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.city

class 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'

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yamb-0.1.2.tar.gz (3.1 kB view details)

Uploaded Source

File details

Details for the file yamb-0.1.2.tar.gz.

File metadata

  • Download URL: yamb-0.1.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for yamb-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5f6e6782739d1cb3468d432600023488b2633659a926807ce0ddc37068c5467a
MD5 44b79596815746b870a8ae175463e037
BLAKE2b-256 e3d4c872948ca3e2ef968a93b42c541f9121fcc9ebd629e6a38fdf6f35557e46

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 file

0.1.1

1 file

0.1

1 file

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