Skip to main content

Visualize FastAPI application's routing tree and dependencies

Project description

pypi Python Versions PyPI Downloads

FastAPI Voyager

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.

fastapi-voyager overview

Table of Contents

Quick Start

With simple configuration, fastapi-voyager can be embedded into FastAPI:

from fastapi import FastAPI
from fastapi_voyager import create_voyager

app = 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))

Visit http://localhost:8000/voyager to explore your API visually.

View full example

Installation

Install via pip

pip install fastapi-voyager

Install via uv

uv add fastapi-voyager

Run with CLI

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

For sub-application scenarios (e.g., app.mount("/api", api)), specify the app name:

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

Note: Sub-Application mounts are not supported yet, but you can specify the name of the FastAPI application with --app. Only a single application (default: app) can be selected.

Features

fastapi-voyager is designed for scenarios using FastAPI as internal API integration endpoints. It helps visualize dependencies and serves as an architecture tool to identify implementation issues such as wrong relationships, overfetching, and more.

Best Practice: When building view models following the ER model pattern, fastapi-voyager can fully realize its potential - quickly identifying which APIs use specific entities and vice versa.

Highlight Nodes and Links

Click a node to highlight its upstream and downstream nodes. Figure out the related models of one page, or how many pages are related with one model.

highlight nodes and dependencies

View Source Code

Double-click a node or route to show source code or open the file in VSCode.

view source code

Quick Search

Search schemas by name and display their upstream and downstream dependencies. Use Shift + Click on any node to quickly search for it.

quick search functionality

Display ER Diagram

ER diagram is a feature from pydantic-resolve which provides a solid expression for business descriptions. You can visualize application-level entity relationship diagrams.

from pydantic_resolve import ErDiagram, Entity, Relationship

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
          ))
ER diagram visualization

Show Pydantic Resolve Meta Info

Set enable_pydantic_resolve_meta=True in create_voyager, then toggle the "pydantic resolve meta" button to visualize resolve/post/expose/collect operations.

pydantic resolve meta information

Command Line Usage

Start Server

# Open in browser (default port 8000)
voyager -m tests.demo --server

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

# Specify app name
voyager -m tests.demo --server --app my_app

Generate DOT File

# Generate .dot file
voyager -m tests.demo

# Specify app
voyager -m tests.demo --app my_app

# Filter by schema
voyager -m tests.demo --schema Task

# Show all fields
voyager -m tests.demo --show_fields all

# Custom module colors
voyager -m tests.demo --module_color=tests.demo:red --module_color=tests.service:tomato

# Output to file
voyager -m tests.demo -o my_visualization.dot

# Version and help
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 business relationships.

The @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.

Development

Setup Development Environment

# Fork and clone the repository
git clone https://github.com/your-username/fastapi-voyager.git
cd fastapi-voyager

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Create virtual environment and install dependencies
uv venv
source .venv/bin/activate
uv pip install ".[dev]"

# Run development server
uvicorn tests.programatic:app --reload

Visit http://localhost:8000/voyager to see changes.

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.

Project Structure

Frontend:

  • src/fastapi_voyager/web/vue-main.js - Main JavaScript entry

Backend:

  • voyager.py - Main entry point
  • render.py - Generate DOT files
  • server.py - Server mode

Roadmap

Dependencies

Credits

License

MIT License

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.6.tar.gz (617.4 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.6-py3-none-any.whl (544.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_voyager-0.15.6.tar.gz
  • Upload date:
  • Size: 617.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","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.6.tar.gz
Algorithm Hash digest
SHA256 2c16388bf9ee406fa9a2d6490425b7651f39fbdb1cf3ea4753173c0058c90a99
MD5 393b01b2c7e5f487a92c1cc083bb02ba
BLAKE2b-256 5fb18cc36c16bde0c434a9fbff41c514a9bfd46ad6ffb82d9c76bfeee6ef1d39

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_voyager-0.15.6-py3-none-any.whl
  • Upload date:
  • Size: 544.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e0313ffed085b3dffa487d22f58cb311b65e08d3dfe9c961e2e94a4303110942
MD5 aca5bba1b6439c87aff0379a13f63e3c
BLAKE2b-256 67ef3b85bceed1ee6bb1966dd7255e03252d1f3809da16a956f008589edf9408

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