Install
pip install ez_yaml
Usage
import ez_yaml
# to_string(obj, settings={})
ez_yaml.to_string({"thing": 1, "abc": [ 1,2,3 ]})
# to_object(file_path, settings={})
# to_object(string , settings={})
ez_yaml.to_object(string='''
thing: 1
abc:
- 1
- 2
- 3
''')
# to_file(obj, file_path, settings={})
ez_yaml.to_file(
{"thing": 1, "abc": [ 1,2,3 ]},
file_path="./my_file.yaml",
)
Settings
import ez_yaml
# to_string(obj, settings={})
ez_yaml.to_string(
{"thing": 1, "abc": [ 1,2,3 ]},
settings=dict(
# these are the default values
safe=False,
width=None,
allow_duplicate_keys=True,
explicit_start=False,
explicit_end=False,
explict_null=True,
indent_mapping=3,
indent_sequence=2,
offset=0,
)
)
# to_file(obj, file_path, settings={})
ez_yaml.to_file(
{"thing": 1, "abc": [ 1,2,3 ]},
file_path="./my_file.yaml",
settings=dict(
width=9999999999999,
explicit_start=True,
explicit_end=True,
)
)
Custom Yaml Tags Example
from ez_yaml import yaml
@yaml.register_class
class YourCustomClass:
yaml_tag = "!python/YourCustomClass"
def __init__(self, something):
self.something = something
@classmethod
def from_yaml(cls, constructor, node):
# will print true
print(node.value.startswith("blah blah YourCustomClass(something:"))
# node.value is the python-value
return YourCustomClass(something=node.value[len("blah blah YourCustomClass(something:")-1:-1])
@classmethod
def to_yaml(cls, representer, object_of_this_class):
representation = f"blah blah YourCustomClass(something:{object_of_this_class.something})"
# ^ needs to be a string (or some other yaml-primitive)
return representer.represent_scalar(
tag=cls.yaml_tag,
value=representation,
style=None,
anchor=None
)
data = [
YourCustomClass(['blah blah blah']),
YourCustomClass({"thing": "lorem ipsum"}),
]
# will get generated with a tag
output = ez_yaml.to_string(data)
# will detect tag and convert it back to a YourCustomClass
yaml.load(output)
Metadata
Release files for ez-yaml 2.2.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 |
|---|---|---|---|---|
| ez_yaml-2.2.0.tar.gz | 381.9 kB | Without provenance | Details for ez_yaml-2.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ez_yaml-2.2.0-py3-none-any.whl | Python 3 | none | any | Details for ez_yaml-2.2.0-py3-none-any.whl |
Total release size: 728.8 kB
Release files / ez_yaml-2.2.0.tar.gz
| Download URL | ez_yaml-2.2.0.tar.gz |
|---|---|
| Size | 381.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa02f14683cd4a32a1be621c5acabe587ddf0e647fef7e075b3c942db722d331
|
|
BLAKE2b-256 checksum How to use checksums |
2f5cbc0e52d9ea94a90d63645dc4df2724ad212ef918f3c89101dff78a4f8ed1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.8.3 pkginfo/1.9.6 requests/2.27.1 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.8.13
|
Release files / ez_yaml-2.2.0-py3-none-any.whl
| Download URL | ez_yaml-2.2.0-py3-none-any.whl |
|---|---|
| Size | 347.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb1fa5734c7ce948ba146d9efab0d5017a94f1e0eeb2a112d40b62df30468de2
|
|
BLAKE2b-256 checksum How to use checksums |
a6f8c7b927a739a658b6d574deabcd0eb293454c5218a3c0208595c98453f12e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.8.3 pkginfo/1.9.6 requests/2.27.1 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.8.13
|
Security for ez-yaml 2.2.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.