fastapi-voyager 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,213 @@
1
+ import SchemaFieldFilter from "./component/schema-field-filter.js";
2
+ import SchemaCodeDisplay from "./component/schema-code-display.js";
3
+ import RouteCodeDisplay from "./component/route-code-display.js";
4
+ import { GraphUI } from "./graph-ui.js";
5
+ const { createApp, reactive, onMounted, watch, ref } = window.Vue;
6
+
7
+ const app = createApp({
8
+ setup() {
9
+ const state = reactive({
10
+ // options and selections
11
+ tag: null,
12
+ tagOptions: [], // array of strings
13
+ routeId: null,
14
+ routeOptions: [], // [{ label, value }]
15
+ schemaFullname: null,
16
+ schemaOptions: [], // [{ label, value }]
17
+ routeItems: {}, // { id: { label, value } }
18
+ showFields: "object",
19
+ fieldOptions: [
20
+ { label: "No fields", value: "single" },
21
+ { label: "Object fields", value: "object" },
22
+ { label: "All fields", value: "all" },
23
+ ],
24
+ generating: false,
25
+ rawTags: [], // [{ name, routes: [{ id, name }] }]
26
+ rawSchemas: [], // [{ name, fullname }]
27
+ rawSchemasFull: [], // full objects with source_code & fields
28
+ initializing: true,
29
+ });
30
+ const showDetail = ref(false);
31
+ const showSchemaFieldFilter = ref(false);
32
+ const showSchemaCode = ref(false);
33
+ const showRouteCode = ref(false);
34
+ const schemaName = ref(""); // used by detail dialog
35
+ const schemaFieldFilterSchema = ref(null); // external schemaName for schema-field-filter
36
+ const schemaCodeName = ref("");
37
+ const routeCodeId = ref("");
38
+ function openDetail() {
39
+ showDetail.value = true;
40
+ }
41
+ function closeDetail() {
42
+ showDetail.value = false;
43
+ }
44
+
45
+ function applyRoutesForTag(tagName) {
46
+ const tag = state.rawTags.find((t) => t.name === tagName);
47
+ state.routeOptions = [];
48
+ if (tag && Array.isArray(tag.routes)) {
49
+ state.routeOptions.push(
50
+ ...tag.routes.map((r) => ({ label: r.name, value: r.id }))
51
+ );
52
+ }
53
+ state.routeId = "";
54
+ }
55
+
56
+ function onFilterTags(val, update) {
57
+ const normalized = (val || "").toLowerCase();
58
+ update(() => {
59
+ if (!normalized) {
60
+ state.tagOptions = state.rawTags.map((t) => t.name);
61
+ return;
62
+ }
63
+ state.tagOptions = state.rawTags
64
+ .map((t) => t.name)
65
+ .filter((n) => n.toLowerCase().includes(normalized));
66
+ });
67
+ }
68
+
69
+ function onFilterSchemas(val, update) {
70
+ const normalized = (val || "").toLowerCase();
71
+ update(() => {
72
+ const makeLabel = (s) => `${s.name} (${s.fullname})`;
73
+ let list = state.rawSchemas.map((s) => ({
74
+ label: makeLabel(s),
75
+ value: s.fullname,
76
+ }));
77
+ if (normalized) {
78
+ list = list.filter((opt) =>
79
+ opt.label.toLowerCase().includes(normalized)
80
+ );
81
+ }
82
+ state.schemaOptions = list;
83
+ });
84
+ }
85
+
86
+ async function loadInitial() {
87
+ state.initializing = true;
88
+ try {
89
+ const res = await fetch("/dot");
90
+ const data = await res.json();
91
+ state.rawTags = Array.isArray(data.tags) ? data.tags : [];
92
+ state.rawSchemasFull = Array.isArray(data.schemas) ? data.schemas : [];
93
+ state.rawSchemas = state.rawSchemasFull.map((s) => ({
94
+ name: s.name,
95
+ fullname: s.fullname,
96
+ }));
97
+ state.routeItems = data.tags.map((t) => t.routes).flat().reduce((acc, r) => {
98
+ acc[r.id] = r;
99
+ return acc;
100
+ }, {});
101
+
102
+ state.tagOptions = state.rawTags.map((t) => t.name);
103
+ state.schemaOptions = state.rawSchemas.map((s) => ({
104
+ label: `${s.name} (${s.fullname})`,
105
+ value: s.fullname,
106
+ }));
107
+ // default route options placeholder
108
+ state.routeOptions = [];
109
+ } catch (e) {
110
+ console.error("Initial load failed", e);
111
+ } finally {
112
+ state.initializing = false;
113
+ }
114
+ }
115
+
116
+ async function onGenerate() {
117
+ state.generating = true;
118
+ try {
119
+ const payload = {
120
+ tags: state.tag ? [state.tag] : null,
121
+ schema_name: state.schemaFullname || null,
122
+ route_name: state.routeId || null,
123
+ show_fields: state.showFields,
124
+ };
125
+
126
+ const res = await fetch("/dot", {
127
+ method: "POST",
128
+ headers: { "Content-Type": "application/json" },
129
+ body: JSON.stringify(payload),
130
+ });
131
+ const dotText = await res.text();
132
+
133
+ // create graph instance once
134
+ const graphUI = new GraphUI("#graph", {
135
+ onSchemaClick: (name) => {
136
+ if (state.rawSchemas.find((s) => s.fullname === name)) {
137
+ schemaFieldFilterSchema.value = name;
138
+ showSchemaFieldFilter.value = true;
139
+ }
140
+ },
141
+ onSchemaAltClick: (name) => {
142
+ // priority: schema full name; else route id
143
+ if (state.rawSchemas.find((s) => s.fullname === name)) {
144
+ schemaCodeName.value = name;
145
+ showSchemaCode.value = true;
146
+ return;
147
+ }
148
+ if (name in state.routeItems) {
149
+ routeCodeId.value = name;
150
+ showRouteCode.value = true;
151
+ return;
152
+ }
153
+ },
154
+ });
155
+
156
+ await graphUI.render(dotText);
157
+ } catch (e) {
158
+ console.error("Generate failed", e);
159
+ } finally {
160
+ state.generating = false;
161
+ }
162
+ }
163
+
164
+ function showDialog() {
165
+ schemaFieldFilterSchema.value = null;
166
+ showSchemaFieldFilter.value = true;
167
+ }
168
+
169
+ async function onReset() {
170
+ state.tag = null;
171
+ state.routeId = "";
172
+ state.schemaFullname = null;
173
+ state.showFields = "object";
174
+ await loadInitial();
175
+ }
176
+
177
+ // react to tag changes to rebuild routes
178
+ watch(
179
+ () => state.tag,
180
+ (val) => {
181
+ applyRoutesForTag(val);
182
+ }
183
+ );
184
+
185
+ onMounted(async () => {
186
+ await loadInitial();
187
+ });
188
+
189
+ return {
190
+ state,
191
+ onFilterTags,
192
+ onFilterSchemas,
193
+ onGenerate,
194
+ onReset,
195
+ showDetail,
196
+ openDetail,
197
+ closeDetail,
198
+ schemaName,
199
+ showSchemaFieldFilter,
200
+ schemaFieldFilterSchema,
201
+ showDialog,
202
+ showSchemaCode,
203
+ showRouteCode,
204
+ schemaCodeName,
205
+ routeCodeId,
206
+ };
207
+ },
208
+ });
209
+ app.use(window.Quasar);
210
+ app.component("schema-field-filter", SchemaFieldFilter);
211
+ app.component("schema-code-display", SchemaCodeDisplay);
212
+ app.component("route-code-display", RouteCodeDisplay);
213
+ app.mount("#q-app");
@@ -0,0 +1,175 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastapi-voyager
3
+ Version: 0.4.1
4
+ Summary: Visualize FastAPI application's routing tree and dependencies
5
+ Project-URL: Homepage, https://github.com/allmonday/fastapi-voyager
6
+ Project-URL: Source, https://github.com/allmonday/fastapi-voyager
7
+ Author-email: Tangkikodo <allmonday@126.com>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: fastapi,openapi,routing,visualization
11
+ Classifier: Framework :: FastAPI
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: fastapi>=0.110
21
+ Requires-Dist: pydantic-resolve>=1.13.2
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest; extra == 'dev'
24
+ Requires-Dist: ruff; extra == 'dev'
25
+ Requires-Dist: uvicorn; extra == 'dev'
26
+ Description-Content-Type: text/markdown
27
+
28
+ [![pypi](https://img.shields.io/pypi/v/fastapi-voyager.svg)](https://pypi.python.org/pypi/fastapi-voyager)
29
+ ![Python Versions](https://img.shields.io/pypi/pyversions/fastapi-voyager)
30
+
31
+ > This repo is still in early stage, currently it support pydantic v2 only, previous name: fastapi-router-viz
32
+
33
+ Inspect your API interactively
34
+
35
+ <img width="1480" height="648" alt="image" src="https://github.com/user-attachments/assets/a6ccc9f1-cf06-493a-b99b-eb07767564bd" />
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ pip install fastapi-voyager
41
+ # or
42
+ uv add fastapi-voyager
43
+ ```
44
+
45
+
46
+ ## Dependencies
47
+
48
+ - FastAPI
49
+ - [pydantic-resolve](https://github.com/allmonday/pydantic-resolve)
50
+
51
+
52
+ ## Feature
53
+
54
+ For scenarios of using FastAPI as internal API integration endpoints, `fastapi-voyager` helps to visualize the dependencies.
55
+
56
+ It is also an architecture inspection tool that can identify issues in data relationships through visualization during the design phase.
57
+
58
+ 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
59
+
60
+
61
+
62
+ ```shell
63
+ git clone https://github.com/allmonday/fastapi-voyager.git
64
+ cd fastapi-voyager
65
+
66
+ voyager -m tests.demo
67
+ --server --port=8001
68
+ --module_color=tests.service:blue
69
+ --module_color=tests.demo:tomato
70
+ ```
71
+
72
+ pick tag, rotue (optional) and click `generate`.
73
+
74
+ <img width="1919" height="898" alt="image" style="border: 1px solid #aaa" src="https://github.com/user-attachments/assets/05e321d0-49f3-4af6-a7c7-f4c9c6b1dbfd" />
75
+
76
+ 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.
77
+
78
+ <img width="1485" height="616" alt="image" style="border: 1px solid #aaa" src="https://github.com/user-attachments/assets/70c4095f-86c7-45da-a6f0-fd41ac645813" />
79
+
80
+
81
+ `shift` click a node to check related nodes.
82
+
83
+ pick a field to narrow the result.
84
+
85
+ <img width="1917" height="800" alt="image" style="border: 1px solid #aaa" src="https://github.com/user-attachments/assets/e770dc70-f293-49e1-bcd7-d8dffa15d9ea" />
86
+
87
+ `alt` click a node to show source code or open file in vscode.
88
+
89
+ <img width="497" height="402" alt="image" style="border: 1px solid #aaa" src="https://github.com/user-attachments/assets/ac81711a-d9c2-4fb1-8b3a-0f4bd1f02572" />
90
+
91
+ more in video:
92
+
93
+ [![IMAGE ALT TEXT](http://img.youtube.com/vi/msYsB9Cc3CA/0.jpg)](https://www.youtube.com/watch?v=msYsB9Cc3CA "Unity Snake Game")
94
+
95
+
96
+ ## Command Line Usage
97
+
98
+ ### open in browser
99
+
100
+ ```bash
101
+ # open in browser
102
+ voyager -m tests.demo --server
103
+
104
+ voyager -m tests.demo --server --port=8002
105
+ ```
106
+
107
+ ### generate the dot file
108
+ ```bash
109
+ # generate .dot file
110
+ voyager -m tests.demo
111
+
112
+ voyager -m tests.demo --app my_app
113
+
114
+ voyager -m tests.demo --schema Task
115
+
116
+ voyager -m tests.demo --show_fields all
117
+
118
+ voyager -m tests.demo --module_color=tests.demo:red --module_color=tests.service:tomato
119
+
120
+ voyager -m tests.demo -o my_visualization.dot
121
+
122
+ voyager --version
123
+ ```
124
+
125
+ The tool will generate a DOT file that you can render using Graphviz:
126
+
127
+ ```bash
128
+ # Install graphviz
129
+ brew install graphviz # macOS
130
+ apt-get install graphviz # Ubuntu/Debian
131
+
132
+ # Render the graph
133
+ dot -Tpng router_viz.dot -o router_viz.png
134
+
135
+ # Or view online at: https://dreampuf.github.io/GraphvizOnline/
136
+ ```
137
+
138
+ or you can open router_viz.dot with vscode extension `graphviz interactive preview`
139
+
140
+
141
+ ## Plan
142
+
143
+ features:
144
+ - [x] group schemas by module hierarchy
145
+ - [x] module-based coloring via Analytics(module_color={...})
146
+ - [x] view in web browser
147
+ - [x] config params
148
+ - [x] make a explorer dashboard, provide list of routes, schemas, to make it easy to switch and search
149
+ - [x] support programmatic usage
150
+ - [x] better schema /router node appearance
151
+ - [x] hide fields duplicated with parent's (show `parent fields` instead)
152
+ - [x] refactor the frontend to vue, and tweak the build process
153
+ - [x] find dependency based on picked schema and it's field.
154
+ - [x] optimize static resource (cdn -> local)
155
+ - [x] add configuration for highlight (optional)
156
+ - [x] alt+click to show field details
157
+ - [x] display source code of routes (including response_model)
158
+ - [x] handle excluded field
159
+ - [ ] user can generate nodes/edges manually and connect to generated ones
160
+ - [ ] support dataclass
161
+ - [ ] group routes by module hierarchy
162
+ - [ ] integration with pydantic-resolve
163
+ - [ ] show difference between resolve, post fields
164
+ - [x] strikethrough for excluded fields
165
+ - [ ] display loader as edges
166
+ - [ ] test cases
167
+
168
+ bugs:
169
+ - [ ] fix duplicated link from class and parent class, it also break clicking highlight
170
+
171
+
172
+ ## Credits
173
+
174
+ - https://apis.guru/graphql-voyager/, for inspiration.
175
+ - https://github.com/tintinweb/vscode-interactive-graphviz, for web visualization.
@@ -0,0 +1,24 @@
1
+ fastapi_voyager/__init__.py,sha256=E5WTV_sYs2LK8I6jzA7AuvFU5a8_vjnDseC3DMha0iQ,149
2
+ fastapi_voyager/cli.py,sha256=FuXllJtlsm33FX6VmDdAFWzzQ5TIraUizBDgvBj3vmY,10489
3
+ fastapi_voyager/filter.py,sha256=uZrVVMhHG5E7j1wdsiB02RAyoDdF1q8A4J04oCboYAU,4644
4
+ fastapi_voyager/graph.py,sha256=H2qpEkLqjE2AceOOQIHPuhK_YvgSUBLvi78dBCLYAGc,14489
5
+ fastapi_voyager/module.py,sha256=ppiJ46rdyA4yQnQA5IQqsMOHGgWdz5orJ0bEQydHsEk,1885
6
+ fastapi_voyager/server.py,sha256=UFj6c0Yx4Rmy56eFXv65n1VdmJeiBX43KsDm6D65U28,2943
7
+ fastapi_voyager/type.py,sha256=k8V45obOzS6HQD8RqaBh4xKBQRUsV-mA_UdMZu51KR0,1005
8
+ fastapi_voyager/type_helper.py,sha256=VLQNivjFi7Wx7_v4vgRvY0uCD2IcqBpvEV3C74MVXK8,7450
9
+ fastapi_voyager/version.py,sha256=YFh850u830ExUciTkvvBKNAw5-kOUreAy1p-gcJGJ70,48
10
+ fastapi_voyager/web/graph-ui.js,sha256=eEjDnJVMvk35LdRoxcqX_fZxLFS9_bUrGAZL6K2O5C0,4176
11
+ fastapi_voyager/web/graphviz.svg.css,sha256=zDCjjpT0Idufu5YOiZI76PL70-avP3vTyzGPh9M85Do,1563
12
+ fastapi_voyager/web/graphviz.svg.js,sha256=lvAdbjHc-lMSk4GQp-iqYA2PCFX4RKnW7dFaoe0LUHs,16005
13
+ fastapi_voyager/web/index.html,sha256=-AAK0hxtW58urx_T13o7OHKTlEAk9ZyMKz-2MDPj0S8,7864
14
+ fastapi_voyager/web/quasar.min.css,sha256=F5jQe7X2XT54VlvAaa2V3GsBFdVD-vxDZeaPLf6U9CU,203145
15
+ fastapi_voyager/web/quasar.min.js,sha256=h0ftyPMW_CRiyzeVfQqiup0vrVt4_QWojpqmpnpn07E,502974
16
+ fastapi_voyager/web/vue-main.js,sha256=PpvaoDquNgOAsqWgIO75bWRcEVl_vuos_vM1Qo5jlww,6406
17
+ fastapi_voyager/web/component/route-code-display.js,sha256=NECC1OGcPCdDfbghtRJEnmFM6HmH5J3win2ibapWPeA,2649
18
+ fastapi_voyager/web/component/schema-code-display.js,sha256=oOusgTvCaWGnoKb-NBwu0SXqJJf2PTUtp3lUczokTBM,5515
19
+ fastapi_voyager/web/component/schema-field-filter.js,sha256=9WBjO6JJl2yf6OiiXoddMgvL32qTDu0PM-RxkkJ7t5M,6267
20
+ fastapi_voyager-0.4.1.dist-info/METADATA,sha256=nl6TQBqmoIj4l9dF5XRZW1wv9edEvYLlDSUMuUr5D2A,5839
21
+ fastapi_voyager-0.4.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
22
+ fastapi_voyager-0.4.1.dist-info/entry_points.txt,sha256=pEIKoUnIDXEtdMBq8EmXm70m16vELIu1VPz9-TBUFWM,53
23
+ fastapi_voyager-0.4.1.dist-info/licenses/LICENSE,sha256=lNVRR3y_bFVoFKuK2JM8N4sFaj3m-7j29kvL3olFi5Y,1067
24
+ fastapi_voyager-0.4.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ voyager = fastapi_voyager.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 tangkikodo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.