Skip to main content

YAMLStar Python Bindings

Python bindings for YAMLStar - a pure YAML 1.2 loader implemented in Clojure.

Features

  • YAML 1.2 Spec Compliance: 100% compliant with YAML 1.2 core schema
  • Pure Implementation: No dependencies on SnakeYAML or other external parsers
  • Fast Native Performance: Uses the native YAMLStar shared library
  • Simple API: Load YAML documents with a single function call
  • Multi-Document Support: Load multiple YAML documents from a single string

Installation

Prerequisites

First, build and install the shared library:

cd ../libyamlstar
make native
sudo make install PREFIX=/usr/local

Or install to user-local directory:

cd ../libyamlstar
make native
make install PREFIX=~/.local

Install Python Package

pip install .

For development:

pip install -e .

Quick Start

import yamlstar

# Create a YAMLStar instance
ys = yamlstar.YAMLStar()

# Load a simple YAML string
data = ys.load("key: value")
print(data)  # {'key': 'value'}

# Load with a parser plugin (see https://yamlstar.org/plugins/)
opts = yamlstar.Options().plugin(yamlstar.parser('snakeyaml'))
ys = yamlstar.YAMLStar(opts, so='libyamlstar-graalvm')
data = ys.load("key: value")

Usage Examples

Basic Types

import yamlstar

ys = yamlstar.YAMLStar()

# Strings
ys.load("hello")  # 'hello'

# Integers
ys.load("42")  # 42

# Floats
ys.load("3.14")  # 3.14

# Booleans
ys.load("true")   # True
ys.load("false")  # False

# Null
ys.load("null")  # None

Collections

# Mappings (dictionaries)
data = ys.load("""
name: Alice
age: 30
city: Seattle
""")
# {'name': 'Alice', 'age': 30, 'city': 'Seattle'}

# Sequences (lists)
data = ys.load("""
- apple
- banana
- orange
""")
# ['apple', 'banana', 'orange']

# Flow style
data = ys.load("[a, b, c]")
# ['a', 'b', 'c']

Nested Structures

data = ys.load("""
person:
  name: Alice
  age: 30
  hobbies:
    - reading
    - coding
    - hiking
""")
# {
#   'person': {
#     'name': 'Alice',
#     'age': 30,
#     'hobbies': ['reading', 'coding', 'hiking']
#   }
# }

Multi-Document YAML

# Load all documents from a multi-document YAML string
docs = ys.load_all("""---
name: Document 1
---
name: Document 2
---
name: Document 3
""")
# [
#   {'name': 'Document 1'},
#   {'name': 'Document 2'},
#   {'name': 'Document 3'}
# ]

Type Coercion

YAMLStar follows YAML 1.2 core schema type inference:

data = ys.load("""
string: hello
integer: 42
float: 3.14
bool_true: true
bool_false: false
null_value: null
""")
# {
#   'string': 'hello',
#   'integer': 42,
#   'float': 3.14,
#   'bool_true': True,
#   'bool_false': False,
#   'null_value': None
# }

Error Handling

try:
    data = ys.load("invalid: yaml: syntax")
except Exception as e:
    print(f"Error loading YAML: {e}")

Version Information

# Get YAMLStar version
version = ys.version()
print(f"YAMLStar version: {version}")

API Reference

YAMLStar Class

__init__()

Create a new YAMLStar instance. Each instance maintains its own native-library lifecycle handle.

ys = yamlstar.YAMLStar()

load(yaml_input)

Load a single YAML document.

Parameters:

  • yaml_input (str): String containing YAML content

Returns:

  • Python object representing the YAML document (dict, list, str, int, float, bool, or None)

Raises:

  • Exception if the YAML is malformed

Example:

data = ys.load("key: value")

load_all(yaml_input)

Load all YAML documents from a multi-document string.

Parameters:

  • yaml_input (str): String containing one or more YAML documents

Returns:

  • List of Python objects, one per YAML document

Raises:

  • Exception if the YAML is malformed

Example:

docs = ys.load_all("---\ndoc1\n---\ndoc2")

version()

Get the YAMLStar version string.

Returns:

  • str: Version string

Example:

version = ys.version()

Development

Running Tests

# Run all tests
make test

# Run only pytest tests
make test-pytest

# Run only FFI tests
make test-ffi

Building Distribution

# Build source distribution
make dist

# Build and install in development mode
make install

Requirements

  • Python: 3.6 or higher
  • libyamlstar: Shared library (installed separately)
  • System: Linux or macOS

Library Search Path

The package searches for libyamlstar.so (or .dylib on macOS) in:

  1. Development path (relative to package)
  2. Directories in LD_LIBRARY_PATH environment variable
  3. /usr/local/lib (default install location)
  4. ~/.local/lib (user-local install location)

Comparison to PyYAML

Feature YAMLStar PyYAML
YAML Version 1.2 1.1
Implementation Pure Clojure C + Python
Type Inference YAML 1.2 core schema YAML 1.1 + custom
Native Performance Yes (Gloat/Glojure) Yes (C extension)
Dependencies libyamlstar.so None

License

MIT License - See License file

Credits

Created by Ingy döt Net, inventor of YAML.

YAMLStar is built on the YAML Reference Parser (pure Clojure implementation).

Links

Download files

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

Source Distribution

yamlstar-0.1.19.tar.gz (7.4 kB view details)

Uploaded Source

Built Distributions

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

yamlstar-0.1.19-py3-none-win_amd64.whl (14.1 MB view details)

Uploaded Python 3Windows x86-64

yamlstar-0.1.19-py3-none-manylinux_2_31_x86_64.whl (28.6 MB view details)

Uploaded Python 3manylinux: glibc 2.31+ x86-64

yamlstar-0.1.19-py3-none-macosx_15_0_x86_64.whl (27.6 MB view details)

Uploaded Python 3macOS 15.0+ x86-64

yamlstar-0.1.19-py3-none-macosx_14_0_arm64.whl (24.8 MB view details)

Uploaded Python 3macOS 14.0+ ARM64

File details

Details for the file yamlstar-0.1.19.tar.gz.

File metadata

  • Download URL: yamlstar-0.1.19.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for yamlstar-0.1.19.tar.gz
Algorithm Hash digest
SHA256 92886c8b77bb8582d23ed8998fc1d61e40a5f2b3a4aa558ad4d4c36206bd8a49
MD5 d025a1304fc528eccbc88767e2cf552b
BLAKE2b-256 3eaec92b6c4462dd70f88b534bf36d17eae5526c1d5dfad7ce8bee69b1a839e4

See more details on using hashes here.

File details

Details for the file yamlstar-0.1.19-py3-none-win_amd64.whl.

File metadata

  • Download URL: yamlstar-0.1.19-py3-none-win_amd64.whl
  • Upload date:
  • Size: 14.1 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for yamlstar-0.1.19-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 7b6316afd13dd6f84b1dd8ccacfa49de03e2e45bb30e81d0741203fe74d534bf
MD5 574d31ba2d975edd61db0fde440d02c4
BLAKE2b-256 87a2d4146ddab5e34faae11da1fe222779a7ec0d0a0383ee93abc8c0ec08ee0e

See more details on using hashes here.

File details

Details for the file yamlstar-0.1.19-py3-none-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for yamlstar-0.1.19-py3-none-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 0ece5bc37fb1e0291a7c29d7ce4d726edfe499edb87c0fc1877f694f2a484d36
MD5 478e7412a4cea3604cb4616a552aa962
BLAKE2b-256 ff3bb5a505c48ca6db826cef2ac400cf74a751857d2b9a385ef04bd75f552bb0

See more details on using hashes here.

File details

Details for the file yamlstar-0.1.19-py3-none-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for yamlstar-0.1.19-py3-none-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 9dfff446d7abfa0e79d56edabff6c5e68fd0105555206eb06f960456663bdb39
MD5 2a646fcb94162633d815603d5fc9a538
BLAKE2b-256 a30450c0f84b94a349aec397ea5dec2539b33ac8c14f7f8eb6901b0152326dce

See more details on using hashes here.

File details

Details for the file yamlstar-0.1.19-py3-none-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for yamlstar-0.1.19-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 68d99c164eaf77bb5c8ca385d97ca92c98a3f848577e29dd41a386b51064d95c
MD5 5f59247dfc9b43bcb1a8f267f0f2239c
BLAKE2b-256 cbbfad175371739840a78b33ea39537963ddacdbc50b16849a419f8dc5ef12b7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.19 This release

5 files

0.1.18

5 files

0.1.17

4 files

0.1.15

4 files

0.1.14

4 files

0.1.12

4 files

0.1.11

4 files

0.1.9

4 files

0.1.8

4 files

0.1.7

4 files

0.1.6

3 files

0.1.5

3 files

0.1.4

3 files

0.1.3

1 file

0.1.2

1 file

0.1.0

1 file

0.0.1

1 file

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