Platform 09–10 · Study guide
Boot services through Application, providers, and optional plugins — dual-mode with FastAPI.
from tpy.kernel import Application
def create_app():
return (
Application(base_path=".")
.with_framework_providers()
.register(AppServiceProvider)
.create(title="My App")
)
Point uvicorn at this factory, or call it from app/main.py.
from fastapi import FastAPI
from tpy.kernel import Application
api = FastAPI()
Application(".").with_framework_providers().mount(api)
# api.state.tpy is the Application
from tpy.kernel import ServiceProvider, Application
from tpy.cache import Cache, MemoryStore
class CacheServiceProvider(ServiceProvider):
def register(self, app: Application) -> None:
app.singleton("cache", lambda c: Cache(MemoryStore()))
def boot(self, app: Application) -> None:
# all bindings exist; safe to resolve
app.make("cache").put("booted", True, ttl=30)
register() runs first (bindings only).boot() runs (can resolve dependencies).app.make("cache").app/main.py still works without the kernel (soft-break). Adopt Application when you need shared services, plugins, lifecycle, and health wiring.