Simple YAML loader for msgspec.Struct
Project description
msgspec-yaml
Simple YAML loader for msgspec.Struct.
Installation
uv
uv add msgspec-yaml
pip
pip install msgspec-yaml
poetry
poetry 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:
import msgspec
import yaml
class Config:
host: str
port: int
with open("config.yml") as f:
data = yaml.safe_load(f)
config = msgspec.convert(data, type=Config)
you can simply write:
import msgspec_yaml
class Config:
host: str
port: int
config = msgspec_yaml.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.2.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.2.tar.gz.
File metadata
- Download URL: msgspec_yaml-1.0.2.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 |
fec139b7ee2f64e13b044a77b7f521f718d37ddb4e4e3b743a6a3096b04f997b
|
|
| MD5 |
4693f9d228b582d6a9791aa11e576618
|
|
| BLAKE2b-256 |
7b63ebc4307f0a190291e057e2d86efbea26af940bf687b92b3773d10f75dc0f
|
File details
Details for the file msgspec_yaml-1.0.2-py3-none-any.whl.
File metadata
- Download URL: msgspec_yaml-1.0.2-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 |
5ee4de313e8d140a12c916fa87f68ea4be8eba7de9a5b4cf858b5ceacf5733e5
|
|
| MD5 |
cbe2acc561a8a5883f1f815e8d4d908c
|
|
| BLAKE2b-256 |
dc1bc31885f280301fc99dda411d1a1b99860f0f72c5f864d7aa013a2a9afa60
|