Skip to main content

Generate beautiful ASCII and PNG flowcharts from simple text descriptions

Project description

RetroFlow

 ___________________________________________________________
|                                                           |
|   _____      _             ______ _                       |
|  |  __ \    | |           |  ____| |                      |
|  | |__) |___| |_ _ __ ___ | |__  | | _____      __        |
|  |  _  // _ \ __| '__/ _ \|  __| | |/ _ \ \ /\ / /        |
|  | | \ \  __/ |_| | | (_) | |    | | (_) \ V  V /         |
|  |_|  \_\___|\__|_|  \___/|_|    |_|\___/ \_/\_/          |
|                                                           |
|            [ Beautiful ASCII Flowcharts ]                 |
|___________________________________________________________|
               ||                           ||

A Python library for generating beautiful ASCII and PNG flowcharts from simple text descriptions.

PyPI version Python Versions License: MIT codecov

Overview

This is a project to help engineers, researchers, project managers, and others create beautiful, retro-looking ASCII flow diagrams. ASCII diagrams are pretty, and harken back to the mid-20th century technical documentation. They also have real advantages:

  1. They work wonderfully in the age of agentic AI, which can easily read and parse these small representations.
  2. ASCII diagrams can live inline with: PRs, Markdown files, Slack threads, etc.
  3. ASCII diagrams optimize for thinking speed, not presentation quality. It encourages iteration and deletion instead of premature refinement.
  4. Minimalist diagrams reduce visual noise (although they do still look retro and pretty)
  5. They're tool agnostic and can be rendered anywhere
    ┌─────────┐
    │  START  │░
    └─────────┘░
     ░░░░░░░░░░░
         │
         ▼
    ┌─────────┐
    │ PROCESS │░
    └─────────┘░
     ░░░░░░░░░░░
         │
         ▼
    ┌─────────┐
    │DECISION │░
    └─────────┘░
     ░░░░░░░░░░░
         │
         ▼
    ┌─────────┐
    │   END   │░
    └─────────┘░
     ░░░░░░░░░░░

Installation

pip install retroflow

Or with uv:

uv add retroflow

Quick Start

from retroflow import FlowchartGenerator

# Create a generator
generator = FlowchartGenerator()

# Define your flowchart using simple arrow syntax
flowchart = generator.generate("""
    Start -> Process
    Process -> Decision
    Decision -> End
""")

print(flowchart)
    ┌─────────┐
    │  START  │░
    └─────────┘░
     ░░░░░░░░░░
         │
         ▼
    ┌─────────┐
    │ PROCESS │░
    └─────────┘░
     ░░░░░░░░░░
         │
         ▼
    ┌─────────┐
    │DECISION │░
    └─────────┘░
     ░░░░░░░░░░
         │
         ▼
    ┌─────────┐
    │   END   │░
    └─────────┘░
     ░░░░░░░░░░

Features

  • Simple syntax: Define flowcharts using intuitive A -> B arrow notation
  • ASCII output: Generate text-based flowcharts for terminals and documentation
  • PNG export: Create high-resolution images for presentations and reports
  • Intelligent layout: Automatic node positioning with the Sugiyama algorithm
  • Cycle detection: Handles cyclic graphs gracefully
  • Customizable: Adjust box sizes, spacing, and layout algorithms

Usage

Basic Generation

from retroflow import FlowchartGenerator

generator = FlowchartGenerator()

# Simple linear flow
result = generator.generate("""
    A -> B
    B -> C
    C -> D
""")
print(result)

Branching Flows

# Branching and merging
result = generator.generate("""
    Start -> Validate
    Validate -> Process
    Validate -> Error
    Process -> End
    Error -> End
""")
print(result)

Cyclic Flows

# Loops and cycles are supported
result = generator.generate("""
    Init -> Check
    Check -> Process
    Process -> Check
    Check -> Done
""")
print(result)

Export to PNG

generator = FlowchartGenerator()

# Save as high-resolution PNG
generator.save_png("""
    Login -> Authenticate
    Authenticate -> Success
    Authenticate -> Failure
    Success -> Dashboard
    Failure -> Login
""", "auth_flow.png", scale=2)

Export to Text File

generator = FlowchartGenerator()

generator.save_txt("""
    A -> B
    B -> C
""", "flowchart.txt")

Get Statistics

generator = FlowchartGenerator()

flowchart, stats = generator.generate_with_stats("""
    A -> B
    B -> C
    C -> A
""")

print(f"Nodes: {stats['nodes']}")
print(f"Edges: {stats['edges']}")
print(f"Has cycle: {stats['has_cycle']}")
print(f"Longest path: {stats['longest_path']}")

Configuration

FlowchartGenerator Options

generator = FlowchartGenerator(
    box_width=11,           # Width of each box (default: 11)
    box_height=3,           # Height of each box (default: 3)
    horizontal_spacing=4,   # Space between boxes horizontally (default: 4)
    vertical_spacing=3,     # Space between boxes vertically (default: 3)
    layout_algorithm='layered'  # 'layered' or 'simple' (default: 'layered')
)

PNG Export Options

generator.save_png(
    input_text,
    output_path="diagram.png",
    scale=2,              # Resolution multiplier (default: 2)
    horizontal_flow=True, # Left-to-right flow (default: True)
    margin=50,            # Image margin in pixels (default: 50)
    font_path="/path/to/font.ttf",  # Custom font (default: system monospace)
    font_size=11,         # Font size in points (default: 11)
)

Input Format

The input format uses a simple arrow syntax:

# Comments start with #
NodeA -> NodeB
NodeB -> NodeC

# Node names can contain spaces
User Login -> Validate Credentials
Validate Credentials -> Access Granted

Rules

  • Each line defines one connection: Source -> Target
  • Node names are trimmed of whitespace
  • Empty lines are ignored
  • Lines starting with # are comments
  • Node names can contain spaces

API Reference

FlowchartGenerator

The main class for generating flowcharts.

Methods

Method Description
generate(input_text) Generate ASCII flowchart string
generate_with_stats(input_text) Generate flowchart and return statistics
save_png(input_text, output_path, **kwargs) Save as PNG image
save_txt(input_text, output_path) Save as text file

Convenience Functions

from retroflow import generate_flowchart, parse_flowchart

# Quick generation
flowchart = generate_flowchart("A -> B\nB -> C")

# Parse without rendering
connections = parse_flowchart("A -> B\nB -> C")
# Returns: [('A', 'B'), ('B', 'C')]

Lower-Level API

For advanced use cases, you can access the individual components:

from retroflow import (
    parse_flowchart,
    create_graph,
    compute_layout,
    render_flowchart,
    render_to_png,
)

# Parse input
connections = parse_flowchart("A -> B\nB -> C")

# Create graph structure
graph = create_graph(connections)

# Compute layout
layout = compute_layout(graph, algorithm='layered')

# Render to ASCII
ascii_output = render_flowchart(graph, layout)

# Or render to PNG
render_to_png(graph, layout, "output.png")

Development

Setup

git clone https://github.com/ronikobrosly/retroflow.git
cd retroflow
uv sync --dev

Run Tests

uv run pytest

Run Linting

uvx ruff check .
uvx ruff format --check .

License

MIT License - see LICENSE for details.

Contributing

Contributions are 100% welcome! Please feel free to submit a PR.

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

retroflow-0.1.2.tar.gz (75.9 kB view details)

Uploaded Source

Built Distribution

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

retroflow-0.1.2-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file retroflow-0.1.2.tar.gz.

File metadata

  • Download URL: retroflow-0.1.2.tar.gz
  • Upload date:
  • Size: 75.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for retroflow-0.1.2.tar.gz
Algorithm Hash digest
SHA256 63566f54395708cd708b7c304f6a03680e57fe25532bba839f90bb9ebeccbf02
MD5 55f34682416c05de98bfdc94ba142802
BLAKE2b-256 94356dae078dedc0811772bbf4e3ecbac645c1281d5e3aed254250da7ca2d026

See more details on using hashes here.

File details

Details for the file retroflow-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: retroflow-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for retroflow-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ef7928e859d6d9a8a826a1bb26dad31f3dd49202dfb9339b02799885ef2f3049
MD5 fbf114ff4b1ff8891e7bb03da0a80e3e
BLAKE2b-256 96c3e63d4b157612394d67a58115a8415c45d875ec27ce47c94cb231cabd4e5c

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