ruamel.yaml.split
This package provides a YAML document splitter, that allows you to iterate over a UTF-8 encoded file with YAML documents, and that returns each document, start linenumber and optionally loaded data.
Using this has the advantage over using load_all(), that you can skip individual documents that you know don’t load, or that you test/transform before proper loading. E.g. R markdown files have a YAML header followed by a non-YAML body (of course it would have been much better if in R markdown, the header had been followed by --- | instead of only a directory-end-marker (---), that way you could use any compliant YAML parser to load both)
You can use the following to get to each document:
from pathlib import Path
from ruamel.yaml.split import split
for doc, line_nr in split(Path('input.yaml')):
print(doc.decode('utf-8'), line_nr)
The line_nr indicates the starting line of the document and can be used as an offset for e.g. errors that are generated when parsing the document.
You can also provide a YAML() instance to get the document loaded for you:
import ruamel.yaml
for doc, data, line_nr in split(Path('input.yaml'), yaml=ruamel.yaml.YAML()):
print(doc.decode('utf-8'), data, line_nr)
the YAML() instance you provide is used to load all documents.
By default split() splits on the line-ending after the document-end-marker (...), so that any comment on the line of the document-end-marker is part of the document before it. Using some constants imported from ruamel.yaml.split that you provide to the the cmnt parameter of split(), you can influence where the comments “between” documents are split. C_PRE adds any such comments to the preceding document, C_POST to the following document. C_SPLIT_ON_FIRST_BLANK, splits after the first blank line and assigns to both.
from ruamel.yaml.split import C_SPLIT_ON_FIRST_BLANK
for doc, data, line_nr in split(Path('input.yaml'), cmnt=C_SPLIT_ON_FIRST_BLANK):
print(doc.decode('utf-8'), line_nr)
Comments at the end of the document stream are all attached to the last document, independent of the cmnt parameter.
Metadata
Release files for ruamel.yaml.split 0.2.2
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 |
|---|---|---|---|---|
| ruamel.yaml.split-0.2.2.tar.gz | 15.8 kB | Without provenance | Details for ruamel.yaml.split-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ruamel.yaml.split-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for ruamel.yaml.split-0.2.2-py3-none-any.whl |
Total release size: 22.9 kB
Release files / ruamel.yaml.split-0.2.2.tar.gz
| Download URL | ruamel.yaml.split-0.2.2.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f43f4acd04115e56bdb3e980ccfd22ae97d4a2a3a6c15f324c1945de9071b78
|
|
BLAKE2b-256 checksum How to use checksums |
ef86f44ccd893d2cafe46bd43b42779c46221c14681bfc68f96d71bb3fa69a69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.5
|
Release files / ruamel.yaml.split-0.2.2-py3-none-any.whl
| Download URL | ruamel.yaml.split-0.2.2-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e31b0ef8c5e63a19103cfc69637006ec48ad3e44b54f69645f510592625bd9a
|
|
BLAKE2b-256 checksum How to use checksums |
11a74fb76856405adee08a69ccfc22bc899eb065c39b856973172a554f9d83d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.5
|
Security for ruamel.yaml.split 0.2.2
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.