Skip to main content

Simple YAML loader for msgspec.Struct

Reason this release was yanked:

Invalid README.md

Project description

msgspec-yaml

Simple YAML loader for msgspec.Struct.

Installation

uv

uv add msgspec-yaml

pip

pip install msgspec-yaml

poetry

poetry install msgspec-yaml

Usage

import msgspec

import msgspec_yaml


class Config(msgspec.Struct):
    host: str
    port: int


config = msgspec_yaml.load("config.yml", Config)

print(config.host)
print(config.port)

Example YAML file:

host: localhost
port: 8000

API

msgspec_yaml.load(path, struct, encoding="utf-8")

Load a YAML file and convert its contents into a msgspec.Struct.

Parameters

  • path (str | pathlib.Path) — path to the YAML file.
  • struct (type[msgspec.Struct]) — target structure class.
  • encoding (str) — file encoding. Defaults to utf-8.

Returns

An instance of the provided msgspec.Struct.

Raises

  • FileNotFoundError — file does not exist.
  • yaml.YAMLError — invalid YAML file or unsupported file extension.
  • msgspec.ValidationError — data validation failed during conversion.

Why?

Instead of writing:

with open("config.yml") as f:
    data = yaml.safe_load(f)

config = msgspec.convert(data, type=Config)

you can simply write:

config = load("config.yml", Config)

Project details


Download files

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

Source Distribution

msgspec_yaml-1.0.1.tar.gz (1.6 kB view details)

Uploaded Source

Built Distribution

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

msgspec_yaml-1.0.1-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

Details for the file msgspec_yaml-1.0.1.tar.gz.

File metadata

  • Download URL: msgspec_yaml-1.0.1.tar.gz
  • Upload date:
  • Size: 1.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for msgspec_yaml-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3c8650edcc2299da6ada92e428996bffc1c2157ea08fb4c0c670a54edcb971b6
MD5 941890ea3e6908ff7267752ffc93feca
BLAKE2b-256 38f0ce255d43b20be81f6e0ac7f713a7b4771e9d157f5204c304c22795ce773c

See more details on using hashes here.

File details

Details for the file msgspec_yaml-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: msgspec_yaml-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for msgspec_yaml-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0fe5222139473470d98d6603568fa1c48aa82db767f051ede1efbbdd095342bc
MD5 3dc441024960b886a45425aac7bf7960
BLAKE2b-256 31d99a3563483a446ea2e4b3686fdb4a81138021f13c5fc06ff9c3945c3cadeb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page