Package: yaml2dot
Yaml2DotPython implementation of a yaml2dot converter. Now with JSON Support and enhcanched node customization!Check out a demo at my personal pageteamayejay.com/Adrian/Yaml2Dot.Inspried by the originalyml2dot.The YAML to DOT Converter is a Python utility designed to transform YAML or JSON data into a visual graph representation, available in either the DOT (Graph Description Language) or JSON format. This tool employs NetworkX to construct the graph structure and offers the flexibility to produce either DOT files or JSON output in the form of node-link data.Transform this data:person:name:Aliceage:28address:street:456 Elm Stcity:Another Townzip:'54321'hobbies:-reading-hikinginto this easy to read graph(after rendering using d3-graphviz):Table of ContentsGetting StartedPrerequisitesInstallationUsageCLI OPTIONSExamplesSample YAML FilesSample JSON FileRendering ExampleDevelopmentContributingInstallTestingLicenseGetting StartedPrerequisitesBefore using the YAML to DOT Converter, ensure you have the following dependencies installed:Python 3.10(officially tested)NetworkXPyDotClickInstallationThe most straightforward way to install is to use pip:pipinstallyaml2dotFor a manual install you can setup a virtual environment and do the following:pipinstallnetworkxpydotclickor clone the repository and navigate to the project directory:pipinstall.UsageTo convert a YAML/JSON file to a DOT file, use the following command:yaml2dot--input-fileINPUT_FILE--output-fileOUTPUT_FILE[--rankdirRANKDIR][--output-formatOUTPUT_FORMAT][--multi-view][--round-robin][--shapeSHAPE]INPUT_FILE: Path to the input YAML/JSON file.OUTPUT_FILE: Path to the output DOT file.RANKDIR (optional): Rank direction (LR for left to right, TB for top to bottom). Default is LR.MULTI-VIEW (optional): Enable alternative graph view for multiple YAML documents.ROUND-ROBIN (optional): Enable round-robin node style selection. If not specified, defaults the rounded shape.SHAPE (optional): User-defined node shape, applicable when round-robin is not used. SeeGraphviz Shapesfor supported shapes.Example usage for conerting to DOT:yaml2dot--input-fileinput.yaml--output-fileoutput.dot--rankdirLRExample usage for converting for node link data JSON:yaml2dot --input-file input.json --output-file output.json --output-format jsonHere's an example of how to use the library's API to convert YAML or JSON data:fromyaml2dotimportdata_loader,converter# Load YAML or JSON data from a filedata=data_loader.load_yaml_or_json('input.yaml')# or input a python dict directly# data = {"example":"example"}# Convert the data to DOT format (default)dot_output=converter.convert_yaml_or_json_to_format(data)# Convert the data to JSON formatjson_output=converter.convert_yaml_or_json_to_format(data,output_format='json')# Print or save the outputs as neededprint(dot_output)print(json_output)CLI OptionsThe yaml2dot command offers various options to customize the graph rendering:--round-robin: Automatically assigns different node shapes in a round-robin fashion for each YAML document.--shape: Specify a custom shape for nodes. This option is ignored if --round-robin is used.--multi-view: Useful for rendering multiple YAML documents in a single file with distinct node styles. Disables round-robin.ExamplesSample YAML/JSON FilesTheexamplesdirectory contains several sample YAML files that you can use for testing and experimentation. These files cover various YAML structures and complexities. It also contain an example json file for testing and experimentation.Rendering ExampleTo render a sample YAML/JSON file, use the following command:yaml2dot--input-fileexamples/small_graph.yaml--output-filesmall_graph.dot--rankdirLR--shapediamondThis will generate a DOT file that can be visualized using Graphviz or other compatible tools.To render to JSON format:yaml2dot--input-fileexamples/small_graph.yaml--output-filesmall_graph.json--rankdirLR--output-formatjsonThis will generate a node link data JSON file of the networkx graph that can be visualzied usingd3.For a round-robin node style in multi-document YAMLS:yaml2dot--input-fileexamples/multi_document.yaml--output-filemulti_document.dot--rankdirLR--multi-view--round-robinDevelopmentContributingContributions are welcome! I don't have any formal contributing guidelines but since this is a fairly small project, feel free to send an informal message.Dev InstallThe fastest way to start developing is to clone the repository and run the following command:pipinstall'.[all]'TestingSimply run:pytestLicenseThis project is licensed under the MIT License. See the LICENSE file for details.