Skip to main content

forge-inertia

Inertia.js adapter for forge-kits / FastAPI.
Brings the Laravel Inertia workflow to Python — same protocol, same mental model.

pip install forge-kits-inertia

Requirements

  • Python ≥ 3.11
  • forge-kits ≥ 1.6.3
  • A Vite + Vue 3 (or React/Svelte) frontend with @inertiajs/vue3 (or equivalent)

Setup

1. Register the provider

# config/project.py
from forgeapi.inertia import InertiaProvider

config = {
    "providers": [InertiaProvider],
    ...
}

2. Create config/inertia.py

# config/inertia.py
from forgeapi import env

config = {
    "dev_mode":     env("INERTIA_DEV", False),
    "vite_dev_url": env("VITE_DEV_URL", "http://localhost:5173"),
    # Optional overrides (shown with defaults):
    # "root_view":  "public/build/index.html",
    # "public_dir": "public",
    # "vite_entry": "src/main.ts",
    # "version":    "",   # auto-detected from Vite manifest when empty
}

3. Frontend entry (src/main.ts)

import { createApp, h } from 'vue'
import { createInertiaApp } from '@inertiajs/vue3'
import './style.css'

createInertiaApp({
  resolve: name => {
    const pages = import.meta.glob('./Pages/**/*.vue', { eager: true })
    return pages[`./Pages/${name}.vue`]
  },
  setup({ el, App, props, plugin }) {
    createApp({ render: () => h(App, props) })
      .use(plugin)
      .mount(el)
  },
})

4. Vite config (vite.config.ts)

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  build: {
    outDir: '../public/build',
    emptyOutDir: true,
  },
})

Returning an Inertia response

from fastapi import Request
from fastapi.responses import Response
from forgeapi.controllers import Controller, route
from forgeapi.inertia import Inertia

class DashboardController(Controller):
    prefix = "/dashboard"

    @route.get("/", response_class=Response)
    async def index(self, request: Request) -> Response:
        return Inertia("Dashboard", props={"stats": await get_stats()}, request=request)

The component name maps directly to Pages/Dashboard.vue (or .tsx, .svelte).

Lazy (callable) props

Props that are callables are only evaluated when actually needed — useful for partial reloads:

return Inertia("Dashboard", props={
    "user":  current_user.dict(),       # always evaluated
    "stats": lambda: get_heavy_stats(), # skipped on partial reloads that don't request it
}, request=request)

Shared data

Equivalent of Laravel's HandleInertiaRequests middleware — data shared on every response.

# config/project.py (or a dedicated boot file)
from forgeapi.inertia import inertia_share

# Static value
inertia_share("app_name", "My App")

# Per-request callable — receives FastAPI Request
inertia_share("auth", lambda req: {
    "user": req.state.user.dict() if hasattr(req.state, "user") else None,
})

Shared props are merged with page props on every Inertia response. Page props override shared props on key collision.


Partial reloads

forge-inertia handles X-Inertia-Partial-Data / X-Inertia-Partial-Component automatically:

  • Props not in the requested set are excluded from the response.
  • Shared prop callables not in the set are never called.
  • Page prop callables (lambdas) not in the set are never called.
  • If the component name doesn't match, all props are returned normally.

No controller changes required — the adapter filters at the response layer.


Configuration reference

All options with their defaults:

Key Default Description
root_view "public/build/index.html" Compiled HTML shell served on initial load
public_dir "public" Static assets root (mounted at /build)
version "" Asset version; auto-set from Vite manifest when empty
dev_mode False True → serve from Vite dev server (full HMR, no build step)
vite_dev_url "http://localhost:5173" Vite dev server base URL
vite_entry "src/main.ts" Frontend entry point (injected in dev HTML shell)

Dev workflow

Two terminals:

# Frontend (in resources/)
npm run dev

# Backend (in project root)
forgeapi runserver --reload

Set INERTIA_DEV=true in .env. The backend serves an HTML shell that loads JS/CSS directly from the Vite dev server — full HMR, no build step.

Production

# Build frontend
npm run build   # outputs to public/build/

# Run server
forgeapi runserver

InertiaProvider auto-mounts /build as static files and reads the Vite manifest to set the asset version hash (SHA-1, deterministic across restarts).


Protocol compatibility

Feature Status
Initial page load (HTML shell) ✅
Subsequent navigation (XHR/JSON) ✅
Asset version mismatch → 409 + hard reload ✅
POST/PUT/PATCH/DELETE 302 → 303 redirect ✅
Shared props (per-request callables) ✅
Partial reloads (X-Inertia-Partial-Data) ✅
Lazy (callable) page props ✅
SSR ❌ not yet

Metadata

Release files for forge-kits-inertia 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for forge-kits-inertia 0.1.2
File Size Uploaded
forge_kits_inertia-0.1.2.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for forge-kits-inertia 0.1.2
File Interpreter ABI Platform
forge_kits_inertia-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / forge_kits_inertia-0.1.2.tar.gz

Download URL forge_kits_inertia-0.1.2.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
083e778005dbac9cefa0fb2102b97f49eadd5d2f8635716b7edd786ab1c68868
BLAKE2b-256 checksum
How to use checksums
b58694ea6cf52da6e3cc800d4fac83fdad032f91e5d569a8081d02f751bf843d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / forge_kits_inertia-0.1.2-py3-none-any.whl

Download URL forge_kits_inertia-0.1.2-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47b7047e73d0426a7a12921b8cda37636ea6b657002836d9a268f8307c0f08f6
BLAKE2b-256 checksum
How to use checksums
08a06879e1ad9626ea952ab27345e9367d9b59afd14c899677a2dd8299c2a15c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page