yamluna (pronounced yam-LOO-nuh) reads and writes YAML without setup. A plain YAML() loads a file, lets you change it, and saves it with everything you did not touch exactly as it was written: comments, blank lines, quotes, indentation, anchors, and document markers. Register a class and its objects go into the file under a tag and load back as themselves, whether it is your own dataclass or a type you do not own, such as numpy's ndarray. Parsing and writing happen in Rust.
Edit a file
from yamluna import YAML
yaml = YAML()
config = yaml.load("""# Production service
image: app:1.4 # approved release
replicas: 3
ports:
- 80 # HTTP
- 443 # HTTPS
""")
config['replicas'] = 5
config['ports'].append(8080)
print(yaml.dump(config), end='')
Output:
# Production service
image: app:1.4 # approved release
replicas: 5
ports:
- 80 # HTTP
- 443 # HTTPS
- 8080
Two edits, and the rest of the file is unchanged. Loaded mappings and lists are Python dict and list subclasses, so there is no new API to learn for editing them.
Store your own classes
Decorate a class to register it. There is nothing else to write:
from dataclasses import dataclass
from yamluna import YAML
yaml = YAML()
@yaml.register_class
@dataclass
class Server:
host: str
port: int = 80
text = yaml.dump({'primary': Server('web-1', 8080)})
print(text, end='')
print(yaml.load(text)['primary'])
Output:
%TAG ! tag:__main__/
---
primary: !Server
host: web-1
port: 8080
Server(host='web-1', port=8080)
The %TAG line records the package the class came from (__main__ here, because this is a script), so two libraries can each define a Server without one overwriting the other. Each YAML() keeps its own registrations.
Register types you do not own
Call register_class with a to_yaml function that writes the object and a from_yaml function that reads it back:
import numpy as np
from yamluna import YAML, CommentedSeq
def flow(items):
seq = CommentedSeq(items)
seq.fa.set_flow_style()
return seq
def array_to_yaml(representer, array):
fields = {
'dtype': str(array.dtype),
'shape': flow(array.shape),
'data': flow(array.ravel().tolist()),
}
return representer.represent_mapping(representer.plan.tags[np.ndarray], fields)
def array_from_yaml(constructor, node):
fields = constructor.construct_mapping(node)
return np.array(fields['data'], dtype=fields['dtype']).reshape(fields['shape'])
yaml = YAML()
yaml.register_class(np.ndarray, to_yaml=array_to_yaml, from_yaml=array_from_yaml)
text = yaml.dump({'weights': np.eye(2, dtype=np.float32)})
print(text, end='')
print(repr(yaml.load(text)['weights']))
Output:
%TAG ! tag:numpy/
---
weights: !ndarray
dtype: float32
shape: [2, 2]
data: [1.0, 0.0, 0.0, 1.0]
array([[1., 0.],
[0., 1.]], dtype=float32)
The same pattern works for Decimal, UUID, or a class from a C extension. Custom classes covers tags, namespaces, and hooks.
Why yamluna?
- Round trips without settings. In the project's 40-file round-trip corpus, yamluna reproduces all 40 files byte for byte; ruamel.yaml reproduces 3, StrictYAML 2, and PyYAML and py-yaml12 none. There is no
typ=and noindent()call to match the file's style. Comparison and method. - Python objects in and out. One decorator for your own classes, two functions for anyone else's. Tags are namespaced by package, and a hand-written
!Serverresolves as long as only one registered class could be meant. - Comments that follow your edits. Reorder a list or delete a setting and its comments go with it. Examples and current limits.
- Fast. A load-and-save cycle is 1.7 to 6.0 times faster than ruamel.yaml and faster than StrictYAML, the other libraries that keep comments. Libraries that discard formatting, such as PyYAML with libyaml, are faster still. See the measurements.
- Familiar API. Coming from PyYAML, ruamel.yaml, py-yaml12, or StrictYAML? The migration guides list the changes; for ruamel.yaml, it is mostly the import and
typ=.
Install
Install from PyPI with Python 3.11+:
python -m pip install yamluna
Pass a Path to read or write a file: yaml.load(Path('config.yaml')) and yaml.dump(config, Path('config.yaml')). A string passed to load() is YAML text.
Installation guide · Known limitations
Learn more
Documentation · User guide · API reference · Changelog · Report an issue
Python 3.11+ · YAML 1.2, with support for documents declaring YAML 1.1 · MIT or Apache-2.0
Release files for yamluna 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| yamluna-0.1.1.tar.gz | 276.3 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| yamluna-0.1.1-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details |
| yamluna-0.1.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| yamluna-0.1.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| yamluna-0.1.1-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details |
| yamluna-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 2.6 MB
Release files / yamluna-0.1.1.tar.gz
| Download URL | yamluna-0.1.1.tar.gz |
|---|---|
| Size | 276.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5cea2cd2efdaae6301a73d33d9bd51ce3ded8f3b681dfcf38545aae0c1dcd195
|
|
BLAKE2b-256 checksum How to use checksums |
9eb75bd31c8f1adc30c1abdee32ea291df5312133b4066da5e2d143364eba0c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency logRelease files / yamluna-0.1.1-cp311-abi3-win_amd64.whl
| Download URL | yamluna-0.1.1-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 396.7 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e60359259715efe8976d5b750eaf3bd37779c5db7bb183cdf40cc00a02054795
|
|
BLAKE2b-256 checksum How to use checksums |
b0503f158971091b985608d0ee192aaaabe3682040e21f396c5b0896daa3d993
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency logRelease files / yamluna-0.1.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | yamluna-0.1.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 506.3 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
6e0946d9e265b8a1e9d15daa22515a86a307939e5d976875fc863e80c0763450
|
|
BLAKE2b-256 checksum How to use checksums |
9148ffa20a44e514dda695498505a64d5d684ce941fbf20be44219743799b729
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency logRelease files / yamluna-0.1.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | yamluna-0.1.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 496.6 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
e83e0ecdca2d075f6d55282ed74d8611e166a1b1a5f0990294669766d83410a2
|
|
BLAKE2b-256 checksum How to use checksums |
b3805aedd05eac21ca1943c3e2bfff4d40450fbcb2e9de9389a94b516ef9d9b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency logRelease files / yamluna-0.1.1-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | yamluna-0.1.1-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 471.1 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f9de40a2cf09d8b3ff062270ca034e9f98b2d95446ad048566e31d8995e9b4d5
|
|
BLAKE2b-256 checksum How to use checksums |
831e6c9fcd6ca8378eaa4272f394db068388b01742f3774cb74c3243acf1c58c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency logRelease files / yamluna-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | yamluna-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 487.5 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
721df684d79eaa6698d14a3dbca98212ebb542d8256a0903330d8052f7a64bca
|
|
BLAKE2b-256 checksum How to use checksums |
24f9ff4c6eddf332795663947a4eaa8c49012fb0d16cda3961f18d9769c022d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency log