Requirements
SQLAlchemy requires Python 3.10 or higher.
Before installing SQLAlchemy, ensure you have:
- Python 3.10, 3.11, 3.12, 3.13, or 3.14
- pip (comes with Python) or another package manager
typing-extensions >= 4.6.0 (installed automatically as a dependency)
Install with pip
Install SQLAlchemy
Install the latest version of SQLAlchemy using pip:This installs the core library with all essential dependencies. Verify installation
Check that SQLAlchemy is installed correctly:python -c "import sqlalchemy; print(sqlalchemy.__version__)"
You should see the version number (e.g., 2.1.0b2).
Install with conda
If you’re using Anaconda or Miniconda:
conda install -c conda-forge sqlalchemy
Database Drivers
SQLAlchemy requires a database driver (DBAPI) to connect to databases. Install the appropriate driver for your database:
PostgreSQL
MySQL / MariaDB
SQLite
Oracle
Microsoft SQL Server
pip install "SQLAlchemy[postgresql]"
psycopg (version 3) is the recommended driver for PostgreSQL. For async support, use asyncpg.
pip install "SQLAlchemy[mysql]"
SQLite support is included with Python’s standard library - no additional driver needed!pip install "SQLAlchemy[aiosqlite]"
SQLite is perfect for development, testing, and small applications. No server setup required.
pip install "SQLAlchemy[oracle]"
Oracle Database 12c and higher are supported. oracledb is the modern driver recommended by Oracle.
pip install "SQLAlchemy[mssql]"
Async Support
For asynchronous database operations, install the asyncio extra:
pip install "SQLAlchemy[asyncio]"
This installs greenlet>=1, which is required for async functionality.
Async support requires Python 3.10+ and a compatible async database driver like asyncpg, aiomysql, or aiosqlite.
Development Installation
To install from source for development:
Clone the repository
git clone https://github.com/sqlalchemy/sqlalchemy.git
cd sqlalchemy
Install development dependencies (optional)
pip install pytest pytest-xdist
Optional Dependencies
SQLAlchemy offers several optional dependency groups:
Type Checking with mypy
pip install "SQLAlchemy[mypy]"
Installs mypy >= 1.19 and types-greenlet >= 2 for static type checking support.
Multiple Drivers
You can install multiple database drivers at once:
pip install "SQLAlchemy[postgresql,mysql,asyncio]"
Verify Installation
Confirm your installation by running a simple test:
import sqlalchemy
from sqlalchemy import create_engine
# Print version
print(f"SQLAlchemy version: {sqlalchemy.__version__}")
# Test SQLite connection (no driver needed)
engine = create_engine("sqlite:///:memory:")
with engine.connect() as conn:
result = conn.execute(sqlalchemy.text("SELECT 'Hello SQLAlchemy' as message"))
print(result.fetchone())
Expected output:
SQLAlchemy version: 2.1.0b2
('Hello SQLAlchemy',)
Next Steps
Quick Start
Build your first SQLAlchemy application
Documentation
Explore comprehensive tutorials and API reference
Troubleshooting
If you encounter issues during installation:
- Ensure you’re using Python 3.10 or higher:
python --version
- Upgrade pip:
pip install --upgrade pip
- Check for conflicting packages:
pip list | grep -i sqlalchemy
- Visit the SQLAlchemy discussion forum