finds.dev← search

// the find

agronholm/sqlacodegen

★ 2,356 · Python · NOASSERTION · updated Jul 2026

Automatic model code generator for SQLAlchemy

sqlacodegen introspects a live database and generates SQLAlchemy model code from the actual schema — declarative classes, dataclasses, or SQLModel, your pick. It's the go-to tool when you're handed an existing database and need Python models without writing them by hand. Actively maintained, supports SQLAlchemy 2.x, and ships pgvector support.

Relationship inference is genuinely good — it correctly identifies many-to-one, one-to-one, and many-to-many from foreign key and unique constraints without you having to annotate anything. Multiple output targets (plain Table objects, declarative, dataclasses, SQLModel) means you can drop it into whatever style your project already uses. The extension type support is broader than you'd expect: citext, geoalchemy2, pgvector all covered as optional extras. The customization story via entry points is clean — subclass a generator, register it, use it with --generator; no forking required.

Generated code is a starting point, not a destination — relationship names and class names routinely need hand-editing, especially on schemas that don't follow tidy naming conventions. The inflect option for singularizing class names is off by default because it's unreliable, which means you get PluralClass names out of the box and have to clean them up. No incremental or diff mode: if your schema evolves, you re-run and get a full regeneration rather than a patch against what you already have. SQLModel generator explicitly doesn't support many-to-many relationships, which is a significant gap if you're on that stack.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →