SQLAlchemy offers tools for database schema generation, querying, and object-relational mapping.
It has evolved to include a wide range of features for database interaction and has gained popularity among Python developers.
Notable versions include: The following example represents an n-to-1 relationship between movies and their directors.
It is shown how user-defined Python classes create corresponding database tables, how instances with relationships are created from either side of the relationship, and finally how the data can be queried — illustrating automatically generated SQL queries for both lazy and eager loading.
Creating two Python classes and corresponding database tables in the DBMS: One can insert a director-movie relationship via either entity: SQLAlchemy issues the following query to the DBMS (omitting aliases): The output: Setting lazy=True (default) instead, SQLAlchemy would first issue a query to get the list of movies and only when needed (lazy) for each director a query to get the name of the corresponding director: