A SQLAlchemy Dialect and DBAPI 2.0 driver for GeoServer WFS
Project description
SQLAlchemy GeoServer Dialect
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlalchemy_geoserver-0.1.0.tar.gz.
File metadata
- Download URL: sqlalchemy_geoserver-0.1.0.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0658640a52c7ba1f4055e6cbfb057f74096c3b1ff0277c33a949cc15df7d8e2a
|
|
| MD5 |
9534bbf2fdc528e2e6e5dcc3209b5b49
|
|
| BLAKE2b-256 |
72dcdf8234db964bcd148c027de09070271a50b1da8df1c5fcb990a412444e6b
|
File details
Details for the file sqlalchemy_geoserver-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_geoserver-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
751ee342a7b3f169a65121c90c0e459bab94690d0c0d584428534d1bdaefc5c7
|
|
| MD5 |
7492430ef91af9fe638898961a669949
|
|
| BLAKE2b-256 |
74711f1fa19beea6f628cf16534ae5718b9093eab3accfafb28af7b24361cf3b
|