# 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" />
Raw data
{
"_id": null,
"home_page": null,
"name": "fastapi-router-viz",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "fastapi, openapi, routing, visualization",
"author": null,
"author_email": "Tangkikodo <allmonday@126.com>",
"download_url": "https://files.pythonhosted.org/packages/49/e2/c9f6e5fe3365d10b910a074d27493bb22211e6f5ec4910792b96eb1dadec/fastapi_router_viz-0.1.8.tar.gz",
"platform": null,
"description": "# fastapi-router-viz\n\nVisualize FastAPI application's routing tree and dependencies\n\n> This repo is still in early stage.\n\n## Installation\n\n```bash\npip install fastapi-router-viz\n# or\nuv add fastapi-router-viz\n```\n\n## Command Line Usage\n\nOnce installed, you can use the `router-viz` command to generate visualization graphs from your FastAPI applications:\n\n```bash\n# Basic usage - assumes your FastAPI app is named 'app' in app.py\nrouter-viz app.py\n\n# Specify custom app variable name\nrouter-viz main.py --app my_app\n\n# Custom output file\nrouter-viz app.py -o my_visualization.dot\n\n# Show help\nrouter-viz --help\n\n# Show version\nrouter-viz --version\n```\n\nThe tool will generate a DOT file that you can render using Graphviz:\n\n```bash\n# Install graphviz\nbrew install graphviz # macOS\napt-get install graphviz # Ubuntu/Debian\n\n# Render the graph\ndot -Tpng router_viz.dot -o router_viz.png\n\n# Or view online at: https://dreampuf.github.io/GraphvizOnline/\n```\n\n## Programmatic Usage\n\n```python\nclass PageTask(Task):\n owner: Optional[Member]\n\n@ensure_subset(Story)\nclass PageStory(BaseModel):\n id: int\n sprint_id: int\n title: str\n\n tasks: list[PageTask] = []\n owner: Optional[Member] = None\n\nclass PageSprint(Sprint):\n stories: list[PageStory]\n owner: Optional[Member]\n\nclass PageOverall(BaseModel):\n sprints: list[PageSprint]\n\n\n@app.get(\"/page_overall\", tags=['page'], response_model=PageOverall)\ndef get_page_info():\n return {\"sprints\": []}\n\n\nclass PageStories(BaseModel):\n stories: list[PageStory]\n\n@app.get(\"/page_stories/\", tags=['page'], response_model=PageStories)\ndef get_page_info_2():\n return {}\n```\n\n```shell\nrouter-viz -m tests.demo\n```\n\nopen router_viz.dot with vscode extension `graphviz interactive preview`\n\n<img width=\"1062\" height=\"283\" alt=\"image\" src=\"https://github.com/user-attachments/assets/d8134277-fa84-444a-b6cd-1287e477a83e\" />\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Visualize FastAPI application's routing tree and dependencies",
"version": "0.1.8",
"project_urls": {
"Homepage": "https://github.com/allmonday/fastapi-router-viz",
"Source": "https://github.com/allmonday/fastapi-router-viz"
},
"split_keywords": [
"fastapi",
" openapi",
" routing",
" visualization"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "1fb4f0d1563120264be780b69a31e07fc8971d6ef65fd39ce12dae0b5fce0343",
"md5": "4e7276dea5d4e8f34228dde13ad5f072",
"sha256": "904ec5ea077703c0a07ecc24e59e2e05bca9ee9b075a90b7a8c3a8a10bd6d96f"
},
"downloads": -1,
"filename": "fastapi_router_viz-0.1.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4e7276dea5d4e8f34228dde13ad5f072",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 10301,
"upload_time": "2025-09-06T13:26:25",
"upload_time_iso_8601": "2025-09-06T13:26:25.166414Z",
"url": "https://files.pythonhosted.org/packages/1f/b4/f0d1563120264be780b69a31e07fc8971d6ef65fd39ce12dae0b5fce0343/fastapi_router_viz-0.1.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "49e2c9f6e5fe3365d10b910a074d27493bb22211e6f5ec4910792b96eb1dadec",
"md5": "0f0178b92e4727a88b29613004343062",
"sha256": "505d98ed18883142d228cf190a04680283b97237a92247c2847ca18646b8da58"
},
"downloads": -1,
"filename": "fastapi_router_viz-0.1.8.tar.gz",
"has_sig": false,
"md5_digest": "0f0178b92e4727a88b29613004343062",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 174350,
"upload_time": "2025-09-06T13:26:26",
"upload_time_iso_8601": "2025-09-06T13:26:26.553713Z",
"url": "https://files.pythonhosted.org/packages/49/e2/c9f6e5fe3365d10b910a074d27493bb22211e6f5ec4910792b96eb1dadec/fastapi_router_viz-0.1.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-06 13:26:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "allmonday",
"github_project": "fastapi-router-viz",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "fastapi-router-viz"
}