# agronholm/sqlacodegen

Automatic model code generator for SQLAlchemy

Repository: https://github.com/agronholm/sqlacodegen
Canonical: https://ross.abutalabs.com/products/sqlacodegen
Language: Python
License: NOASSERTION
License Family: other
Last push: 2026-07-06T19:30:06+00:00

## Health v2 (maintenance only)
Score: 92/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 91, release rhythm 89, longevity 100
- inputs: {"age_days": 3535, "days_push": 58, "days_rel": 75, "gap_med": 17, "n_releases_24m": 12}
- flags: no_license
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 2365, forks 284 (observed 2026-08-28T04:06:41.553563+00:00)

## What it is
sqlacodegen is a command-line tool that reads the structure of an existing database and generates SQLAlchemy model code, preferring declarative style. It supports SQLAlchemy 2.x, produces PEP 8 compliant output, and accurately detects relationships including many-to-many and one-to-one.

## Use cases
- generate SQLAlchemy models from an existing database schema
- reverse engineer a PostgreSQL database into declarative model classes
- create SQLAlchemy dataclass models from a SQLite database
- generate ORM code for a MySQL database
- bootstrap ORM models for a legacy database
- introspect database tables and relationships into Python code

## When to choose
- you have an existing database and want SQLAlchemy models without writing them by hand
- you need accurate relationship detection including many-to-many and joined table inheritance
- you want PEP 8 compliant, hand-written-looking declarative code
- you need support for PostgreSQL extension types like CITEXT, PostGIS geometry, or pgvector

## When to avoid
- you are designing models first and want migrations from models to database (use Alembic instead)
- you use an ORM other than SQLAlchemy
- you need a GUI-based database modeling tool

## Facets
- artifact type: cli-tool
- maturity: active
- function: orm, database, cli
- domain: databases, developer-tools, backend
- platform: python, cli, cross-platform
- tags: sqlalchemy, model-generation, database-introspection, reverse-engineering, declarative-models, code-generation

## Member repositories
- agronholm/sqlacodegen (main) score 92

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:06:41.553563+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T02:35:59.528290+00:00, confidence not recorded.
  - readme: https://github.com/agronholm/sqlacodegen (fetched 2026-08-28T04:06:41.553563+00:00, sha efee150c84f6)
  - registry_pypi: https://pypi.org/pypi/sqlacodegen/json (fetched 2026-08-29T10:16:29.779669+00:00, sha 2743321b48a8)
- Data as of 2026-08-30T08:39:29.467469+00:00.
