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 object mapping include:

  • automatic bidirectional conversion of attributes types

  • attribute creation and type inference for new attributes

  • storage of content in text files optimized for version control

  • custom converters to map complex classes to JSON-compatible types

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:

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

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

Modifications to an 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 the mapped file:

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

are automatically reflected in the objects:

>>> 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.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.1.1.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

YORM-0.1.1-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file YORM-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for YORM-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ecc8db32e9ae006e7822d9105526089bb787ca3f1f7b618cfb42cfdfbe4a6a0f
MD5 d21519dc7da36a5e9784f2775f097e0e
BLAKE2b-256 b4452b8e1fe51873cf1710f427a04b41570af8cfcee1cff195140e7f955f8602

See more details on using hashes here.

File details

Details for the file YORM-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for YORM-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 24f2aab9de4c00df5b3575e987c84a08c74bfe990a56104eecd70cb5ebc3d850
MD5 42153afd27d791a6ab0b438d58f7791f
BLAKE2b-256 6d921351ed2289580dbee8802dfd925047e2664947c09159e26633dfacc291b3

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