Docs / Guides / Storage & route cache

Platform 16–17 · Study guide

Storage & route cache

Store files on disk (S3-ready API) and cache the route table for ops tooling.

What you will learn
  • How to read/write files via Storage
  • How to build and list a route cache
  • How optimize ties config + routes together

1. File storage setup

from tpy.storage import Storage

disk = Storage.disk("local")
disk.put("reports/hello.txt", b"hello")
raw = disk.get("reports/hello.txt")
disk.delete("reports/hello.txt")

Local files land under the project storage disk root. The API is intentionally driver-shaped so an S3 disk can plug in later without rewriting callers.

2. Route cache setup

$ tpy serve   # app must import cleanly
$ tpy route cache --app app.main:app
$ tpy route list --cached
$ tpy route clear

Writes storage/framework/routes.cache.json by importing your FastAPI app and collecting routes.

3. How route cache helps

  • Inspect routes without booting heavy middleware every time.
  • Ship a snapshot for ops/docs generation.
  • Combine with tpy optimize for production warm caches.