Skip to main content

Generate Graphviz DOT visualizations from INI, YAML, and TOML configuration files.

Project description

ConfigGraphViz 📊

PyPI version CI Status License: MIT Python Versions Example Graph

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 (.dot file 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

  1. Import:

    from configgraphviz import parse_config, build_dot_graph
    from pathlib import Path
    
  2. 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()
    
  3. 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)
    
  4. 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.dot with dot -Tpng example.dot -o example.png might produce an image similar to this concept (actual layout depends on Graphviz):

graph LR
    root["root"] --&gt; server["server\n(section)"];
    root --&gt; database["database\n(section)"];
    root --&gt; users["users\n(list)"];

    server --&gt; server_host["host: '192.168.1.100'"];
    server --&gt; server_port["port: 8080"];
    server --&gt; server_retry["retry_options\n(section)"];
    server_retry --&gt; server_retry_attempts["attempts: 3"];
    server_retry --&gt; server_retry_delay["delay: 5"];

    database --&gt; database_type["type: 'postgresql'"];
    database --&gt; database_connection["connection: '...'"];
    database --&gt; database_pool["pool_size: 10"];

    users --&gt; users_0["0\n(item)"];
    users --&gt; users_1["1\n(item)"];
    users_0 --&gt; users_0_name["name: 'alice'"];
    users_0 --&gt; users_0_role["role: 'admin'"];
    users_1 --&gt; users_1_name["name: 'bob'"];
    users_1 --&gt; users_1_role["role: 'user'"];

    style root fill:#lightblue,stroke:#333,stroke-width:2px
    style server fill:#lightblue,stroke:#333,stroke-width:2px
    style server_retry fill:#lightblue,stroke:#333,stroke-width:2px
    style database fill:#lightblue,stroke:#333,stroke-width:2px
    style users fill:#lightgrey,stroke:#333,stroke-width:2px
    style users_0 fill:#lightgrey,stroke:#333,stroke-width:2px
    style users_1 fill:#lightgrey,stroke:#333,stroke-width:2px

(Note: Mermaid diagram used here for conceptual illustration. Actual output is DOT language for Graphviz.)

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.

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

configgraphviz-0.1.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

configgraphviz-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file configgraphviz-0.1.0.tar.gz.

File metadata

  • Download URL: configgraphviz-0.1.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for configgraphviz-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b3200435c9f7fbf0f842b023fe521639160aff35e5b45fd69c1eaa6c7bc517f6
MD5 edbe57357277ab88cdd272e48f508f7f
BLAKE2b-256 7033e2ea6dff5dd9346bb7cc1524e3b2b1d2400337de7d066c031b2f6a420831

See more details on using hashes here.

Provenance

The following attestation bundles were made for configgraphviz-0.1.0.tar.gz:

Publisher: python-package.yml on manyan-chan/ConfigGraphViz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file configgraphviz-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: configgraphviz-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for configgraphviz-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 881f21fec6746a6f0ebe6cbd6d32c1c2fd29b3361701e239ae2ce1c1c30756e8
MD5 eb215bec9f6e9b3d29564839c34f576c
BLAKE2b-256 de3fb450e7921e6cfd510034fadfb63f2343817718ac8040b726d445387904da

See more details on using hashes here.

Provenance

The following attestation bundles were made for configgraphviz-0.1.0-py3-none-any.whl:

Publisher: python-package.yml on manyan-chan/ConfigGraphViz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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