Skip to main content

A PyYAML thin wrapper.

Project description

Yamlen - a Thin PyYAML Wrapper

CircleCI Codecov

Features

  • Contextual tag construction.

Examples

Create a Loader

>>> from yamlen import Loader
>>> loader = Loader()

Load YAML documents in Streams

>>> from io import StringIO

>>> stream = StringIO("foo")
>>> loader.load(stream)
'foo'

>>> stream = StringIO("foo\n---\nbar")
>>> list(loader.load_all(stream))
['foo', 'bar']

Load YAML Documents in Files.

>>> import os
>>> from tempfile import TemporaryDirectory

>>> with TemporaryDirectory() as dir_path:
...     path = os.path.join(dir_path, "example.yml")
...     with open(path, "w") as f:
...         _ = f.write("foo")
...     loader.load_from_path(path)
'foo'

>>> with TemporaryDirectory() as dir_path:
...     path = os.path.join(dir_path, "example.yml")
...     with open(path, "w") as f:
...         _ = f.write("foo\n---\nbar")
...     list(loader.load_all_from_path(path))
['foo', 'bar']

Contextual tag construction: include another YAML file.

>>> from yamlen.tag.impl.inclusion import InclusionTag
>>> loader.add_tag("!include", InclusionTag())

>>> with TemporaryDirectory() as dir_path:
...     foo_path = os.path.join(dir_path, "foo.yml")
...     bar_path = os.path.join(dir_path, "bar.yml")
...     with open(foo_path, "w") as f:
...         _ = f.write(f"!include ./bar.yml")
...     with open(bar_path, "w") as f:
...         _ = f.write("bar")
...     loader.load_from_path(foo_path)
'bar'

License

MIT License

Copyright (c) 2021 Yu Mochizuki

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yamlen-0.2.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

yamlen-0.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file yamlen-0.2.0.tar.gz.

File metadata

  • Download URL: yamlen-0.2.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.7.12 Linux/4.15.0-1110-aws

File hashes

Hashes for yamlen-0.2.0.tar.gz
Algorithm Hash digest
SHA256 39ffed8d817adb6a80d5e4ad3e87b2e4bb4952011ec67331594b5c2be21a3355
MD5 3ef258703dc28c0c27cc9971a31f068e
BLAKE2b-256 83f7d7278470d518366207c7c8cb934e45ae6e37840e8f33b55cbe422985b6e4

See more details on using hashes here.

File details

Details for the file yamlen-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: yamlen-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.7.12 Linux/4.15.0-1110-aws

File hashes

Hashes for yamlen-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 001f59e11b5bfeb6b816d89b92f7748d7407b015f2a0d53bb0148e27926f5fdd
MD5 f72c18c0da90bd42a55e0f88307bbd8b
BLAKE2b-256 edb8366931dbce869ff5ad52285dfc3a7fbad1a6ef512ce16a89dd687d2539bc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page