Database Configuration
Astris provides an out-of-the-box database layer powered by SQLModel, SQLAlchemy 2.0, and Alembic.
Connection Strings & Database Drivers (DATABASE_URL)
Set your database connection URL in your project's .env file:
SQLite (Default for Local Development)
Built into Python with zero dependencies required:
ini
DATABASE_URL=sqlite:///database/app.dbPostgreSQL
Requires the psycopg2-binary driver:
bash
uv add psycopg2-binaryConnection URL:
ini
DATABASE_URL=postgresql://user:password@localhost:5432/my_databaseMySQL / MariaDB
Requires the pymysql driver:
bash
uv add pymysqlConnection URL:
ini
DATABASE_URL=mysql+pymysql://user:password@localhost:3306/my_databaseDriver Diagnostics
If a required driver is missing when your application starts, Astris catches the error and provides an immediate, actionable installation hint:
text
RuntimeError: Missing database driver 'psycopg2' for postgresql database.
To resolve, run:
uv add psycopg2-binaryAutomatic Table Creation (AUTO_CREATE_TABLES)
Astris manages table creation based on your environment:
- Local Development (
APP_ENV=local): Defaults toTrue. All tables defined inapp/modules/*/*_model.pyare automatically created on startup for instant development velocity. - Production (
APP_ENV=production): Defaults toFalse. Automatic table creation is disabled to prevent accidental schema changes. Useuv run orbit migrateto apply versioned migrations.
You can explicitly override this behavior in .env:
ini
AUTO_CREATE_TABLES=falseEngine Configuration
The database engine is configured automatically by the Astris kernel on startup via astris.database.db.
You can configure query logging in .env:
ini
# Print raw SQL queries to console
DB_ECHO=trueNext Steps
- Define tables and models: SQLModel Models.
- Execute queries and transactions: Queries & CRUD.
- Run schema migrations: Alembic Migrations.