Skip to main content

Inertia package dapater for Nestipy

Project description

Nestipy Logo

Version Python License

Description

Nestipy is a Python framework built on top of FastAPI that follows the modular architecture of NestJS

Under the hood, Nestipy makes use of FastAPI, but also provides compatibility with a wide range of other libraries, like Blacksheep, allowing for easy use of the myriad of third-party plugins which are available.

Getting started

pip install nestipy-inertia

Full example

main.py

  import os

import uvicorn
from nestipy.core import NestipyFactory
from nestipy.common import session
from app_module import AppModule, inertia_config
from nestipy_inertia import inertia_head, inertia_body, vite_react_refresh

app = NestipyFactory.create(AppModule)

# set view engine mini jinja and
app.set_base_view_dir(os.path.join(os.path.dirname(__file__), "views"))

# app.use_static_assets()
env = app.get_template_engine().get_env()
env.add_function("inertiaHead", inertia_head)
env.add_function("inertiaBody", inertia_body)

# When using react
env.add_function("viteReactRefresh", vite_react_refresh)
# Inertia config

front_dir = (
    os.path.join(os.path.dirname(__file__), "inertia", "dist")
    if inertia_config.environment != "development" or inertia_config.ssr_enabled is True
    else os.path.join(os.path.dirname(__file__), "inertia", "src")
)

app.use_static_assets(front_dir, "/dist")
app.use_static_assets(os.path.join(front_dir, "assets"), "/assets")
app.use(session())

if __name__ == '__main__':
    uvicorn.run('main:app', host="0.0.0.0", port=8000, reload=True)

app_module.py

import os

from nestipy.common import Module

from app_controller import AppController
from app_service import AppService
from nestipy_inertia import InertiaModule, InertiaConfig

inertia_config = InertiaConfig(
    manifest_json_path=os.path.join(
        os.path.dirname(__file__), "inertia", "dist", "manifest.json"
    ),
    environment="development",
    use_flash_messages=True,
    use_flash_errors=True,
    entrypoint_filename="main.tsx",
    ssr_enabled=False,
    assets_prefix="/dist",
)


@Module(
    imports=[
        InertiaModule.register(
            inertia_config
        )
    ],
    controllers=[AppController],
    providers=[
        AppService,
    ]
)
class AppModule:
    ...

vite.config.ts

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import nestipyVite from "./nestipy.inertia";

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        react(),
        nestipyVite({
            entry: './src/main.tsx',
            ssr: './src/ssr.tsx'
        }),
    ],
})

nestipy.inertia.ts

import { PluginOption } from "vite";

type Input = {
    entry: string,
    ssr?: string,
    manifest?: string
}
type NestipyPlugin = (options: Input) => PluginOption
const nestipyVite: NestipyPlugin = ({entry, ssr, manifest = "manifest.json"}) => {
    return {
        name: "nestipy-vite-plugin",
        config: (config, env) => {
            return {
                ...config,
                build: {
                    manifest: env.isSsrBuild ? false: manifest,
                    outDir: env.isSsrBuild ? "dist/ssr" : "dist",
                    rollupOptions: {
                        input: env.isSsrBuild && ssr ? ssr : entry,
                    },
                },
                ssr: {
                    noExternal: ['@inertiajs/server']
                }
            }
        }
    }
}

export default nestipyVite

Viw full exapmle code here.

Support

Nestipy is an MIT-licensed open source project. It can grow thanks to the sponsors and support from the amazing backers. If you'd like to join them, please [read more here].

Stay in touch

License

Nestipy is MIT licensed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nestipy_inertia-0.1.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

nestipy_inertia-0.1.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file nestipy_inertia-0.1.1.tar.gz.

File metadata

  • Download URL: nestipy_inertia-0.1.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.4.0

File hashes

Hashes for nestipy_inertia-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1a014f93990ae3826957f0fbd142272b5125f37d1460c55ce5aa4302109162fc
MD5 2b70b972b3418afab04f44a8cc62ba09
BLAKE2b-256 65104271e7d750592e2c88f1a804567ec3923760b12f6b7191501215e6688ba1

See more details on using hashes here.

File details

Details for the file nestipy_inertia-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nestipy_inertia-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.4.0

File hashes

Hashes for nestipy_inertia-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 601a44ed7003898fe016771cf183635ac6366d5fb5c3e18054d783d49195d5d1
MD5 1b64e3706cbf3d82815c78921474613d
BLAKE2b-256 2ebad10bc1a96f6de7b6256e09f23dbbdd2e37c9b4b3b1c40734cfbd18055d1b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page