litestar-build
Skill19 starsChanged 11 days agoMITView on GitHub
Use when working with uv build, uv_build, hatch build, PyApp, scie-jump, PYAPP_*, wheel assets, GitHub release matrices, cargo-zigbuild, or python-build-standalone. Not for runtime deployment.
- Installs packages
- Commits and pushes
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- advanced-alchemySkill
- litestar-autowireSkill
- litestar-deploymentSkill
- litestar-docsSkill
- litestar-emailSkill
- litestar-granianSkill
- litestar-htmxSkill
- litestar-mcpSkill
- litestar-queuesSkill
- litestar-saqSkill
- litestar-securitySkill
- litestarSkill
- litestar-styleguideSkill
- litestar-testingSkill
- litestar-viteSkill
- msgspecSkill
- polyfactorySkill
- pytest-databasesSkill
- sqlspecSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 4 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 27
All three paths assume the wheel is already complete — no bun run build happens at deploy/install time.
- Very specific: line 92
Run asset compilation, static template generation, and license collection before uv build --wheel --clear.
- Very specific: line 94
Use cargo zigbuild --release --target <arch>-unknown-linux-gnu.2.17 with BZIP2_SYS_STATIC=1 and LZMA_API_STATIC=1 when building portable …
- Distinctive: line 110
Every Litestar app with bundled assets has some variant of this:
- Very specific: line 163
Create install, build-assets, build-wheel.
- Very specific: line 169
PyApp — Simple: add [tool.hatch.build.targets.binary] to pyproject.toml, export PYAPP_* env vars (PYAPP_PROJECT_PATH, …
- Very specific: line 170
PyApp — Advanced: write a tools/bundler.py that pre-installs deps into a python-build-standalone archive, patches PyApp's src/app.rs for a …
- Very specific: line 175
Start with a reusable test.yml that accepts python-version + coverage inputs.
- Very specific: line 197
Pin
uvandbunversions in CI: Use exact pinned versions (e.g., UV_VERSION=0.13.9 and BUN_INSTALL_VERSION=bun-v1.4.4). - Very specific: line 199
Never commit built frontend output or
.litestar.json: Keep bundle_dir paths (including hot and hot.ssr) and .litestar.json in .gitignore. - Distinctive: line 209
Before claiming "the wheel builds":
- Distinctive: line 219
Before claiming "the PyApp binary works":
- Distinctive: line 227
Before claiming "CI works":
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
litestar-build
Build-side packaging patterns for Litestar applications: how to produce a self-contained wheel (uv_build or hatchling) that embeds the Vite/Bun frontend, how to wrap that wheel in a PyApp or scie-jump onefile binary, and how to wire the pipeline into GitHub Actions CI and releases.
This skill is the counterpart to litestar-deployment — build is about producing artifacts, deployment is about running them.
The Core Idea: One Wheel, Self-Contained
A Litestar wheel is the single source of truth for a release. It contains:
- Python code (
src/py/app/orapp/) - SQL migrations, Jinja templates, INI configs
- The built Vite/Bun frontend bundle (JS, CSS, HTML, images)
- Email templates rendered from React/MJX to static HTML
Once produced, that wheel can be:
pip installed into a container (litestar-deployment).- Wrapped in a PyApp binary (
dist/<app>,dist/app-x86_64-linux-gnu) for zero-dep distribution. - Uploaded to PyPI or a private index.
All three paths assume the wheel is already complete — no bun run build happens at deploy/install time.
Why bundle assets into the wheel (and not serve from a CDN)
| Property | Bundled wheel | External CDN |
| Deploy artifacts | 1 (.whl or binary) | 2+ (wheel + CDN upload) |
| Version alignment | Atomic — API and UI lock-step | Easy to skew; rollback is painful |
| PyApp onefile | Required — the binary embeds the wheel | Not possible — binary can't fetch CDN URLs at install time |
| Offline/air-gapped | Works | Doesn't |
| Dev server startup | Instant (files on disk next to package) | Fine |
| Frontend-only deploys | Rebuild + redeploy wheel | Push to CDN only |
For most Litestar apps that ship as a product (CLIs, internal tools, enterprise installers), bundled-in-wheel is correct. Projects like litestar-fullstack-inertia and litestar-fullstack all bundle.
Why litestar-vite configs look the way they do in reference apps
This is the piece most developers miss. The Vite/litestar-vite configs in the reference apps are deliberately set up so the Vite output lands inside the Python package directory — because that's what makes the wheel pick them up automatically.
litestar-fullstack (src/js/web/vite.config.ts):
export default defineConfig({
build: {
outDir: path.resolve(__dirname, "../../py/app/server/static/web"), // ← inside src/py/app/ (the Python package)
emptyOutDir: true,
},
plugins: [
litestar({
bundleDir: path.resolve(__dirname, "../../py/app/server/static/web"),
hotFile: path.resolve(__dirname, "../../py/app/server/static/web/hot"),
}),
],
})litestar-fullstack-inertia — in litestar-vite v0.30+, Python ViteConfig(paths=PathConfig(bundle_dir=...)) is the single source of truth and writes .litestar.json on startup/CLI invocation so litestar({ input: [...] }) in vite.config.ts inherits bundleDir, hotFile, and assetUrl automatically (and litestar assets build exports OpenAPI/routes metadata, runs TypeGenConfig codegen once with LITESTAR_VITE_SKIP_BUILD_TYPEGEN=1, installs node_modules if missing, and runs the Vite build):
from pathlib import Path
from litestar_vite.config import PathConfig, ViteConfig
def get_vite_config(base_dir: Path) -> ViteConfig:
"""Configure litestar-vite to emit assets inside the app/ Python package."""
return ViteConfig(
paths=PathConfig(
root=base_dir.parent,
bundle_dir=Path("app/domain/web/public"),
resource_dir=Path("resources"),
),
)Advanced reference pattern — same approach: Vite and the offline-report build write to src/py/<app>/server/public/ and src/py/<app>/domain/web/static/reports/offline/, both under the package root.
Contrast with a naïve vite build that writes to ./dist/ at the repo root: those files are outside the package directory listed in [tool.hatch.build.targets.wheel] packages = [...], so Hatchling silently drops them. The wheel ships without a frontend.
Rule: Vite's outDir and litestar-vite's bundle_dir must point inside one of the Python packages that Hatchling is told to include. Everything else flows from that.
Code Style Rules
- Emit all compiled frontend bundles (
PathConfig.bundle_dir/ Vitebuild.outDir) inside a Python package directory included by Hatchling (app/...orsrc/py/<pkg>/...). - Choose exactly one Hatchling asset inclusion strategy (
[tool.hatch.build.targets.wheel.force-include]ORignore-vcs = true) — never combine both. - Guard custom Hatchling build hooks (
BuildHookInterface.initialize) withif version == "editable":(warning tosys.stderr, creating the placeholder directory, and returning early when compiled assets do not exist yet) souv syncsucceeds before frontend assets are built, and excludetools/buildfrommypyandpyright. - Run asset compilation, static template generation, and license collection before
uv build --wheel --clear. - Treat
PYAPP_*configuration variables (PYAPP_PROJECT_PATH,PYAPP_PYTHON_VERSION,PYAPP_DISTRIBUTION_EMBED,PYAPP_DISTRIBUTION_VARIANT_GIL,PYAPP_SKIP_INSTALL) as compile-time inputs tocargo build/cargo zigbuild; at runtime, usePYAPP_INSTALL_DIR_<PROJECT_NAME>(where<PROJECT_NAME>is the uppercasedPYAPP_PROJECT_NAMEwith-replaced by_) to override the extraction directory and inspectos.getenv("PYAPP")("1"or path when built withPYAPP_PASS_LOCATION=1) to detect PyApp execution. - Use
cargo zigbuild --release --target <arch>-unknown-linux-gnu.2.17withBZIP2_SYS_STATIC=1andLZMA_API_STATIC=1when building portable Linux PyApp binaries, and ensure both$(uv tool dir --bin)($HOME/.local/bin) and$HOME/.cargo/binare onPATH/$GITHUB_PATHso the build never silently falls back tocargo build --releaseand binds to the runner's hostglibc.
Quick Reference
| Topic | Reference | Key Commands |
| Wheel build + asset bundling | references/wheel-assets.md | uv build --wheel --clear, uv_build, hatchling (force-include / ignore-vcs) |
| PyApp — simple (hatch-binary) | references/pyapp-simple.md | hatch build --target binary |
| PyApp — advanced (offline + custom install dir) | references/pyapp-advanced.md | tools/bundler.py build, cargo zigbuild |
Standalone onefile (a-scie/jump scie-jump) | references/scie-bundler.md | uv export, uv pip install --target, scie-jump --scie-jump |
| GitHub Actions CI (test matrix) | references/github-ci.md | astral-sh/setup-uv@v10.3.3, oven-sh/setup-bun@v2, composite actions |
| GitHub Actions release | references/github-release.md | matrix onefiles, cargo-zigbuild, gh release create |
| Upgrading Python / PyApp | references/upgrading.md | Files to edit in sync |
Canonical Makefile Build Graph
Every Litestar app with bundled assets has some variant of this:
.PHONY: install build-assets build-wheel build-onefile
install: ## Install Python + JS deps
@uv sync --all-groups
@cd src/js/web && bun install --frozen-lockfile
build-assets: ## Build frontend into the Python package
@uv run app assets install
@uv run app assets build
build-wheel: build-assets ## Self-contained Python wheel
@uv build --wheel --clear
build-onefile: build-wheel ## Single-file PyApp binary
@./tools/scripts/build-onefile-package.shThe dependency chain is load-bearing: build-onefile depends on build-wheel, which depends on build-assets. Running them out of order produces an empty or broken artifact.
The two-variant story
Real projects have multiple JS build outputs that all need to land in the wheel:
js-build-all: js-build-web js-build-offline-report
build-wheel: generate-licenses build-templates js-build-all
@uv build --wheel --clearEach js-build-* target emits into a distinct subdirectory of the Python package (src/py/<app>/server/public, src/py/<app>/domain/web/static/reports/offline, etc.). Because they're all inside the package, a single uv build --wheel --clear captures everything.
<workflow>Workflow
Step 1: Point Vite output inside the Python package
Configure ViteConfig(paths=PathConfig(bundle_dir=Path("app/domain/web/public"))) in Python so .litestar.json bridges the target directory to litestar-vite-plugin. If vite.config.ts overrides build.outDir directly (monorepo or standalone Vite build), set build.outDir and litestar({ bundleDir, hotFile }) to an absolute path inside your Python package (src/py/<pkg>/... or <pkg>/...). Do not let Vite default to ./dist/.
Step 2: Choose a build backend (uv_build vs hatchling)
uv_build(requires = ["uv_build>=0.13.0,<0.14.0"],build-backend = "uv_build"): fastest backend for pure-Python packages whose built assets live insidemodule-root/module-name([tool.uv.build-backend]options:module-root,module-name,source-include,source-exclude,wheel-exclude). Does not supportBuildHookInterfacehooks orhatch-binary.hatchlingforce-include(inertia): List built assets under[tool.hatch.build.targets.wheel.force-include]so built assets stay.gitignored.hatchlingignore-vcs = true(SPA): Ignore.gitignoreunderpackages = [...]; requires keeping dev junk out of package dirs.- Optional custom Hatchling hook: Guard
BuildHookInterface.initialize(version, build_data)withif version == "editable":(warn tosys.stderr, create placeholder dir, return early) souv syncsucceeds before assets exist, and excludetools/buildfrommypyandpyright.
See references/wheel-assets.md for full config.
Step 3: Wire Makefile targets
Create install, build-assets, build-wheel. Make the wheel target depend on the asset target. Pass --clear to uv build --wheel --clear so stale wheels in dist/ never get picked up by downstream packaging steps.
Step 4: Add a onefile bundler (if shipping a binary)
Decide which flavor:
- PyApp — Simple: add
[tool.hatch.build.targets.binary]topyproject.toml, exportPYAPP_*env vars (PYAPP_PROJECT_PATH,PYAPP_DISTRIBUTION_EMBED=1,PYAPP_FULL_ISOLATION=1,PYAPP_UV_ENABLED=1), and runhatch build --target binary. Good for standard OS baselines withselfCLI commands. See pyapp-simple.md. - PyApp — Advanced: write a
tools/bundler.pythat pre-installs deps into apython-build-standalonearchive, patches PyApp'ssrc/app.rsfor a custom default install dir, and runscargo zigbuild. Good for air-gapped distribution or bespoke install dirs. See pyapp-advanced.md. scie-jump(a-scie/jumpv1.13.0): stageuv export+ wheel viauv pip install --targetintopython-build-standalone, renderlift.json(load_dotenv: false,=PYTHONNOUSERSITE: "1",=PYTHONPATH: ""), and assemble per target with<host-scie-jump> --scie-jump <target-scie-jump> lift.json. Requires no Rust/Zig toolchain and builds Linux/macOS/Windows onefiles from one script. See scie-bundler.md.
Step 5: Add GitHub Actions CI
Start with a reusable test.yml that accepts python-version + coverage inputs. Call it from ci.yml across a matrix. Use astral-sh/setup-uv@v10.3.3 and oven-sh/setup-bun@v2. See github-ci.md.
For larger projects, factor setup-python and setup-node into .github/actions/ composite actions.
Step 6: Add release workflow
Trigger on v* tags. Run the test matrix first. Then build the wheel once. Then build PyApp onefiles in a per-target matrix (x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, Apple, Windows). Upload to gh release create. See github-release.md.
</workflow><guardrails>Guardrails
- Vite/bun output must land inside a Python package directory. Otherwise Hatchling drops it. Set
PathConfig.bundle_dir(and any explicit Vitebuild.outDir) to a path undersrc/py/<pkg>/or<pkg>/. uv buildruns last. Assets, licenses, templates, OpenAPI TypeGen all run beforeuv build --wheel --clear.- Pick one bundling strategy.
force-includeorignore-vcs = true, not both. Mixing them causes duplicate-file warnings and unpredictable wheel contents. - Skip or warn-only on editable installs in custom Hatchling hooks.
uv syncinstalls the project in editable mode (version == "editable") beforeuv run app assets buildcan execute. If a customBuildHookInterfaceruns inpyproject.toml(e.g.,path = "tools/build/hatch_build.py"), short-circuit whenversion == "editable"(warning tosys.stderr, creating the placeholder directory, and returning early instead of raisingValueErroror runningbun run build) and excludetools/buildfrommypy/pyrightunlesshatchlingis in the typecheck environment. - PyApp
PYAPP_*config vars are build-time (exceptPYAPP_INSTALL_DIR_<PROJECT_NAME>).PYAPP_PROJECT_NAME,PYAPP_PYTHON_VERSION,PYAPP_DISTRIBUTION_EMBED,PYAPP_DISTRIBUTION_VARIANT_GILare consumed whencargo buildcompiles PyApp — not when the resulting binary runs. At runtime, the compiled binary readsPYAPP_INSTALL_DIR_<PROJECT_NAME>(uppercasedPYAPP_PROJECT_NAMEwith-replaced by_; keep set forself remove/self restore) to override the extraction directory, and setsPYAPP=1(or the executable path whenPYAPP_PASS_LOCATION=1) inside the spawned Python process. - PyApp version upgrades touch multiple files.
pyproject.toml,build-onefile-package.sh,.github/workflows/release.yml,tools/bundler.py. See upgrading.md. cargo-zigbuildfor portable glibc — and verify it is onPATH. Plaincargo buildon a modern Linux runner links against the runner's hostglibc(e.g.GLIBC_2.39on Ubuntu 24.04), producing binaries that pass host smoke tests (./dist/app --help) but fail inside older distros or Debian Bookworm / distroless containers (GLIBC_2.36) withversion 'GLIBC_2.39' not found. Usecargo zigbuild --target x86_64-unknown-linux-gnu.2.17to link against glibc 2.17, add$(uv tool dir --bin)($HOME/.local/bin) and$HOME/.cargo/bintoPATH/$GITHUB_PATHafteruv tool install cargo-zigbuild, and never allow Linux CI builds to fall back silently tocargo build --release.- Static-link native deps in PyApp. Set
BZIP2_SYS_STATIC=1andLZMA_API_STATIC=1beforecargo zigbuild, or patchCargo.tomlto addfeatures = ["static"]. (In PyAppv0.29.0–v0.31.0,bzip2 = "0.6.0"uses the pure-Rustlibbz2-rs-sysbackend by default and has noxz/lzmadependency, so these flags are a harmless belt-and-suspenders safeguard that remain critical when pinning older PyApp releases.) - Pin
uvandbunversions in CI. Use exact pinned versions (e.g.,UV_VERSION=0.13.9andBUN_INSTALL_VERSION=bun-v1.4.4). Drift in either breaks reproducible builds. - Create placeholder asset dirs in CI. Hatchling's
force-includetarget fails ifapp/domain/web/publicorsrc/py/app/server/static/webdoesn't exist at wheel/editable-build time. CI jobs that don't build the frontend (lint, mypy, pyright) still needmkdir -p <asset-dir>beforeuv sync. - Never commit built frontend output or
.litestar.json. Keepbundle_dirpaths (includinghotandhot.ssr) and.litestar.jsonin.gitignore. CI rebuilds them on every run. Reason: JS builds are non-deterministic across machines and cause noisy diffs. - Coverage on one Python version only. Multiple versions uploading the same
coverage.xmlsilently stomp each other. Pin it to one version in your matrix (if: matrix.python-version == '3.12'). - Disk cleanup on CI runners (including PyApp scratch and runtime extraction dirs). GitHub's
ubuntu-latesthas ~30GB free; bundling large native wheels createsdist/.scratch(~1.2 GB) anddist/python-dist.tar.gz(~280 MB), and running./dist/<app> --helpon the runner host extracts ~750 MB into~/.<app>/runtime. Removedist/.scratch,dist/python-dist.tar.gz, and the extracted host runtime directory before running downstreamdocker/build-push-actionsteps.
</guardrails><validation>Validation Checkpoint
Before claiming "the wheel builds":
make build-wheelsucceeds in a clean checkout (aftermake install)unzip -l dist/*.whl | grep -E '\.(js|css|html)$'shows the built frontend- The wheel installs cleanly (
uv pip install dist/*.whlin a fresh venv) python -c "import app; app.run()"(or equivalent) serves assets with no extra steps.gitignoreexcludes the built asset directoryPathConfig.bundle_dir(and any explicit Vitebuild.outDir) resolves inside a Python package dir- Hatchling config uses exactly one of
force-includeORignore-vcs = true
Before claiming "the PyApp binary works":
dist/<app> --helpruns on the build machine- The binary is ≥ 50 MB (much smaller means it's not embedding Python)
- On Linux,
ldd dist/<app>shows ≤ libc / libm / libpthread (nolibbz2, noliblzma) - A network-isolated
docker run --rm --network=none gcr.io/distroless/cc-debian13:nonroot /opt/dist/<app> --helpsucceeds (proves no runtime PyPI fetches) - The install dir (
~/.<app>/runtime/or similar) is created on first run and re-used on second run
Before claiming "CI works":
- Python matrix covers minimum + stable + latest (e.g., 3.11, 3.12, 3.13)
make build-wheelruns in CI and the resulting wheel is uploaded as an artifact- Pre-commit / ruff / mypy / pyright / slotscheck run on every PR
- Release workflow is gated on CI (
needs: [lint, test]) - A tag push produces wheel + onefiles + GitHub release in one run
</validation><example>Example
[build-system]
build-backend = "hatchling.build"
requires = ["hatchling"]
[tool.hatch.build.targets.wheel]
packages = ["app"]
[tool.hatch.build.targets.wheel.force-include]
"app/domain/web/public" = "app/domain/web/public"
[tool.hatch.build.targets.binary]
pyapp-version = "0.31.0"
python-version = "3.13"
scripts = ["app"]# Hatchling's binary builder reads PYAPP_* from the process environment (not pyproject.toml)
PYAPP_DISTRIBUTION_EMBED=1 PYAPP_FULL_ISOLATION=1 PYAPP_UV_ENABLED=1 \
hatch build --target binaryExample Projects
- litestar-fullstack-inertia — monolithic
app/layout, Inertia.js + React 19,force-includebundling,hatch build --target binaryfor 4-platform PyApp. - litestar-fullstack — nested
src/py/app/+src/js/web/layout, React + TanStack Router SPA,ignore-vcs = truebundling, React Email templates.
</example>References Index
- Wheel Build + Asset Bundling
- PyApp — Simple (hatch-binary)
- PyApp — Advanced (offline, custom install dir, portable glibc)
- Standalone Onefiles (
a-scie/jumpscie-jump) - GitHub Actions — CI (Test Matrix)
- GitHub Actions — Release
- Upgrading — Python, PyApp, python-build-standalone
Official References
- https://ofek.dev/pyapp/ — PyApp documentation (all
PYAPP_*env vars) - https://github.com/ofek/pyapp — PyApp source (patch target:
src/app.rs) - https://github.com/a-scie/jump —
scie-jumponefile launcher andlift.jsonspec - https://hatch.pypa.io/latest/config/build/ — Hatchling build config
- https://hatch.pypa.io/latest/plugins/builder/binary/ — Hatch binary builder (simple PyApp)
- https://docs.astral.sh/uv/concepts/build-backend/ —
uv_buildbackend configuration - https://docs.astral.sh/uv/concepts/projects/build/ —
uv buildreference - https://github.com/astral-sh/python-build-standalone/releases — Portable Python archives
- https://github.com/rust-cross/cargo-zigbuild — cargo-zigbuild for portable glibc
- https://bun.sh/docs/cli/install — Bun install and lockfile
Cross-References
- litestar-deployment — runtime deployment (Dockerfiles, K8s, Railway, Cloud Run, systemd) that consumes the artifacts this skill produces
- litestar-vite — Vite plugin config (asset pipeline details, TypeGen, HMR)
- litestar-granian — Granian ASGI server (what the wheel's entry-point starts)
- litestar settings — env-driven
@dataclasssettings that work both in-wheel and as a PyApp binary
Shared Styleguide Baseline
- General Principles
- Python
- CI/CD
- Litestar
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

