Setup

For your first steps, simply follow Getting Started with Pony to create the database object and define your models. You may want to make use of Pydantic’s inbuilt BaseSettings Model to manage your connection secrets. The specific parameters can be found in Connecting to the Database.

  1. import fastapi
  2. from src.config import Settings
  3. from src.models import db
  4. settings = Settings()
  5. api = fastapi.FastAPI()
  6. db.bind(**settings.get_connection)
  7. db.generate_mapping(create_tables=True)