Skip to main content

Automatic object YAML mapping for Python.

Project description

YORM

Enables automatic, bidirectional, human-friendly mappings of object attributes to YAML files.

Build Status
Coverage Status
Scrutinizer Code Quality
PyPI Version
PyPI Downloads

Uses beyond typical object serialization and relational 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:

$ pip3 install YORM

or directly from the source code:

$ git clone https://github.com/jacebrowning/yorm.git
$ cd yorm
$ python3 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.converters 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

# Revision History

## 0.6 (unreleased)

  • Added preliminary support for JSON serialization (@pr0xmeh).

## 0.5 (2015/09/25)

  • Renamed yorm.base to yorm.bases.

  • Stopped creating files on instantiation when auto=False.

  • Now automatically storing on fetch after initial store.

## 0.4.1 (2015/06/19)

  • Fixed attribute loss in non-dict when conversion to dict.

  • Now automatically adding missing attributes to mapped objects.

## 0.4 (2015/05/16)

  • Moved all converters into the yorm.converters package.

  • Renamed container to containers.

  • Renamed Converter to Convertible for mutable types

  • Added a new Converter class for immutable types

  • Removed the context manager in mapped objects.

  • Fixed automatic mapping of nested attributes.

## 0.3.2 (2015/04/07)

  • Fixed object overwrite when calling utilities.update.

## 0.3.1 (2015/04/06)

  • Fixed infinite recursion with properties that rely on other mapped attributes.

## 0.3 (2015/03/10)

  • 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 synchronization.

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

## 0.2.1 (2015/02/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.6.dev2.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

YORM-0.6.dev2-py3-none-any.whl (41.6 kB view details)

Uploaded Python 3

File details

Details for the file YORM-0.6.dev2.tar.gz.

File metadata

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

File hashes

Hashes for YORM-0.6.dev2.tar.gz
Algorithm Hash digest
SHA256 bb2ee7484cbef3f81dbcce76b263190364bae1c42cd5f88f67c5769481b5e491
MD5 dd1bc0b769e0724ad30533d358f04437
BLAKE2b-256 55df5d0ada884c68b8fc6d1c533b03b8d81d04b96f08465a9c1da0c5940911c5

See more details on using hashes here.

File details

Details for the file YORM-0.6.dev2-py3-none-any.whl.

File metadata

File hashes

Hashes for YORM-0.6.dev2-py3-none-any.whl
Algorithm Hash digest
SHA256 d03ddf7eef471794c810f80e712978b384e50a456cbdcd3f82d25087a70af2f2
MD5 1c793ae39755ea3b686992708e7f77e7
BLAKE2b-256 482e943dfb459baea9c089a105db2333fb72c2cec31e7dce7a1dab985758b469

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