skillfed

GeoAlchemy2

Using SQLAlchemy with Spatial Databases

geoalchemy2 v0.20.0 5.2M downloads/30d#2,152 on PyPI709
Permissive license MIT Active released

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 geoalchemy2

uv

uv add geoalchemy2

poetry

poetry add geoalchemy2

Installing 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

Development Status :: 4 - BetaEnvironment :: PluginsIntended Audience :: Information TechnologyOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Topic :: Scientific/Engineering :: GIS

Tags

sqlalchemy spatial databasegis orm pythongeographic data sqlalchemyspatial queries ormgeospatial database mappingspatial orm
gisspatial-dataorm

More GIS packages