Generate a FastAPI starter using current Pydantic 2 and FastAPI conventions, avoiding the deprecated patterns most online examples still use.
Hyphens become underscores in the import package, because a hyphen is not a valid Python identifier.
15 files, internally consistent.
Imports, dependencies, scripts and configuration agree. Nothing was compiled or run — see Checks.
my_api/__init__.pyMakes the directory a package, which is what lets the relative imports below resolve.
"""my-api."""
__version__ = "0.1.0"
Written against Pydantic 2 and FastAPI 0.115. The output uses model_config = ConfigDict(…) rather than an inner class Config, model_dump() rather than dict(), BaseSettings from pydantic_settings, str | None rather than Optional[str], and datetime.now(UTC) rather than the deprecated datetime.utcnow(). Pydantic 1 examples will not work against it.
FastAPI Scaffold runs entirely on your device — the files are generated in your browser from templates built into the page. No Python runs here, nothing is installed, and your project name and options are not sent anywhere.
You’re on the Free plan. Compare plans
Most FastAPI examples you will find are Pydantic 1, and Pydantic 1 and 2 are not source compatible. Code copied from one into a project running the other either fails on import or warns now and breaks on the next release.
This generates the current forms, and lists them on the page so you can check them against whatever you were reading. A lifespan context manager rather than the deprecated startup and shutdown decorators. `model_config = ConfigDict(...)` rather than an inner `class Config`. `model_dump()` rather than `dict()`. `BaseSettings` from `pydantic_settings`, which is where it moved. `str | None` rather than `Optional[str]`. `Annotated[Store, Depends(get_store)]` rather than a dependency hiding in a default argument. And `datetime.now(UTC)` rather than `datetime.utcnow()`, which is deprecated and returns a value that compares wrongly against anything timezone-aware.
The structure is arranged so the example can be replaced rather than deleted. The store is injected rather than imported, so a real database swaps in without touching the routes. Request and response models are separate, so a client cannot supply an id or a creation time — the most common way an API ends up trusting input it should not. Unknown fields are rejected rather than dropped, so a misspelled field name is an error.
Every file is checked against the others: relative imports resolve against the generated package, absolute imports of the project's own package resolve too, each third-party import is in the requirements, and the environment example is checked for anything that looks like a working credential.
No Python runs here. Nothing is installed, imported or compiled, and the page says so. The templates themselves are parsed with CPython's own parser in this site's test suite, which is a real guarantee about their syntax and nothing more.
Because that is where it moved in Pydantic 2. Importing it from pydantic raises an error naming the new package, so a generator emitting the old import produces code that cannot even start.
The decorators are deprecated, and the context manager is better anyway: setup and the matching teardown live in one function, so a resource opened at startup cannot be forgotten at shutdown.
Because one shared model lets a client send an id or a created-at value. Splitting them means the fields the server owns exist only on the way out.
Structurally. Imports resolve, requirements match what is imported, and the project configuration is consistent. No interpreter runs in your browser, so nothing is imported or executed, and the page does not claim otherwise.
No, on purpose. The store is a dictionary behind an injected class, so you can replace it with a real one without touching the routes — which is the part worth generating.
If a tool here saved you some time, you can put something towards the hosting.Buy me a coffee, on Ko-fi, opens in a new tab