Skip to main content

Visualize FastAPI application's routing tree and dependencies

Project description

pypi Python Versions

This repo is still in early stage, currently it supports pydantic v2 only, previous name: fastapi-router-viz

Inspect your API interactively

image

Installation

pip install fastapi-voyager
# or
uv add fastapi-voyager

Dependencies

Feature

For scenarios of using FastAPI as internal API integration endpoints, fastapi-voyager helps to visualize the dependencies.

It is also an architecture inspection tool that can identify issues in data relationships through visualization during the design phase.

If the process of building the view model follows the ER model, the full potential of fastapi-voyager can be realized. It allows for quick identification of APIs that use entities, as well as which entities are used by a specific API

git clone https://github.com/allmonday/fastapi-voyager.git
cd fastapi-voyager

voyager -m tests.demo 
           --server --port=8001 
           --module_color=tests.service:blue 
           --module_color=tests.demo:tomato

generate the graph

after initialization, pick tag, rotue (optional) and click generate.

image

highlight

click a node to highlight it's upperstream and downstream nodes. figure out the related models of one page, or homw many pages are related with one model.

image

filter related nodes

shift click a node to check related node, pick a field to narrow the result.

image

view source code

alt click a node to show source code or open file in vscode.

image image

alt click a route to show source code or open file in vscode

image

Command Line Usage

open in browser

# open in browser
voyager -m tests.demo --server  

voyager -m tests.demo --server --port=8002

generate the dot file

# generate .dot file
voyager -m tests.demo  

voyager -m tests.demo --app my_app

voyager -m tests.demo --schema Task

voyager -m tests.demo --show_fields all

voyager -m tests.demo --module_color=tests.demo:red --module_color=tests.service:tomato

voyager -m tests.demo -o my_visualization.dot

voyager --version

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

# 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/

or you can open router_viz.dot with vscode extension graphviz interactive preview

Plan before v1.0

features:

  • group schemas by module hierarchy
  • module-based coloring via Analytics(module_color={...})
  • view in web browser
    • config params
    • make a explorer dashboard, provide list of routes, schemas, to make it easy to switch and search
  • support programmatic usage
  • better schema /router node appearance
  • hide fields duplicated with parent's (show parent fields instead)
  • refactor the frontend to vue, and tweak the build process
  • find dependency based on picked schema and it's field.
  • optimize static resource (cdn -> local)
  • add configuration for highlight (optional)
  • alt+click to show field details
  • display source code of routes (including response_model)
  • handle excluded field
  • add tooltips
  • route
    • group routes by module hierarchy
    • add response_model in route
  • support dataclass (pending)
  • click field to highlight links
  • user can generate nodes/edges manually and connect to generated ones
    • add owner
  • ui optimization
    • fixed left/right bar show field information
  • display standard ER diagram difficult
    • display potential invalid links
  • integration with pydantic-resolve
    • show difference between resolve, post fields
    • strikethrough for excluded fields
    • display loader as edges
  • export voyager core data into json (for better debugging)
    • add api to rebuild core data from json, and render it
  • fix Generic case test_generic.py

bugs & non feature:

  • fix duplicated link from class and parent class, it also break clicking highlight
  • add tests
  • refactor
    • abstract render module

Using with pydantic-resolve

pydantic-resolve's @ensure_subset decorator is helpful to pick fields from source class in safe.

TODO: ...

Credits

Changelog

  • 0.7:
    • 0.7.4
      • optimize tag/route, move to left.
      • fresh on change, no need to click generate any more.
    • 0.7.3
      • fix module_color failure
    • 0.7.2
      • keep links inside filtered nodes.
    • 0.7.1
      • support brief mode, you can use --module_prefix tests.service to show links between routes and filtered schemas, to make the graph less complicated.
  • 0.6:
    • 0.6.2:
      • fix generic related issue

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_voyager-0.7.4.tar.gz (574.2 kB view details)

Uploaded Source

Built Distribution

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

fastapi_voyager-0.7.4-py3-none-any.whl (523.4 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_voyager-0.7.4.tar.gz.

File metadata

  • Download URL: fastapi_voyager-0.7.4.tar.gz
  • Upload date:
  • Size: 574.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for fastapi_voyager-0.7.4.tar.gz
Algorithm Hash digest
SHA256 37d2cf61ad85bc09a4566edb884122b10b0831031b7f8f2a379398c5c6f2209c
MD5 ddcfdf52fb2027766b6ce8306469b811
BLAKE2b-256 f38861c9bd81201b9f642602c30b07fb970e66317fc4db0d5b154592dbaf6cf5

See more details on using hashes here.

File details

Details for the file fastapi_voyager-0.7.4-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_voyager-0.7.4-py3-none-any.whl
Algorithm Hash digest
SHA256 068132aa24e7ac9d35b0e579e01ec9475e70be78a30455a23b1b3c3f6d9ddb20
MD5 42057f0c1b37a54b5713677dc9906d83
BLAKE2b-256 143111e14f51af3f384632ec488cfae0c0cbbbb18264af019cdd2d46e7802ffa

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