|
| 1 | +# Interactive Graph |
| 2 | + |
| 3 | +!!! interactive-graph "Interactive Graph" |
| 4 | + |
| 5 | + Turn your container into an interactive dependency graph. Explore routes, functions, services, factories, |
| 6 | + configuration, and scopes in a live page with search, grouping, and dependency tracing. |
| 7 | + |
| 8 | + Learn how it works and explore it on an demo pet store app: |
| 9 | + |
| 10 | + [:octicons-arrow-right-24: Live Demo](wireup_graph/pet_store.html){ .md-button .md-button--primary target="_blank" } |
| 11 | + |
| 12 | +Wireup can render your dependency graph as an interactive page, including: |
| 13 | + |
| 14 | +- routes and injected functions for selected frameworks |
| 15 | +- services and factories |
| 16 | +- configuration nodes |
| 17 | +- singleton, scoped, and transient lifetimes |
| 18 | + |
| 19 | +This is one of the fastest ways to understand how a real application is wired together without relying on a static dump |
| 20 | +or a handwritten diagram. |
| 21 | + |
| 22 | +## Preview |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +## Automatic with FastAPI and Flask |
| 28 | + |
| 29 | +FastAPI and Flask can expose the graph page automatically (defaults to `/_wireup`). |
| 30 | + |
| 31 | +### FastAPI |
| 32 | + |
| 33 | +```python |
| 34 | +import wireup.integration.fastapi |
| 35 | + |
| 36 | +wireup.integration.fastapi.setup( |
| 37 | + container, |
| 38 | + app, |
| 39 | + add_graph_endpoint=True, |
| 40 | +) |
| 41 | +``` |
| 42 | + |
| 43 | +### Flask |
| 44 | + |
| 45 | +```python |
| 46 | +import wireup.integration.flask |
| 47 | + |
| 48 | +wireup.integration.flask.setup( |
| 49 | + container, |
| 50 | + app, |
| 51 | + add_graph_endpoint=True, |
| 52 | +) |
| 53 | +``` |
| 54 | + |
| 55 | +## Use in other frameworks |
| 56 | + |
| 57 | +If your framework does not have automatic graph-page setup, you can still generate the graph yourself from Python. |
| 58 | + |
| 59 | +### 1. Build graph data |
| 60 | + |
| 61 | +```python |
| 62 | +from wireup.renderer.core import GraphOptions, to_graph_data |
| 63 | + |
| 64 | +graph_data = to_graph_data( |
| 65 | + container, # or get_app_container() if the integration provides it |
| 66 | + options=GraphOptions(base_module="myapp"), |
| 67 | +) |
| 68 | +``` |
| 69 | + |
| 70 | +### 2. Render it as HTML |
| 71 | + |
| 72 | +```python |
| 73 | +from wireup.renderer.full_page import full_page_renderer |
| 74 | + |
| 75 | +html = full_page_renderer(graph_data, title="My App - Wireup Graph") |
| 76 | +``` |
| 77 | + |
| 78 | +### 3. Return it from a route |
| 79 | + |
| 80 | +```python |
| 81 | +@app.get("/_wireup") |
| 82 | +def wireup_graph(): |
| 83 | + graph_data = to_graph_data( |
| 84 | + container, options=GraphOptions(base_module="myapp") |
| 85 | + ) |
| 86 | + html = full_page_renderer(graph_data, title="My App - Wireup Graph") |
| 87 | + |
| 88 | + return HTMLResponse(html) |
| 89 | +``` |
| 90 | + |
| 91 | + |
| 92 | +!!! tip |
| 93 | + Make sure to permission this endpoint appropriately in production since it exposes internal implementation details. You can disable it by omitting `add_graph_endpoint=True` or by not registering the route at all. |
0 commit comments