Skip to main content

ymlstash

A simple ORM-like utility for operating on local YAML files via Python dataclasses.

In the context of this library, a stash is a diretory in the filesystem that holds many .yml files that all adhere to the same structure.

ymlstash simplifies the management of such a basic database of files.

Install

Package is published on PyPI - https://pypi.org/project/ymlstash/

Install from pip or your favorite package manager:

$ pip install ymlstash

Usage

Start by defining your model as a dataclass:

from dataclasses import dataclass
from typing import ClassVar

@dataclass
class User:
    name: str
    age: int
    active: bool
    key: ClassVar[str] = "name"

Primary Keys

Each model must include a primary key that will be used as the entry filename to uniquely access each record.

The recommended way do to this is with the special key field which is used to denote that name should be used as the primary key field. If an object has name: "foo", it will be saved as foo.yml in the stash root directory.

Actions

Instantiate a new object:

user = User(name="yuval", age=42, active=True)

Save it to file:

from ymlstash import YmlStash

stash = YmlStash(User, "path/to/db")  # path can either be a string or Path() object
stash.save(user)

This will create a yuval.yml file in the stash root directory.

If the key field is not present on the dataclass, an explicit key must be passed:

stash.save(obj, key="custom-key")

Load from file:

user = stash.load("yuval")

List all keys existing in stash:

keys = stash.list_keys()

Delete a key:

stash.delete("foo")

Check for key existence:

stash.exists("foo")

Drop all files (careful, this deletes everything):

stash.drop()

License

MIT

Metadata

Release files for ymlstash 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ymlstash 1.2.1
File Size Uploaded Provenance
ymlstash-1.2.1.tar.gz 3.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ymlstash 1.2.1
File Interpreter ABI Platform
ymlstash-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / ymlstash-1.2.1.tar.gz

Download URL ymlstash-1.2.1.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
48d6ed27f5c2f9d28a3ed78c082cf464c9fe29a139a1097bfd9911952583090c
BLAKE2b-256 checksum
How to use checksums
40f0d4c2449e5b06453c6851d04b88d1b2a9e6923c82e0de6671cd6591543a39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.8.9-arch1-1

Release files / ymlstash-1.2.1-py3-none-any.whl

Download URL ymlstash-1.2.1-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d96dbb9c706648dea5213da607bb42270fe9fdebc5cf4a50e869193df11f195e
BLAKE2b-256 checksum
How to use checksums
32ab08942be2c9fa9c8455efa20ab546f29a7c25b2c715ed9001a1967f516b0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.8.9-arch1-1

Security for ymlstash 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page