Fast Representation Graph for PyYAML using NetworkX.
import yaml
from nx_yaml import NxSafeDumper, NxSafeLoader
data_in = yaml.load("yaml: great", Loader=NxSafeLoader)
data_out = yaml.dump(data_in, Dumper=NxSafeDumper)
print(data_out)
import networkx as nx
import matplotlib.pyplot as plt
data_out = yaml.compose("[nx, also great]", Loader=NxSafeLoader)
nx.draw_spectral(data_out, with_labels=True, node_size=5000)
plt.show()
This library offers four implementations that jointly bypass the pyyaml.nodes library. This is transparent when you use load
and dump
since the representation graph is an implementation detail. This library will be faster thanks to a better graph implementation.
Users of graphs who use the compose
and represent
will now get NetworkX objects. NX is a fully fledged library compared to the barebones yaml.nodes
module.
With nx_yaml
NetworkX becomes your native representation graph using YAML. There is no need to convert between the yaml.nodes.Node
and nx.DiGraph
by hand.
See:
Four abstraction isolate and replace pyyaml.nodes representation graph implementation:
NxComposer
: https://github.com/yaml/pyyaml/blob/main/lib/yaml/composer.py
NxConstructor
: https://github.com/yaml/pyyaml/blob/main/lib/yaml/constructor.py
NxRepresenter
: https://github.com/yaml/pyyaml/blob/main/lib/yaml/representer.py
NxSerializer
: https://github.com/yaml/pyyaml/blob/main/lib/yaml/serializer.py
nodes
with NetworkXThis is work in progress.
pypi
is updated on demand.
The development environment is self-contained using the pipenv
tool.
pytest
resources/tests