Metadata-Version: 2.4
Name: fastapi-router-viz
Version: 0.1.8
Summary: Visualize FastAPI application's routing tree and dependencies
Project-URL: Homepage, https://github.com/allmonday/fastapi-router-viz
Project-URL: Source, https://github.com/allmonday/fastapi-router-viz
Author-email: Tangkikodo <allmonday@126.com>
License: MIT
License-File: LICENSE
Keywords: fastapi,openapi,routing,visualization
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Requires-Dist: fastapi>=0.115
Requires-Dist: pydantic-resolve>=1.13.2
Provides-Extra: dev
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: uvicorn; extra == 'dev'
Description-Content-Type: text/markdown

# fastapi-router-viz

Visualize FastAPI application's routing tree and dependencies

> This repo is still in early stage.

## Installation

```bash
pip install fastapi-router-viz
# or
uv add fastapi-router-viz
```

## Command Line Usage

Once installed, you can use the `router-viz` command to generate visualization graphs from your FastAPI applications:

```bash
# Basic usage - assumes your FastAPI app is named 'app' in app.py
router-viz app.py

# Specify custom app variable name
router-viz main.py --app my_app

# Custom output file
router-viz app.py -o my_visualization.dot

# Show help
router-viz --help

# Show version
router-viz --version
```

The tool will generate a DOT file that you can render using Graphviz:

```bash
# Install graphviz
brew install graphviz  # macOS
apt-get install graphviz  # Ubuntu/Debian

# Render the graph
dot -Tpng router_viz.dot -o router_viz.png

# Or view online at: https://dreampuf.github.io/GraphvizOnline/
```

## Programmatic Usage

```python
class PageTask(Task):
    owner: Optional[Member]

@ensure_subset(Story)
class PageStory(BaseModel):
    id: int
    sprint_id: int
    title: str

    tasks: list[PageTask] = []
    owner: Optional[Member] = None

class PageSprint(Sprint):
    stories: list[PageStory]
    owner: Optional[Member]

class PageOverall(BaseModel):
    sprints: list[PageSprint]


@app.get("/page_overall", tags=['page'], response_model=PageOverall)
def get_page_info():
    return {"sprints": []}


class PageStories(BaseModel):
    stories: list[PageStory]

@app.get("/page_stories/", tags=['page'], response_model=PageStories)
def get_page_info_2():
    return {}
```

```shell
router-viz -m tests.demo
```

open router_viz.dot with vscode extension `graphviz interactive preview`

<img width="1062" height="283" alt="image" src="https://github.com/user-attachments/assets/d8134277-fa84-444a-b6cd-1287e477a83e" />
