Skip to main content

yamluna: YAML for Python, out of the box.

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 no indent() 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 !Server resolves 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.0

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

Built distributions (wheels)

Table of built distributions (wheels) for yamluna 0.1.0
File
yamluna-0.1.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
yamluna-0.1.0-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.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details
yamluna-0.1.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
yamluna-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size: 2.4 MB

Release files / yamluna-0.1.0-cp311-abi3-win_amd64.whl

Download URL yamluna-0.1.0-cp311-abi3-win_amd64.whl
Size 396.7 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a665f9e7ddd2a51368aa8eb619cf06a49ee5cd48ed1490d2420733f64259d55b
BLAKE2b-256 checksum
How to use checksums
8cdf50da4dd5c8922f946d6b46f4ad0b993f6344a6ae9cff4eed62278748ece6
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

Release files / yamluna-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL yamluna-0.1.0-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
1c81ef39f8c54affd986d99e41bb6c5aca3ff57d5a7e69790b094864958ffa96
BLAKE2b-256 checksum
How to use checksums
04955535e3e965481a5a493ca105330eeb4ba4f7efed7ede887cb92b6ed4752a
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

Release files / yamluna-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL yamluna-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 496.4 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
c13d7604fe10c26accbb2c8ed65235cee230f1092bce6c1dc3f2cc728476d919
BLAKE2b-256 checksum
How to use checksums
b5c9a8d7138834a6149b1a62896c9f31d744f52f680f74c9242aeb243f964d16
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

Release files / yamluna-0.1.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL yamluna-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Size 471.2 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
82536bf1ea5d54d953d0a907f7cd15e3cd4e0e90d9931ed6f52ed057dad4d0fe
BLAKE2b-256 checksum
How to use checksums
3750ad55b16f9cd1afc38862440dd3cfeafc5b161659e3f7e700d7f955a12d0f
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

Release files / yamluna-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL yamluna-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 487.4 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0edfa9ab500087b3b7369b1653707afdb952cf345f94b547c286f37f51732389
BLAKE2b-256 checksum
How to use checksums
b71cfdbc91c50d0861956b86231c270212648904c15d1bb2bbc27ae572cf2ef8
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

Release history Release notifications | RSS feed

0.1.1

6 release files

This release

0.1.0 This release

5 release files

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