type-yaml
Describes a yaml schema using Python types.
Simple Python types such as list[str] or dict[int, list[str]] that allow yaml to verify that the type fits and parse values based on it.
Requirements
- Python 3.8+
- PyYAML
Install
pip install type-yaml
Features:
intfloatstrboollist/typing.Listdict/typing.Dictset/typing.Settuple/typing.Tupledataclass- default values and default-factory
- special notation in yaml with metadata
operator |/typing.Uniontyping.Any- lazy evaluation by string representation of type
Examples
from dataclasses import dataclass
from type_yaml import load
@dataclass
class Point:
x: int
y: int
print(load(list[Point], open("points.yaml")))
# >>> [Point(x=1, y=2), Point(x=3, y=4)]
# points.yaml
-
x: 1
y: 2
-
x: 3
y: 4
Usage
Functions such as load, loads, dump, and dumps can be imported from type_yaml. The details of each are as follows.
load(type, stream, **kwargs)- Load a yaml file and parse it into a Python object.
typeis a type that can be parsed by type_yaml.streamis a text stream. e.g.open("file.yaml")- options
loader: yaml loader of PyYAML. default:yaml.SafeLoadertrue_strings: list of strings that are parsed asTrue. default:("true", "yes", "on", "1")false_strings: list of strings that are parsed asFalse. default:("false", "no", "off", "0")type_name_map,globalns,localns: a dictionary or namespace of variable names is given to allow interpretation of the string representation of the type
loads(type, string, **kwargs)- Load a yaml string and parse it into a Python object.
typeis a type that can be parsed by type_yaml.stringis a yaml string.- options is same as
load
dump(value, stream, **kwargs)- Dump a Python object to a yaml file.
valueis a Python object that can be parsed by type_yaml.streamis a text stream. e.g.open("file.yaml")- options
dumper: yaml dumper of PyYAML. default: `type_yaml.yaml_interpreter.RealYamlDumper
dumps(value, **kwargs)- Dump a Python object to a yaml string.
valueis a Python object that can be parsed by type_yaml.- options is same as
dump
Other
The license is the MIT License.
If you have any bugs, mistakes, feature suggestions, etc., issues and pull requests are welcome.
Metadata
Release files for type-yaml 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| type_yaml-0.3.0.tar.gz | 9.3 kB | Without provenance | Details for type_yaml-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| type_yaml-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for type_yaml-0.3.0-py3-none-any.whl |
Total release size: 18.5 kB
Release files / type_yaml-0.3.0.tar.gz
| Download URL | type_yaml-0.3.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67c58ddf320d654e3d078dbd77b4fcd43a93c5d8b21941790fecee68afb044cd
|
|
BLAKE2b-256 checksum How to use checksums |
58b105d57c4376c6ee8b82fa7a8318f23b0920df11e120a411d48057ab2998ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.11.0rc2 Linux/5.15.0-67-generic
|
Release files / type_yaml-0.3.0-py3-none-any.whl
| Download URL | type_yaml-0.3.0-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d74c1c018e87f17934d4bc2d6997f472da34582fe44ea7efee4e011c13e7a6c
|
|
BLAKE2b-256 checksum How to use checksums |
44c4632fa5ad87ea94d534c2f4361ba4ef9ebd7314849b5429867503161377bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.11.0rc2 Linux/5.15.0-67-generic
|
Security for type-yaml 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.