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 add 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 toutf-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
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
msgspec_yaml-1.0.0.tar.gz
(1.6 kB
view details)
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 msgspec_yaml-1.0.0.tar.gz.
File metadata
- Download URL: msgspec_yaml-1.0.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91dc612ce6de5c6a30ed26f6902aa45c86f3526e1f4c08b21364a2ac00e2baea
|
|
| MD5 |
54927e106aa51fd16684de9428f0f34d
|
|
| BLAKE2b-256 |
2cd0d3e76ee14b454bbc8a30c7d74cd4470548c0355958c212bebae74fdff346
|
File details
Details for the file msgspec_yaml-1.0.0-py3-none-any.whl.
File metadata
- Download URL: msgspec_yaml-1.0.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c431f41264a7443631a7231560e9dd850083286b0998779bd9f3850ecb32269d
|
|
| MD5 |
5f3e150daa45dabec72f6401f6882abe
|
|
| BLAKE2b-256 |
47e251a4ff53bf782a7f00b33a500063f7f48184d0d2a8ee4567b08190083470
|