安全地读写可读的YAML,保留顺序并避免不想要的类型推断带来的意外。这个库是PyYaml的包装器,具有合理的读写行为,通常用于配置。
项目描述
这个微库是PyYaml的包装器,具有合理的读写行为,用于安全地读写可读的YAML,通常与配置文件一起使用。
使用saneyaml,您可以导出可读且整洁的YAML,并安全地加载任何YAML,通过将除布尔值以外的所有内容加载为字符串来保持顺序并避免类型转换的意外。
在加载YAML时,您可以可选地检查重复的映射键。
兼容Python 3。需要PyYAML 5.x或更高版本。
许可证:apache-2.0 网站主页:https://github.com/aboutcode-org/saneyaml
用法
pip install saneyaml
>>> from saneyaml import load
>>> from saneyaml import dump
>>> a=load('''version: 3.0.0.dev6
...
... description: |
... AboutCode Toolkit is a tool to process ABOUT files. An ABOUT file
... provides a way to document a software component.
... ''')
>>> a
dict([
(u'version', u'3.0.0.dev6'),
(u'description', u'AboutCode Toolkit is a tool to process ABOUT files. '
'An ABOUT file\nprovides a way to document a software component.\n')])
>>> pprint(a.items())
[(u'version', u'3.0.0.dev6'),
(u'description',
u'AboutCode Toolkit is a tool to process ABOUT files. An ABOUT file\nprovides a way to document a software component.\n')]
>>> print(dump(a))
version: 3.0.0.dev6
description: |
AboutCode Toolkit is a tool to process ABOUT files. An ABOUT file
provides a way to document a software component.
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分发
saneyaml-0.6.1.tar.gz (82.2 kB 查看哈希值)
构建分发
saneyaml-0.6.1-py3-none-any.whl (13.1 kB 查看哈希值)