SQLAclhemy is the de facto framework for dealing with relational databases in Python. It was created by Mike Bayer in 2005. SQLAlchemy allows you to work with MySQL, MS-SQL, PostgreSQL, Oracle, SQLite and other databases.
Why use SQLAlchemy
The most important feature of SQLAlchemy is its ORM. ORM or Object Relational Mapper allows you to work with a database using object-oriented code without using SQL queries. Another feature of SQLAlchemy is that the application code will remain the same regardless of the database used. This allows you to easily migrate from one database to another without rewriting the code. SQLAlchemy has a component called SQLAlchemy Core. It is an abstraction over traditional SQL. It provides an SQL Expression Language that allows you to generate SQL statements using Python constructs. Unlike ORM, which focuses on models and objects, Core focuses on tables, columns, indexes, and so on (similar to conventional SQL). SQL Expression Language is very similar to SQL, but it is standardized, so it can be used in different databases. SQLAlchemy ORM and Core can be used independently of each other. Under the hood, SQLAlchemy ORM uses Core.
So which to use: Core or ORM?
The point of ORM is to simplify the database process. In the process adds some complexity, but it is imperceptible if you are not working with very large amounts of data. For most projects ORM will be enough, but where there is a lot of data, it is worth working with pure SQL.
Who uses SQLAlchemy
- Fedora Project
- and many others.
You need to have a basic knowledge of Python and SQL to understand the tutorial.
- Installing SQLAlchemy and connecting to the database.
- Creating a database schema in SQLAlchemy Core.
- Performing CRUD operations with SQLAlchemy Core.
- Creating a database schema in SQLAlchemy ORM.
- Performing a CRUD operation with the SQLAlchemy ORM.