Skip to Content
Apso is in public beta. Get started
GuidesFrameworksPython (FastAPI)Overview

Python with FastAPI

The Python template combines FastAPI, async SQLAlchemy 2, Pydantic 2, Alembic, and pytest. Apso generates models, request schemas, routers, and services into app/autogen/.

Requirements

  • Python 3.11 or newer
  • PostgreSQL
  • @apso/cli

Create and run a project

apso init --name my-api --language python --skip-platform cd my-api python -m venv .venv source .venv/bin/activate pip install -e ".[dev]" apso generate apso dev

On Windows, activate the environment with .venv\Scripts\activate.

Generated structure

my-api/ ├── .apsorc ├── alembic/ ├── app/ │ ├── main.py │ ├── database.py │ ├── autogen/ │ │ ├── models/ │ │ ├── routers/ │ │ ├── schemas/ │ │ └── services/ │ └── extensions/ ├── tests/ └── pyproject.toml

Do not edit app/autogen/. Put custom routers, middleware, services, and business rules in app/extensions/.

API documentation

With the service running on the template’s default port, open:

  • Swagger UI: http://localhost:3000/_docs
  • ReDoc: http://localhost:3000/_redoc

Manage database migrations

The Python template uses Alembic:

alembic revision --autogenerate -m "add project status" alembic upgrade head alembic downgrade -1

Use apso migrate when you want Apso to preview the schema change and generate a language-native migration.

Test and check the project

pytest ruff check app tests black --check app tests mypy app
Last updated on