Registry / serialization / yorm
library1.6.2pypypiunverified

YORM (YAML Object-Relational Mapper) is a Python library that provides automatic object-YAML mapping, allowing Python objects to be seamlessly persisted to and loaded from YAML files. It enables defining models with attributes that are automatically synchronized with a specified YAML file, supporting features like autosaving and schema validation. The current version is 1.6.2, and it has an active but irregular release cadence.

pip install yorm
INSTALL
IMPORT
SIG · YORM
Y
yorm
serializationpythonv1.6.2
Install
3.0s avg
Import
145ms
Disk
23MB
Pass rate
1/ 10
Env Coverage1 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.6.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✕ build_error
py 3.11
✕ build_error
✕ build_error
py 3.12
✕ build_error
✕ build_error
py 3.13
✕ build_error
✕ build_error
py 3.9
✕ build_error
✓ 3s
23MB installed
● package 23MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Model
import yorm class MyModel(yorm.Model):
Base class for YORM models.
attr
import yorm @yorm.attr(autosave=True) class MyModel(yorm.Model):
Decorator for classes and attributes. Use `@yorm.attr(autosave=True)` for class-level autosaving or `my_attr = yorm.attr(type=str)` for attribute definition.
sync
import yorm yorm.sync(MyModel, 'path/to/data.yaml')
yorm.sync(MyModel)
As of v1.6, `yorm.sync()` requires a path argument. Implicit paths are deprecated.

This quickstart demonstrates how to define a YORM model, synchronize it with a temporary YAML file, create and update objects, and verify persistence. It uses `autosave=True` for automatic saving of changes.

import yorm import os import tempfile import shutil # Create a temporary directory for the YAML file temp_dir = tempfile.mkdtemp() try: # Define a model with autosave enabled at the class level @yorm.attr(autosave=True) class Person(yorm.Model): name = yorm.attr(type=str) email = yorm.attr(type=str, default='') # Synchronize the model with a YAML file in the temporary directory file_path = os.path.join(temp_dir, 'person.yaml') yorm.sync(Person, file_path) print(f"Synchronized Person model with: {file_path}") # Create a new person object. Due to autosave=True, it's saved automatically. print("\nCreating Bob...") bob = Person(name="Bob", email="bob@example.com") print(f"Bob created: {bob.name} ({bob.email})") # Update an attribute. The change is saved automatically. print("Updating Bob's email...") bob.email = "robert@example.com" print(f"Bob's email updated to: {bob.email}") # Fetch all persons (should be just Bob) print("\nFetching all persons...") persons = Person.all() for p in persons: print(f"Found: {p.name} ({p.email})") # Verify the update by reloading and checking if persons and persons[0].email == "robert@example.com": print("Update verified: Bob's email is now robert@example.com") else: print("Error: Bob's email not updated as expected.") # Delete all persons. This also gets persisted. print("\nDeleting all persons...") Person.all().clear() print(f"Persons remaining after clear: {len(Person.all())}") finally: # Clean up the temporary directory shutil.rmtree(temp_dir) print(f"\nCleaned up temporary directory: {temp_dir}")
Debug
Known issues
deprecatedCalling `yorm.sync()` without a `path` argument is deprecated and will raise a `DeprecationWarning`.
fix
Always provide a `path` argument to `yorm.sync()`, e.g., `yorm.sync(Person, 'data/person.yaml')`.
affects: >=1.6
gotchaIf `autosave=False` is set (or omitted) on a model, changes to objects will not be automatically persisted to the YAML file. Data loss can occur if `model.save()` is not explicitly called.
fix
Ensure `autosave=True` in the `@yorm.attr` decorator for the class, or explicitly call `your_object.save()` after making changes to persist them.
affects: All versions
gotchaManually editing the generated YAML file in an incorrect format can lead to `ruamel.yaml` parsing errors or `yorm.exceptions.InvalidObjectError` when the data is loaded.
fix
Avoid manual editing of YORM-managed YAML files. If manual edits are necessary, ensure strict YAML syntax and schema adherence. In case of errors, inspect the YAML for malformed entries or incorrect data types.
affects: All versions
Upgrade
Version history
1.6.2latest on PyPI · released Mar 23, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
39 hits · last 30 days
node
32
OpenAI (training)
1
Resources
yorm — pip install yorm · libregistry