Fast, modern yaml parser and manipulator
Project description
Yamlium
A high-performance, dependency-free YAML parser for Python that preserves all YAML features including comments, anchors, and formatting.
📦 Features
- 🎯 First-Class YAML Features: Preserves all YAML elements including comments, newlines, anchor names, and formatting
- ⚡ High Performance: 3x faster than PyYAML
- 🧹 Zero Dependencies: Pure Python implementation with no external dependencies
- 🛡️ Type Safety: Full type hints support
- 🛠️ Rich API: Intuitive interface for manipulating YAML structures
🛠️ Installation
pip install yamlium
🚀 Quick Start
Basic Parsing
from yamlium import parse
# Parse a YAML string
yaml_str = """
name: John Doe
age: 30
address:
street: 123 Main St
city: Boston
"""
data = parse(yaml_str)
# Access values
print(data["name"]) # John Doe
print(data["address"]["city"]) # Boston
Preserving YAML Features
from yamlium import parse
yaml_str = """
# User configuration
user: &user_ref # Anchor definition
name: Alice
role: admin
# Reference to user
admin: *user_ref # Alias reference
""".lstrip()
yml = parse(yaml_str)
# The YAML structure is preserved when converting back including:
# - Anchor names
# - Comments
# - Newlines between objects
print(yml.to_yaml() == yaml_str)
Manipulating YAML
from yamlium import parse
yaml_str = """
users: # List of users
- name: alice
age: 25
- name: Bob
age: 30
- name: charlie
"""
yml = parse(yaml_str)
# Modify values while preserving structure
for key, value, obj in yml.walk_keys():
if key == "age":
value += 1
elif key == "name":
# Using the string manipulation interface `.str`
obj[key] = value.str.capitalize()
print(yml.to_yaml())
JSON Conversion
from yamlium import from_json, from_dict
# Convert from JSON string
json_str = '{"name": "test", "values": [1, 2, 3]}'
yaml_data = from_json(json_str)
# Convert from Python dict
python_dict = {"name": "test", "values": [1, 2, 3]}
yaml_data = from_dict(python_dict)
📚 API Reference
Parsing Functions
parse(input: str | Path) -> MappingParse a single YAML documentparse_full(input: str | Path) -> DocumentParse multiple YAML documentsfrom_json(input: str | Path) -> Mapping | SequenceConvert JSON to YAML structurefrom_dict(input: dict | list) -> Mapping | SequenceConvert Python dict/list to YAML structure
Yaml object functions
Given:
from yamlium import parse
yml = parse("my_yaml.yml")
yml.to_yaml()Convert to yaml stringyml.to_dict()Convert to python dictionaryyml.yaml_dump(destination="my_yaml.yml")Write directly to yaml fileyml.pprint()Pretty print the dictionaryyml.walk()Iterate through all yaml objectsyml.walk_keys()Iterate through all yaml keys
🔄 Comparison to PyYaml
While PyYaml solves the purpose of converting to dictionary perfectly fine, it completely ignores anything non-dictionary-conversion related in the yaml file.
Input yaml
# Anchor definition
dev: &default_config
schedule: false
my_config: [1, 2, 3]
staging:
# Alias reference
<<: *default_config
schedule: true
Output
yamlium |
PyYaml |
|---|---|
| ✅ Retaining structure | ❌ Changing structure |
# Anchor definition
dev: &default_config
schedule: false
my_config: [1, 2, 3]
staging:
# Alias reference
<<: *default_config
schedule: true
|
dev:
my_config: &id001
- 1
- 2
- 3
schedule: false
staging:
my_config: *id001
schedule: true
|
🤝 Contributing
Contributions are welcome! Please feel free to submit Issues, Feature requests or Pull requests!
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yamlium-0.1.12.tar.gz.
File metadata
- Download URL: yamlium-0.1.12.tar.gz
- Upload date:
- Size: 63.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03578c643a752d238db474ec9a56e34fe532da82922b01bc82239bc271b08925
|
|
| MD5 |
c6f0d7e9dd5838c72d5c64f5abdafa0e
|
|
| BLAKE2b-256 |
5ef38a2d3188f18c499e508605a51c2ccec99c2f52d1de58db4f4538d2262f40
|
Provenance
The following attestation bundles were made for yamlium-0.1.12.tar.gz:
Publisher:
build_release.yml on erikmunkby/yamlium
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yamlium-0.1.12.tar.gz -
Subject digest:
03578c643a752d238db474ec9a56e34fe532da82922b01bc82239bc271b08925 - Sigstore transparency entry: 265306705
- Sigstore integration time:
-
Permalink:
erikmunkby/yamlium@1db3842d433bea055f677d68a4390ef2fccad06e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/erikmunkby
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_release.yml@1db3842d433bea055f677d68a4390ef2fccad06e -
Trigger Event:
push
-
Statement type:
File details
Details for the file yamlium-0.1.12-py3-none-any.whl.
File metadata
- Download URL: yamlium-0.1.12-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5572fb4391b4a79a50006792dba32e093faee3ac0670755ae9822c443cfa538
|
|
| MD5 |
4977451c918cb08f513bed1c7acb39d4
|
|
| BLAKE2b-256 |
51587c36691d20492985f35d3c5b73ed858b1783a93fe1130e2f1463c49522c0
|
Provenance
The following attestation bundles were made for yamlium-0.1.12-py3-none-any.whl:
Publisher:
build_release.yml on erikmunkby/yamlium
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yamlium-0.1.12-py3-none-any.whl -
Subject digest:
e5572fb4391b4a79a50006792dba32e093faee3ac0670755ae9822c443cfa538 - Sigstore transparency entry: 265306713
- Sigstore integration time:
-
Permalink:
erikmunkby/yamlium@1db3842d433bea055f677d68a4390ef2fccad06e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/erikmunkby
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_release.yml@1db3842d433bea055f677d68a4390ef2fccad06e -
Trigger Event:
push
-
Statement type: