Skip to main content

ysaqml provides a YAML-backed persistence layer for SQLAlchemy.

Project description

ysaqml

PyPI - Python Version License Platforms GitHub release

Overview

ysaqml provides a YAML-backed persistence layer for SQLAlchemy. Tables live in memory inside SQLite for fast queries, while their contents are loaded from – and saved back to – .yaml files using the blazing-fast naay parser/dumper.

Why?

  • Keep relational workflows while still committing plain-text fixtures.
  • Edit data in YAML, rely on SQLite for constraints and transactions.
  • Round-trip friendly thanks to naay's strict string-only subset.

Installation

pip install -e .

This pulls in SQLAlchemy and naay. Tests rely on pytest (install with pip install -e .[test]).

Usage

Context-managed workflow

from pathlib import Path
from sqlalchemy import Column, Integer, MetaData, String, Table, select

from ysaqml import YamlSqliteEngine

metadata = MetaData()
users = Table(
		"users",
		metadata,
		Column("id", Integer, primary_key=True),
		Column("name", String, nullable=False),
)

data_dir = Path("./data")

with YamlSqliteEngine(metadata, data_dir) as backend:
		engine = backend.engine
		with engine.begin() as conn:
				conn.execute(users.insert().values(id=1, name="Ada"))
				result = conn.execute(select(users)).mappings().all()
				print(result)
# context manager flushes SQLite rows back into data/users.yaml

Each SQLAlchemy table is materialized to <data_dir>/<table_name>.yaml. When entering the context the engine wipes any existing rows in the in-memory database, rehydrates them from YAML if the file exists, and on successful exit dumps the SQLite contents back to YAML.

Custom dialect / engine helper

ysaqml also registers a SQLAlchemy dialect so you can build engines with ysaqml:/// URLs. The convenience helper wires up the required engine plugin and disposes the engine when you are done:

from contextlib import closing
from pathlib import Path
from sqlalchemy import Column, Integer, MetaData, String, Table, select

from ysaqml import create_yaml_engine

metadata = MetaData()
users = Table(
		"users",
		metadata,
		Column("id", Integer, primary_key=True),
		Column("name", String, nullable=False),
)

data_dir = Path("./data")

with closing(create_yaml_engine(metadata, data_dir)) as engine:
		with engine.begin() as conn:
				conn.execute(users.insert().values(id=1, name="Ada"))
				print(conn.execute(select(users)).mappings().all())
# exiting the context disposes the engine and writes YAML files

Under the hood this builds an in-memory SQLite engine using the ysaqml dialect and attaches an engine plugin that loads YAML files immediately and saves them back when the engine is disposed. If you manage the engine manually, make sure to call engine.dispose() to persist your changes.

File format

Every YAML document uses the following schema:

_naay_version: "1.0"
rows:
	- id: "1"
		name: "Ada"
  • _naay_version is validated but not enforced – it defaults to ysaqml.DEFAULT_NAAY_VERSION and is kept intact when re-saving.
  • rows is an ordered list of dictionaries where every value is a string.

ysaqml serializes Python None values as the sentinel string __NULL__. When loading back, that string becomes None again, so avoid storing it as a literal value.

Testing

pytest

The tests create temporary directories and exercise the full load → mutate → dump loop.

License

Released under the GNU LGPL-3.0-or-later.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ysaqml-2025.12.6.post3.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ysaqml-2025.12.6.post3-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file ysaqml-2025.12.6.post3.tar.gz.

File metadata

  • Download URL: ysaqml-2025.12.6.post3.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ysaqml-2025.12.6.post3.tar.gz
Algorithm Hash digest
SHA256 02154de0b2b8b98cd3b6ea93f0b4aaac0eafda2720323498f048ab4e69c5a9c8
MD5 9992360ce410f1c376f5434d48f76008
BLAKE2b-256 8acf4b9e15aa8aaad23e59fa96a347ce7135e9b6d71d6eb69a9f82a0b1659faf

See more details on using hashes here.

Provenance

The following attestation bundles were made for ysaqml-2025.12.6.post3.tar.gz:

Publisher: release.yml on rbroderi/ysaqml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ysaqml-2025.12.6.post3-py3-none-any.whl.

File metadata

File hashes

Hashes for ysaqml-2025.12.6.post3-py3-none-any.whl
Algorithm Hash digest
SHA256 a020cd5cefee9df2c5eb3decc7a24ecbd53d32cc3af8230da02158466ee10c0c
MD5 24d2861773e88b7f7672976ac880cb50
BLAKE2b-256 fde0c6670195daadbd8ecc49e2b9fc4c9dc059b9f39e71aa958cb3b5235cb28c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ysaqml-2025.12.6.post3-py3-none-any.whl:

Publisher: release.yml on rbroderi/ysaqml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page