What is the difference between SQLAlchemy Core and ORM?

The ORM is, as the name implies, an object-relational mapper: Its purpose is to represent database relations as Python objects.

The core is a query builder. Its purpose is to provide a programmatic means to generate SQL queries (and DDL) — but the results of those queries are just tuples (with a little extra magic), not objects of your own (“your” being, in this case, “the application developer’s”) design.

In general, if you’re trying to programmatically build queries (particularly based on information only available at runtime), you should be using the core. If you’re trying to build your application MVC-style and want database-backed objects to be the “model”, you should be using the ORM.

Leave a Comment