GeoAlchemy 2 Documentation

Using SQLAlchemy with Spatial Databases.

GeoAlchemy 2 aims to be simpler than its predecessor, in terms of both usage, and maintainance.

GeoAlchemy 2 requires SQLAlchemy 0.8; it does not work with SQLAlchemy 0.7 and lower.

GeoAlchemy 2 supports PostGIS 2.0 and PostGIS 1.5.

GeoAlchemy 2 doesn’t currently support other dialects than PostgreSQL/PostGIS. Supporting Oracle Locator in the previous series was the main contributor to code complexity. So it is currently not clear whether we want to go there again. Please contact us you want to add, and maintain, support for other spatial databases in GeoAlchemy 2.

What’s New in GeoAlchemy 2

The first series had its own namespace for spatial functions, namely geoalchemy.functions. With GeoAlchemy 2, spatial functions are called like any other function, using func, which is SQLAlchemy’s standard way of calling SQL functions.

GeoAlchemy 2 works with SQLAlchemy’s ORM, as well as with SQLAlchemy’s SQL Expression Language (a.k.a the SQLAlchemy Core). This is thanks to SQLAlchemy’s new type-level comparator system.

GeoAlchemy 2 supports PostGIS’ geometry type, as well as geography type.

GeoAlchemy 2 supports reflection of geometry and geography columns.

GeoAlchemy 2 adds to_shape, from_shape functions for a better integration with Shapely.

See the Migrate to GeoAlchemy 2 page for details on how to migrate a GeoAlchemy application to GeoAlchemy 2.


GeoAlchemy 2 works with both SQLAlchemy’s Object Relational Mapping (ORM) and SQL Expression Language. This documentation provides a tutorial for each system. If you’re new to GeoAlchemy 2 start with this.


The code is available on GitHub:


Many thanks to Mike Bayer for his guidance and support! He also fostered the birth of GeoAlchemy 2.

Indices and tables

Project Versions

Table Of Contents

Next topic

Migrate to GeoAlchemy 2

This Page