ruamel.yaml.string
==================
:version: 0.1.1
:updated: 2023-05-02
This plug-in adds a method ``dump_to_string`` (and its equivalent ``dumps``)
to the ``ruamel.yaml.YAML`` instance that returns the document as
a Python ``string``.
Installation
============
The module can be installed from PyPI using::
pip install ruamel.yaml.string
This module is dependent on ``ruamel.yaml``, so you do not have to explicitly
make your module depending on both.
Usage
=====
.. code:: python
import ruamel.yaml
yaml = ruamel.yaml.YAML(typ=['rt', 'string'])
data = dict(abc=42, help=['on', 'its', 'way'])
print('retval', yaml.dump_to_string(data))
print('>>>> done')
which gives::
retval abc: 42
help:
- on
- its
- way
>>>> done
Please note that there is no final newline added to the string
that is returned. That the ``>>>> done`` is on the next line is caused by
the `print()` function adding a newline by default. (This is different
from using PyYAML's `dump`, as e.g. the output of various ``print dump(data)``
examples in the documentation (2021) fail to clearly show the double newline at the
end of the examples output. It is similar to `json.dumps(data, indent=2)` that returns
a string without final newline.)
Alternatively the
first call to ``print`` could be::
print('retval', yaml.dump_to_string(data, add_final_eol=True), end='')
with the same effect.
`.dump_to_string()` can be shortened to `.dumps()`
*Directly writing to ``sys.stdout`` using ``yaml.dump(data, sys.stdout)`` is
much more efficient than ``print``-ing the result of ``yaml.dumps(data)``*
ChangeLog
=========
0.1.1 (2023-05-02):
- typing added and readme corrections
0.1.0 (2022-03-17):
- initial plug-in version
Raw data
{
"_id": null,
"home_page": "https://sourceforge.net/p/ruamel-yaml-string/code/ci/default/tree",
"name": "ruamel.yaml.string",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3",
"maintainer_email": "",
"keywords": "yaml 1.2 dump python string",
"author": "Anthon van der Neut",
"author_email": "a.van.der.neut@ruamel.eu",
"download_url": "https://files.pythonhosted.org/packages/11/47/fa7c06b8f9946fc9192cb4d944367f31197715915f5e71363909e8c35eb7/ruamel.yaml.string-0.1.1.tar.gz",
"platform": null,
"description": "\nruamel.yaml.string\n==================\n\n:version: 0.1.1\n:updated: 2023-05-02\n\nThis plug-in adds a method ``dump_to_string`` (and its equivalent ``dumps``)\nto the ``ruamel.yaml.YAML`` instance that returns the document as\na Python ``string``.\n\nInstallation\n============\n\nThe module can be installed from PyPI using::\n\n pip install ruamel.yaml.string\n\nThis module is dependent on ``ruamel.yaml``, so you do not have to explicitly\nmake your module depending on both.\n\nUsage\n=====\n\n.. code:: python\n\n import ruamel.yaml\n\n yaml = ruamel.yaml.YAML(typ=['rt', 'string'])\n data = dict(abc=42, help=['on', 'its', 'way'])\n print('retval', yaml.dump_to_string(data))\n print('>>>> done')\n\nwhich gives::\n\n retval abc: 42\n help:\n - on\n - its\n - way\n >>>> done\n\n\nPlease note that there is no final newline added to the string\nthat is returned. That the ``>>>> done`` is on the next line is caused by\nthe `print()` function adding a newline by default. (This is different\nfrom using PyYAML's `dump`, as e.g. the output of various ``print dump(data)`` \nexamples in the documentation (2021) fail to clearly show the double newline at the\nend of the examples output. It is similar to `json.dumps(data, indent=2)` that returns\na string without final newline.)\n\nAlternatively the\nfirst call to ``print`` could be::\n\n print('retval', yaml.dump_to_string(data, add_final_eol=True), end='')\n\nwith the same effect.\n\n`.dump_to_string()` can be shortened to `.dumps()`\n\n*Directly writing to ``sys.stdout`` using ``yaml.dump(data, sys.stdout)`` is \nmuch more efficient than ``print``-ing the result of ``yaml.dumps(data)``*\n\n\nChangeLog\n=========\n\n0.1.1 (2023-05-02):\n - typing added and readme corrections\n\n0.1.0 (2022-03-17):\n - initial plug-in version\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "add dump_to_string/dumps method that returns YAML document as string",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://sourceforge.net/p/ruamel-yaml-string/code/ci/default/tree"
},
"split_keywords": [
"yaml",
"1.2",
"dump",
"python",
"string"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "912ab508237a7fcceab8a8724405480eb55d527523419c9dbcde369f954656ad",
"md5": "c1b04bd6924681de24222f8e95a9385f",
"sha256": "eb146bcb42b116216638034a434e9cf3ae2a5d3933aa37183a9854b5f3ff42de"
},
"downloads": -1,
"filename": "ruamel.yaml.string-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c1b04bd6924681de24222f8e95a9385f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3",
"size": 4118,
"upload_time": "2023-05-02T05:37:20",
"upload_time_iso_8601": "2023-05-02T05:37:20.332664Z",
"url": "https://files.pythonhosted.org/packages/91/2a/b508237a7fcceab8a8724405480eb55d527523419c9dbcde369f954656ad/ruamel.yaml.string-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1147fa7c06b8f9946fc9192cb4d944367f31197715915f5e71363909e8c35eb7",
"md5": "56185844e2a4dd803cd49da75489bf7d",
"sha256": "7a7aedcc055d45c004d38b756f58474ebefb106851f4ce56ce58415709784350"
},
"downloads": -1,
"filename": "ruamel.yaml.string-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "56185844e2a4dd803cd49da75489bf7d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3",
"size": 12678,
"upload_time": "2023-05-02T05:37:18",
"upload_time_iso_8601": "2023-05-02T05:37:18.085415Z",
"url": "https://files.pythonhosted.org/packages/11/47/fa7c06b8f9946fc9192cb4d944367f31197715915f5e71363909e8c35eb7/ruamel.yaml.string-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-02 05:37:18",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "ruamel.yaml.string"
}