Skip to main content

Node tree implementation for yaml files

Project description

Latest PyPI version Number of PyPI downloads Test node.ext.yaml

node.ext.yaml provides a node implementation to yaml files.

For more information on nodes see node package.

For more information on plumbing see plumber package.

Usage

Create a yaml file:

from node.ext.yaml import YamlFile

class MyYamlFile(YamlFile):

    @property
    def fs_path(self):
        return '/path/to/file.yaml'

file = MyYamlFile()
file['child'] = 'Value'

# write file to disk
file()

Define factories for child nodes:

from node.ext.yaml import YamlNode

class SpecificChild(YamlNode):
    pass

class DefaultChild(YamlNode):
    pass

class MyYamlFile(YamlFile):
    factories = {
        'child': SpecificChild,
        '*': DefaultChild
    }

Define a schema for node members:

from node import schema
from node.behaviors import SchemaAsAttributes
from plumber import plumbing

@plumbing(SchemaAsAttributes)
class MyYamlFile(YamlFile):
    schema = {
        'int_member': schema.Int(),
        'str_member': schema.Str()
    }

file = MyYamlFile()
file.attr['int_member'] = 1
file.attr['str_member'] = u'String'

Schema members can be defined directly on class.

Note: Be careful not to override existing API members.

from node.behaviors import SchemaProperties

@plumbing(SchemaProperties)
class MyYamlFile(YamlFile):
    int_member = schema.Int()
    str_member = schema.Str()

file = MyYamlFile()
file.int_member = 1
file.str_member = u'String'

Python Versions

  • Python 2.7, 3.3+

Contributors

  • Robert Niederreiter

Changes

2.0.0 (2026-02-03)

  • Refactor package layout to use pyproject.toml and implicit namespace packages. [rnix]

0.4 (2025-10-25)

  • Pin upper versions of dependencies. [rnix]

0.3 (2022-12-21)

  • node.ext.yaml.behaviors.YamlSequenceStorage implements now __contains__, which compares the storage values directly. This is needed to make containment checks work because yaml child nodes are not cached on __getitem__. [rnix]

  • node.ext.yaml.behaviors.YamlMember provides now default_mapping_factory and default_sequence_factory settings. [rnix]

  • node.ext.yaml.behaviors.YamlMember inherits from node.behaviors.WildcardFactory now. [rnix]

  • Use node.behaviors.SequenceAdopt and node.behaviors.SequenceOrder behaviors on node.ext.yaml.YamlSequence. [rnix]

  • Use node.behaviors.MappingOrder behavior in favor of node.behaviors.Order as introduced in node 1.2 on node.ext.yaml.YamlMapping and node.ext.yaml.YamlFile. [rnix]

0.2 (2022-10-06)

  • Inherit YamlRootStorage from node.ext.fs.FSLocation, which provides fs_path property. Note that fs_path is handled as list now. [rnix]

  • Inherit IYamlRoot from node.ext.fs.interfaces.IFile. [rnix]

  • Package depends on node.ext.fs now. [rnix]

  • Replace deprecated use of Adopt by MappingAdopt. [rnix]

  • node.ext.yaml.YamlNode and node.ext.yaml.YamlFile not provides a default child factory any more. [rnix]

0.1 (2021-11-22)

  • Initial work [rnix]

License

Copyright (c) 2021-2025, Node Contributors All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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

node_ext_yaml-2.0.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

node_ext_yaml-2.0.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file node_ext_yaml-2.0.0.tar.gz.

File metadata

  • Download URL: node_ext_yaml-2.0.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for node_ext_yaml-2.0.0.tar.gz
Algorithm Hash digest
SHA256 cef382f388b0acc2f420f5b05fd82d097fe5ada3b3e79cca5ccb0104f1df9c66
MD5 ab2a65c4df2804357f2f173f2f5736ce
BLAKE2b-256 b916fe0b0ce3cc7409b41b800d1d8e80bff8f2edde920196ee42d2abad475462

See more details on using hashes here.

File details

Details for the file node_ext_yaml-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: node_ext_yaml-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for node_ext_yaml-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d74bc5da4edc934c393afe652241161c9267bf92d11b1528c6f5ea211ec51baf
MD5 d3e9a5fa93bb46033c9d570ba299c27b
BLAKE2b-256 eeddb424d43e98735c01af932f6bed8e7e1eac95dac64dd3795440bb36672374

See more details on using hashes here.

Supported by

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