ConfigGraphViz 📊
Visualize the structure of your configuration files! ConfigGraphViz parses common config formats (INI, YAML, TOML) and generates Graphviz DOT language output, allowing you to create diagrams of your configuration hierarchy.
This helps understand complex configurations by showing sections, nested keys, lists, and values.
Features
- Parses INI (
.ini), YAML (.yaml,.yml), and TOML (.toml) files. - Generates Graphviz DOT language output (
.dotfile content). - Visualizes nested structures (dictionaries/sections, lists).
- Distinguishes sections, keys, lists, and values using different node shapes/colors (customizable via DOT attributes).
- Simple Python API.
- Requires Python 3.8+.
- Type Hinted.
Installation
Install from PyPI:
# Install required parsers too
pip install configgraphviz PyYAML "tomli; python_version < '3.11'"
Or install directly from GitHub:
# Make sure to install dependencies manually or via the repo's requirements
pip install git+https://github.com/manyan-chan/ConfigGraphViz.git
pip install PyYAML "tomli; python_version < '3.11'" # Install deps separately
For local development:
git clone https://github.com/manyan-chan/ConfigGraphViz.git
cd ConfigGraphViz
pip install -e .[test] # Installs PyYAML, tomli, pytest etc.
Note: You need Graphviz installed separately to render the generated .dot files into images (e.g., PNG, SVG). See Graphviz Download Page.
Usage
-
Import:
from configgraphviz import parse_config, build_dot_graph from pathlib import Path
-
Parse your configuration file:
config_file = "path/to/your/config.yaml" # Or .ini, .toml try: parsed_data = parse_config(config_file) print("Successfully parsed config.") except (FileNotFoundError, ValueError, ImportError) as e: print(f"Error parsing config: {e}") exit()
-
Generate the DOT graph string:
graph_name = Path(config_file).stem # Use filename as graph name dot_string = build_dot_graph(parsed_data, graph_name=graph_name) print("\nGenerated DOT output:") print(dot_string)
-
Save and Render (using Graphviz):
output_dot_file = f"{graph_name}.dot" output_image_file = f"{graph_name}.png" # Or .svg, .pdf, etc. with open(output_dot_file, "w", encoding="utf-8") as f: f.write(dot_string) print(f"\nDOT graph saved to {output_dot_file}") # Optional: Use subprocess to call Graphviz's 'dot' command import subprocess import shutil if shutil.which("dot"): # Check if 'dot' command exists try: subprocess.run(["dot", "-Tpng", output_dot_file, "-o", output_image_file], check=True) print(f"Rendered graph image saved to {output_image_file}") except (subprocess.CalledProcessError, FileNotFoundError) as e: print(f"\nFailed to render graph using 'dot' command: {e}") print("Please ensure Graphviz is installed and in your system's PATH.") else: print("\nGraphviz 'dot' command not found.") print(f"You can render the DOT file manually: dot -Tpng {output_dot_file} -o {output_image_file}")
Example Output
Given a simple YAML file (example.yaml):
server:
host: "192.168.1.100"
port: 8080
retry_options:
attempts: 3
delay: 5
database:
type: postgresql
connection: "..."
pool_size: 10
users:
- name: alice
role: admin
- name: bob
role: user
Running the script will produce a .dot file. Rendering example.yaml.dot with dot -Tpng example.yaml.dot -o example.yaml.png produces the actual graph image using Graphviz.
The following Mermaid diagram illustrates the concept of the generated structure (Note: This is Mermaid syntax for demonstration in Markdown, not the DOT output itself. Actual layout by Graphviz may differ):
graph LR
root("(root)") --> server("server\n(section)");
root --> database("database\n(section)");
root --> users("users\n(list)");
server --> server_host("host: '192.168.1.100'");
server --> server_port("port: 8080");
server --> server_retry("retry_options\n(section)");
server_retry --> server_retry_attempts("attempts: 3");
server_retry --> server_retry_delay("delay: 5");
database --> database_type("type: 'postgresql'");
database --> database_connection("connection: '...'");
database --> database_pool("pool_size: 10");
users --> users_0("0\n(item)");
users --> users_1("1\n(item)");
users_0 --> users_0_name("name: 'alice'");
users_0 --> users_0_role("role: 'admin'");
users_1 --> users_1_name("name: 'bob'");
users_1 --> users_1_role("role: 'user'");
Testing
Uses pytest. Install test dependencies (pip install -e .[test]) and run:
pytest
Contributing
Contributions welcome! Please submit issues or PRs on GitHub.
License
MIT License - see LICENSE file.
Release files for configgraphviz 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| configgraphviz-0.1.1.tar.gz | 12.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| configgraphviz-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.7 kB
Release files / configgraphviz-0.1.1.tar.gz
| Download URL | configgraphviz-0.1.1.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92e56270717d3ae206b522d967e6288e344fa6c7a32623e28b2b0e18c9a010e4
|
|
BLAKE2b-256 checksum How to use checksums |
31d826d77c853116caeb1121d87061607da726cf59a29ed68f228841f6eb19e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2025.
Transparency logRelease files / configgraphviz-0.1.1-py3-none-any.whl
| Download URL | configgraphviz-0.1.1-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8efb942dcc9f96ed8e90bbaaaa0e3ee9aa0f3634bd98ba9d25f6e793b94e22b0
|
|
BLAKE2b-256 checksum How to use checksums |
565ba20804da2cfad2007d113cec80952bb47eee279104548cc9f63d46c9e3ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2025.
Transparency log