Docs / Guides / Application kernel

Platform 09–10 · Study guide

Application kernel

Boot services through Application, providers, and optional plugins — dual-mode with FastAPI.

What you will learn
  • create() vs mount() modes
  • How ServiceProviders register and boot
  • How to resolve services from the container

1. Setup — recommended create()

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.

2. Setup — mount onto existing FastAPI

from fastapi import FastAPI
from tpy.kernel import Application

api = FastAPI()
Application(".").with_framework_providers().mount(api)
# api.state.tpy is the Application

3. How providers work

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)
  1. Every provider register() runs first (bindings only).
  2. Then every boot() runs (can resolve dependencies).
  3. Fetch services with app.make("cache").
Generated app/main.py still works without the kernel (soft-break). Adopt Application when you need shared services, plugins, lifecycle, and health wiring.