Automatic object-YAML mapping for Python.
| |Build Status| | |Coverage Status| | |Scrutinizer Code Quality| | |PyPI Version|
| YORM enables automatic, bidirectional, human-friendly mappings of object attributes to YAML files. | Uses beyond typical object serialization and relational mapping include:
View the talk from PyOhio 2015 <https://www.youtube.com/watch?v=0woNEKf-wAo>
__.
Install YORM with pip:
.. code:: sh
$ pip install YORM
or directly from the source code:
.. code:: sh
$ git clone https://github.com/jacebrowning/yorm.git
$ cd yorm
$ python setup.py install
Simply take an existing class:
.. code:: python
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:
.. code:: python
import yorm
from yorm.types 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:
.. code:: python
>>> s1 = Student("John Doe", "GVSU", 123)
>>> s2 = Student("Jane Doe", "GVSU", 456, year=2014)
>>> s1.gpa = 3
are automatically reflected on the filesytem:
.. code:: sh
$ cat students/GVSU/123.yml
name: John Doe
gpa: 3.0
school: GVSU
year: 2009
Modifications and new content in each mapped file:
.. code:: sh
$ echo "name: John Doe
> gpa: 1.8
> year: 2010
" > students/GVSU/123.yml
are automatically reflected in their corresponding object:
.. code:: python
>>> s1.gpa
1.8
.. |Build Status| image:: http://img.shields.io/travis/jacebrowning/yorm/master.svg :target: https://travis-ci.org/jacebrowning/yorm .. |Coverage Status| image:: http://img.shields.io/coveralls/jacebrowning/yorm/master.svg :target: https://coveralls.io/r/jacebrowning/yorm .. |Scrutinizer Code Quality| image:: http://img.shields.io/scrutinizer/g/jacebrowning/yorm.svg :target: https://scrutinizer-ci.com/g/jacebrowning/yorm/?branch=master .. |PyPI Version| image:: http://img.shields.io/pypi/v/yorm.svg :target: https://pypi.python.org/pypi/yorm
YAMLLoadWarning
by using yaml.safe_load()
.PyYAML
to 5.1
for security fixes.Number
(and NullableNumber
) type for floats that store
as integers when possible.List
converter to accept tuples as lists.match
utility (credit:
@astronouth7303 <https://github.com/astronouth7303>
__).auto_resolve
to clean up file conflicts
automatically.Removed warnings about calling save/load unnecessarily.
Now allowing keyword arguments to be passed to class construction via
create
and find
utilities.
Now adding additional attributes from __init__
on
AttributeDictionary
.
__init__
must not use
positional arguments.DEPRECIATION: Renamed ModelMixin.new
to
ModelMixin.create
.
ModelMixin
to add ORM methods to mapped classes.pytest
traceback in wrapped methods.data
property to Mapper
as a hook for other
serialization libraries.list
and dict
.__init__
in Dictionary
converters to run custom
validations.sync()
.auto=True
to auto_save=True
.strict=True
to auto_track=False
.auto_create
to defer file creation to ORM
functions.attr
decorators on Dictionary
converters.String
to fetch true
and false
as strings.attr
decorators.attr
decorator to a single argument.List.of_type()
factory to create lists with less
boilerplate.None
in NullableString
.yorm.converters
to yorm.types
.strict=False
.String
to only use quotes if absolutely
necessary.yorm.base
to yorm.bases
.auto=False
.dict
when conversion to dict
.yorm.converters
package.container
to containers
.Converter
to Convertible
for mutable typesConverter
class for immutable typesutilities.update
.store
to sync_object
.store_instances
to sync_instances
.map_attr
to attr
.sync
to call sync_object
or sync_instances
as
needed.update_object
and update_file
to force synchronization.update
to call update_object
and/or update_file
as
needed.None<Type>
extended types with None
as a default.AttributeDictionary
with keys available as attributes.SortedList
that sorts when dumped.map_attr
and store
to be used together.Dictionary
containers to be used as attributes.yorm.settings.fake
option to bypass the filesystem.