Guide · Open source
How to use SQLAlchemy: install it and what it does
Updated · written with AI from the project's own documentation and checked against our catalogue data
SQLAlchemy is an MIT-licensed Python library for working with relational databases. It gives you a SQL toolkit for building queries in Python code and an object-relational mapper (ORM) that lets you work with database rows as Python objects. This guide explains how to install it, what its two main parts do, and whether it suits your project.
Quick start
- 1Confirm your Python version. Check that you are running Python 3.11 or newer, the version this guide infers from available wheel builds.
- 2Install from PyPI. Run pip install sqlalchemy in your project environment to install the library from PyPI.
- 3Decide between the SQL toolkit and the ORM. Choose the SQL toolkit if you want to control the exact SQL your code produces, or the ORM if you want database rows represented as Python objects.
- 4Read the official documentation. Visit https://www.sqlalchemy.org for usage examples, since the README provided here does not include them.
Install SQLAlchemy with pip
SQLAlchemy is distributed on PyPI, so you install it with your Python package manager. The project's README gives this command for installing from PyPI.
- Requires Python 3.11 or newer. This is inferred from the available wheel builds, not stated as an official requirement, so check the project's documentation if you are on an older interpreter.
pip install sqlalchemyUnderstand the SQL toolkit and the ORM
SQLAlchemy has two main layers. The SQL toolkit lets you build queries in Python code, which helps you keep the SQL your application produces visible and under your control. The object-relational mapper (ORM) lets you read and write database rows as Python objects instead of writing every statement by hand.
Teams that want control over generated SQL often start with the toolkit, while teams that want rows represented as objects use the ORM. You can choose the layer that fits each part of your application.
Use it to keep database access portable
Developers use SQLAlchemy to keep database access organized and portable across database engines. If your project may need to move between database engines later, this is one of the main reasons to build on it.
The README given for this directory entry is truncated and does not include detailed usage examples. For API examples such as connecting to a database or defining models, use the official documentation at https://www.sqlalchemy.org rather than relying on this page.
Check whether SQLAlchemy fits your project
SQLAlchemy is built for relational databases and is a Python library. It is a good fit for Python developers building applications backed by a SQL database. It is not a good fit if you only need a simple key-value or document store, if your project is not written in Python, or if you have no SQL or Python background, since the README does not provide a beginner tutorial.
- Good fit: Python applications backed by a SQL database
- Good fit: teams that want control over the SQL their code produces
- Good fit: projects that may need to switch database engines
- Poor fit: key-value or document storage needs
- Poor fit: non-Python projects
- Poor fit: complete beginners with no SQL or Python background
What people use it for
- Building a Python web application backed by a relational SQL database
- Writing queries in Python code while keeping control over the SQL produced
- Working with database rows as Python objects through the ORM
- Organizing database access in a project that may switch between database engines later
Frequently asked questions
Is SQLAlchemy free to use?
Yes. SQLAlchemy is released under the MIT licence, which is a permissive open-source licence. Check the licence text in the project repository if you need the exact terms for your use.
How do I install SQLAlchemy?
Install it from PyPI with pip install sqlalchemy. It is a Python library, so it is installed in the Python environment your project uses.
What Python version does SQLAlchemy require?
This guide infers Python 3.11 or newer from the available wheel builds. It is not stated as an official requirement in the source, so confirm it in the official documentation.
What is the difference between the SQL toolkit and the ORM?
The SQL toolkit lets you build queries in Python code and keeps the SQL visible. The ORM maps database rows to Python objects so you can work with them as objects instead.
What are alternatives to SQLAlchemy?
Comparable projects listed for this entry include the Django ORM, Peewee, Tortoise ORM and Pony ORM. Each has different design choices, so compare them against your project's needs.
Can SQLAlchemy be used with non-Python projects?
No. SQLAlchemy is a Python library, so it is only useful for Python projects. Non-Python projects should look for a library in their own language.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
SQLAlchemy suits Python developers building applications on a SQL database, especially those who want control over their SQL or may need to switch database engines later. Pick something else if you only need a key-value or document store, use a non-Python language, or are new to both SQL and Python, since the README offers no beginner tutorial.
Install options & downloads