GeoAlchemy2
Using SQLAlchemy with Spatial Databases
What it is and what it does
GeoAlchemy2 is a Python toolkit that bridges SQLAlchemy and spatial databases, allowing you to work with geographic data types and spatial queries through an ORM interface. It builds on SQLAlchemy's declarative system to map geographic columns and operations to database-native spatial types, letting you query and manipulate geographic data using Python objects rather than raw SQL.
The package is designed for applications that need to store, retrieve, and analyze geographic information—such as location-based services, mapping applications, or GIS analysis workflows. It handles the translation between Python spatial objects and the spatial data types supported by your underlying database, abstracting away database-specific SQL syntax for common geographic operations.
Use it for:
- Build location-based web services that query geographic points, polygons, or routes stored in a spatial database
- Develop GIS analysis tools that need to perform spatial operations like distance calculations or intersection tests through an ORM
- Create mapping applications that store and retrieve geographic features alongside relational data
- Implement geofencing or proximity-based filtering in applications backed by a spatial database
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
GeoAlchemy2 extends SQLAlchemy to work with spatial databases, providing an ORM layer for geographic data types and operations.
Yes. GeoAlchemy2 is actively maintained, has low install friction, carries a permissive MIT license, and fills a clear need for ORM-based spatial database access. It is well-established and supports current Python versions. Install it if you need to work with geographic data in a SQLAlchemy-based application.
Install
geoalchemy2 on PyPI
pip
pip install geoalchemy2uv
uv add geoalchemy2poetry
poetry add geoalchemy2Installing GeoAlchemy2
Before you install
Low friction installation with only two runtime dependencies (SQLAlchemy and packaging). Active maintenance with recent releases and a stable repository.
License in practice
MIT license permits commercial and private use with minimal restrictions.
Quickstart
pip install geoalchemy2
from geoalchemy2 import Geometry
from sqlalchemy import Column, Integer, create_engine
from sqlalchemy.orm import declarative_base
Base = declarative_base()
class Location(Base):
__tablename__ = 'locations'
id = Column(Integer, primary_key=True)
geom = Column(Geometry('POINT'))
Requires a spatial database backend (such as PostGIS) to be installed and configured separately; Python 3.10 or later.
Verify before relying
- Which spatial database backends are supported (PostGIS, SpatiaLite, etc.)
- Whether a spatial database system must be installed separately
- Performance characteristics for large geographic datasets
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — SQLAlchemy, packaging |
| Maintenance | actively maintained — 94 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 5,163,891/month — #2,152 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: geoalchemy2-0.20.0-py3-none-any.whl
Keywords: geo, gis, sqlalchemy, orm
Tags
More GIS packages
Shapely provides Python tools for creating,…
permissive · top 1,000 on PyPI
pyprojpyproj provides a Python interface to PROJ,…
permissive · top 1,000 on PyPI
geopandasGeoPandas extends pandas DataFrames to handle…
permissive · top 1,000 on PyPI
geopygeopy is a Python client for geocoding and…
permissive · top 5,000 on PyPI
pyogrioPyogrio provides fast, bulk-oriented read and…
permissive · top 5,000 on PyPI
h3h3 provides Python bindings to Uber's H3…
permissive · top 5,000 on PyPI
SQLAlchemySQLAlchemy is a Python SQL toolkit and Object…
permissive · top 100 on PyPI
pygeofilterParses OGC filtering standards (CQL, CQL JSON,…
permissive · top 15,000 on PyPI
osmiumosmium provides Python bindings for the…
permissive · top 15,000 on PyPI
sqlalchemy-jdbcapiSQLAlchemy dialect for JDBC and ODBC database…
permissive · top 15,000 on PyPI
geodatasetsGeodatasets provides a curated database of…
permissive · top 15,000 on PyPI
geoarrow-cgeoarrow-c provides low-level Python bindings…
permissive · top 15,000 on PyPI
Flask-SQLAlchemyFlask-SQLAlchemy integrates SQLAlchemy database…
permissive · top 1,000 on PyPI
sqlalchemy-firebirdProvides a SQLAlchemy 2.0+ dialect for…
permissive · top 15,000 on PyPI
cmeel-octomapProvides Python bindings to OctoMap, a 3D…
unclear · top 15,000 on PyPI