Skip to main content

Visualize FastAPI application's routing tree and dependencies

Project description

pypi Python Versions PyPI Downloads

Visualize your FastAPI endpoints, and explore them interactively.

Its vision is to make code easier to read and understand, serving as an ideal documentation tool.

This repo is still in early stage, it supports pydantic v2 only

visit live demo source code:composition oriented development pattern

image

with simple configuration it can be embedded into FastAPI.

app.mount('/voyager', 
          create_voyager(
            app, 
            module_color={'src.services': 'tomato'}, 
            module_prefix='src.services', 
            swagger_url="/docs",
            ga_id="G-XXXXXXXXVL",
            initial_page_policy='first',
            online_repo_url='https://github.com/allmonday/composition-oriented-development-pattern/blob/master',
            enable_pydantic_resolve_meta=True))

https://github.com/allmonday/composition-oriented-development-pattern/blob/master/src/main.py#L48

Plan & Raodmap

Installation

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

run with cli:

voyager -m path.to.your.app.module --server

Sub-Application mounts are not supported yet, but you can specify the name of the FastAPI application used with --app. Only a single application (default: 'app') can be selected, but in a scenario where api is attached through app.mount("/api", api), you can select api like this:

voyager -m path.to.your.app.module --server --app api

Features

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

It is also an architecture tool that can identify issues inside implementation, finding out wrong relationships, overfetchs, or anything else.

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

Given ErDiagram defined by pydantic-resolve, application level entity relationship diagram can be visualized too.

highlight nodes and links

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

view source code

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

image

quick search

seach schemas by name and dispaly it's upstream and downstreams.

shift + click can quickly search current one

image

display ER diagram

ER diagram is a new feature from pydantic-resolve which provide a solid expression for business descritpions.

diagram = ErDiagram(
    configs=[
        Entity(
            kls=Team,
            relationships=[
                Relationship( field='id', target_kls=list[Sprint], loader=sprint_loader.team_to_sprint_loader),
                Relationship( field='id', target_kls=list[User], loader=user_loader.team_to_user_loader)
            ]
        ),
        Entity(
            kls=Sprint,
            relationships=[
                Relationship( field='id', target_kls=list[Story], loader=story_loader.sprint_to_story_loader)
            ]
        ),
        Entity(
            kls=Story,
            relationships=[
                Relationship( field='id', target_kls=list[Task], loader=task_loader.story_to_task_loader),
                Relationship( field='owner_id', target_kls=User, loader=user_loader.user_batch_loader)
            ]
        ),
        Entity(
            kls=Task,
            relationships=[
                Relationship( field='owner_id', target_kls=User, loader=user_loader.user_batch_loader)
            ]
        )
    ]
)

# display in voyager
app.mount('/voyager', 
          create_voyager(
            app,
            er_diagram=diagram)
image

Show pydantic resolve meta info

setting enable_pydantic_resolve_meta=True in create_voyager, toggle pydantic resolve meta.

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

voyager --help

About pydantic-resolve

pydantic-resolve is a lightweight tool designed to build complex, nested data in a simple, declarative way. In v2 it introduced an important feature: ER Diagram, and fastapi-voyager has supported this feature, allowing for a clearer understanding of the business relationships.

pydantic-resolve's @ensure_subset decorator DefineSubset metaclass helps safely pick fields from the 'source class' while indicating the reference from the current class to the base class.

Developers can use fastapi-voyager without needing to know anything about pydantic-resolve, but I still highly recommend everyone to give it a try.

Dependencies

Credits

How to develop & contribute?

fork, clone.

install uv.

uv venv
source .venv/bin/activate
uv pip install ".[dev]"
uvicorn tests.programatic:app  --reload

Setup Git Hooks (Optional)

Enable automatic code formatting before commits:

./setup-hooks.sh
# or manually:
git config core.hooksPath .githooks

This will run Prettier automatically before each commit. See .githooks/README.md for details.

open localhost:8000/voyager

frontend:

  • src/fastapi_voyager/web/vue-main.js: main js

backend:

  • voyager.py: main entry
  • render.py: generate dot file
  • server.py: serve mode

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.15.2.tar.gz (615.0 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.15.2-py3-none-any.whl (542.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_voyager-0.15.2.tar.gz
  • Upload date:
  • Size: 615.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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 fastapi_voyager-0.15.2.tar.gz
Algorithm Hash digest
SHA256 51caf08db43dc1d859384ba453e6cc94ef21a4e2696283ca1e360137ccd4a553
MD5 542bb10b874214dc3bcb43837bd8f545
BLAKE2b-256 cef314ed382e46a8e518972fa7c327e49d3f172a4f5c84c97696793ddfc68e50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_voyager-0.15.2-py3-none-any.whl
  • Upload date:
  • Size: 542.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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 fastapi_voyager-0.15.2-py3-none-any.whl
Algorithm Hash digest
SHA256 17c64e06a9a2b25aa7e678e08d36ec656bdd6ecd3e019c62eda0500a24d6d970
MD5 a8a0d67a01b42cc868f2d80f0278112c
BLAKE2b-256 8aa81a53d146e8cfa23f7e00c5f13216f364d5bce21db93db7f4a71d1a1c927d

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