Docs / Guides / Optimize · CLI · Watch

Platform 18–20 · Study guide

Optimize · CLI · Watch

Ship faster boots, explore the CLI professionally, and rebuild when schema.tpy changes.

What you will learn
  • How tpy optimize prepares production caches
  • Which DX commands to use daily
  • How watch mode rebuilds on schema edits

1. Optimize (config + routes)

$ tpy optimize
$ tpy optimize --skip-routes
$ set TPY_CONFIG_CACHE=1
  1. Writes config cache JSON.
  2. Imports the app and writes route cache (unless --skip-routes).
  3. With TPY_CONFIG_CACHE=1, boots prefer the fresh config cache.

2. Better CLI (study these first)

CommandWhat it teaches you
tpy -V / tpy versionInstalled framework version
tpy aboutEnv + project diagnostics
tpy commandsFull command map
tpy doctorScaffold health

3. Watch mode setup

# terminal A — API
$ tpy serve --reload

# terminal B — schema rebuilds
$ tpy watch
$ tpy watch --with-db
$ tpy watch --interval 0.5

4. How watch works

  1. Polls mtimes of schema.tpy and tpy.toml (stdlib only — no extra deps).
  2. On change, runs tpy build --skip-db (or full build with --with-db).
  3. You still run tpy migrate yourself when tables change.
Watch rebuilds code. Migrate changes the database. Serve reloads Python. All three are separate on purpose.