Skip to main content

Automatic object YAML mapping for Python.

Project description

YORM

Build Status
Coverage Status
Scrutinizer Code Quality
PyPI Version
PyPI Downloads

YORM provides functions and decorators to enable automatic, bidirectional, and human-friendly mappings of Python object attributes to YAML files.

Uses beyond typical object serialization and mapping include:

  • bidirectional conversion between basic YAML and Python types

  • attribute creation and type inference for new attributes

  • storage of content in text files optimized for version control

  • extensible converters to customize formatting on complex classes

Getting Started

Requirements

  • Python 3.3+

Installation

YORM can be installed with pip:

$ pip install YORM

or directly from the source code:

$ git clone https://github.com/jacebrowning/yorm.git
$ cd yorm
$ python setup.py install

Basic Usage

Simply take an existing class:

class Student:
    def __init__(self, name, school, number, year=2009):
        self.name = name
        self.school = school
        self.number = number
        self.year = year
        self.gpa = 0.0

and define an attribute mapping:

import yorm
from yorm.standard import String, Integer, Float

@yorm.attr(name=String, year=Integer, gpa=Float)
@yorm.sync("students/{self.school}/{self.number}.yml")
class Student:
    ...

Modifications to each object’s mapped attributes:

>>> s1 = Student("John Doe", "GVSU", 123)
>>> s2 = Student("Jane Doe", "GVSU", 456, year=2014)
>>> s1.gpa = 3

are automatically reflected on the filesytem:

$ cat students/GVSU/123.yml
name: John Doe
gpa: 3.0
school: GVSU
year: 2009

Modifications and new content in each mapped file:

$ echo "name: John Doe
> gpa: 1.8
> year: 2010
> expelled: true
" > students/GVSU/123.yml

are automatically reflected in their corresponding object:

>>> s1.gpa
1.8
>>> s1.expelled
True

For Contributors

Requirements

Installation

Create a virtualenv:

$ make env

Run the tests:

$ make test
$ make tests  # includes integration tests

Build the documentation:

$ make doc

Run static analysis:

$ make pep8
$ make pep257
$ make pylint
$ make check  # includes all checks

Prepare a release:

$ make dist  # dry run
$ make upload

Changelog

0.3 (dev)

  • Updated mapped objects to only read from the filesystem if there are changes.

  • Renamed store to sync_object.

  • Renamed store_instances to sync_instances.

  • Renamed map_attr to attr.

  • Added sync to call sync_object or sync_instances as needed.

  • Added update_object and update_file to force syncrhonization.

  • Added update to call update_object and/or update_file as needed.

0.2.1 (2015-2-12)

  • Container types now extend their builtin type.

  • Added None<Type> extended types with None as a default.

  • Added AttributeDictionary with keys available as attributes.

  • Added SortedList that sorts when dumped.

0.2 (2014-11-30)

  • Allowing map_attr and store to be used together.

  • Allowing Dictionary containers to be used as attributes.

  • Fixed method resolution order for modified classes.

  • Added a yorm.settings.fake option to bypass the filesystem.

0.1.1 (2014-10-20)

  • Fixed typos in examples.

0.1 (2014-09-29)

  • Initial release.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

YORM-0.3a1.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

YORM-0.3a1-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file YORM-0.3a1.tar.gz.

File metadata

  • Download URL: YORM-0.3a1.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for YORM-0.3a1.tar.gz
Algorithm Hash digest
SHA256 a574b80eaebb2ed160891628427f6f9e09d35ba7b0800e98e2efe9a53df45a41
MD5 71659d7ae2f03829cd2bacbb3e29a20d
BLAKE2b-256 92ab13df1f284ea24fd861f1579419ac63c1cdbefa96d9064941c6be8c6e2194

See more details on using hashes here.

File details

Details for the file YORM-0.3a1-py3-none-any.whl.

File metadata

File hashes

Hashes for YORM-0.3a1-py3-none-any.whl
Algorithm Hash digest
SHA256 379097ab00de253263e669c57fbd43d0de78638715afdba63116e921005f8496
MD5 620b68147117b50d99f7766cced877ff
BLAKE2b-256 9841ff251c86f9d84486ac491843a46b6e2fc6155b46cacdb2cb7b676f51b7e2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page