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__(name, number, grade=9):
        self.name = name
        self.number = number
        self.grade = grade
        self.gpa = 0.0

Define an attribute mapping:

from yorm import store_instances, map_attr
from yorm.standard import

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

And interact with objects normally:

>>> s1 = Student("John Doe", 123)
>>> s2 = Student("Jane Doe", 456, grade=12)
>>> s1.gpa = 3

Mapped attributes are automatically reflected on the filesytem:

$ cat students/9/123.yml
name: John Doe
gpa: 3.0
grade: 9

And in the objects:

$ echo "name: John Doe
> gpa: 1.8
> grade: 9
> expelled: true
" > students/9/123.yml
>>> 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 (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-rc.1.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

YORM-0.1_rc.1-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file YORM-0.1-rc.1.tar.gz.

File metadata

  • Download URL: YORM-0.1-rc.1.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for YORM-0.1-rc.1.tar.gz
Algorithm Hash digest
SHA256 0347aae88f5d4b76537c495160f34573099c7ec64bd2e1063e3962989f2b0c4e
MD5 81c982966025e8d7ace06826be941aad
BLAKE2b-256 e9bb64b12e756f060b34f307dbdabe78bb364d6e8cef9ec02e0c5a551d2aec4d

See more details on using hashes here.

File details

Details for the file YORM-0.1_rc.1-py3-none-any.whl.

File metadata

File hashes

Hashes for YORM-0.1_rc.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e117343c486ed171b4fc0fdef826f32becf8954ecd29a39d4a611017d09c6cd8
MD5 8260d08d3963d705cb8076bebefcd3a1
BLAKE2b-256 2bf6cc1d44917e69bf56be693fc96a3456309d882ed312f2dd3a22fb24662b00

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