Skip to main content

SQLAlchemy GeoServer Dialect

PyPI

A DB-API 2.0 driver and a SQLAlchemy Dialect designed to query GeoServer WFS layers using pseudo-SQL converted to valid underlying HTTP CQL_FILTER queries.

Installation

pip install sqlalchemy-geoserver

(Note: In the root of this repository, you may install locally using pip install -e .)

Connection String

The SQLAlchemy engine is created using the scheme geoserver+http:// or geoserver+https://. Provide the base URL to your GeoServer workspace's WFS endpoint:

engine = create_engine(
    "geoserver+http://localhost:8080/geoserver/workspace/ows"
)

If your GeoServer instance requires an authorization header, pass it via connect_args:

engine = create_engine(
    "geoserver+https://geoserver.example.com/geoserver/workspace/ows",
    connect_args={"headers": {"Authorization": "Bearer token123"}}
)

Usage

This driver acts as a "Read Only" interface fetching a FeatureCollection from a GeoServer WFS API request. It parses standard SQL SELECT queries that use standard logical operators (==, !=, <, >, IN, LIKE, etc.) and translates those to their equivalent GeoServer CQL.

from sqlalchemy import create_engine, MetaData, Table, select

# Create an engine to the geoserver host and specific workspace/layer path
engine = create_engine(
    "geoserver+http://localhost:8080/geoserver/workspace/ows"
)

# You can also pass authentication headers if required
# engine = create_engine(
#     "geoserver+https://geoserver.example.com/geoserver/workspace/ows",
#     connect_args={"headers": {"Authorization": "Bearer token123"}}
# )

metadata = MetaData()
metadata.reflect(bind=engine)

# Tables correspond to the layer names available at that endpoint
# Assuming there is a layer named 'layer_name'
layer_table = Table('layer_name', metadata, autoload_with=engine)

# Standard SQLAlchemy core query
stmt = select(layer_table).where(layer_table.c.property_name == 'value')

with engine.connect() as conn:
    results = conn.execute(stmt).fetchall()
    for row in results:
        print(row._mapping)

Local GeoServer Setup

To run a local GeoServer instance using Docker:

docker run -d -p 8080:8080 --name geoserver \
  -v ./geoserver_data/:/opt/geoserver_data \
  docker.osgeo.org/geoserver:3.0.x

GeoServer will be available at http://localhost:8080/geoserver. The WFS endpoint for a workspace named myworkspace would be:

geoserver+http://localhost:8080/geoserver/myworkspace/ows

Metadata

Release files for sqlalchemy-geoserver 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlalchemy-geoserver 0.2.0
File Size Uploaded
sqlalchemy_geoserver-0.2.0.tar.gz 20.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-geoserver 0.2.0
File Interpreter ABI Platform
sqlalchemy_geoserver-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.5 kB

Release files / sqlalchemy_geoserver-0.2.0.tar.gz

Download URL sqlalchemy_geoserver-0.2.0.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bb785f83b814942a1241788114d9fe3736a5c0ef09636e6a4b7828bd258e7c37
BLAKE2b-256 checksum
How to use checksums
336bbb5d97b1fad435ae62ba699842eac6085375502f3f4539f0989914be7b76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release files / sqlalchemy_geoserver-0.2.0-py3-none-any.whl

Download URL sqlalchemy_geoserver-0.2.0-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61818f08d507c573016c27eade2c15617b7a766617ebba59485345816583e455
BLAKE2b-256 checksum
How to use checksums
db37ad50bc40778337a00f3f7499d5f99e5fe2ade737fe4eedc1f28ed8243572
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page