OGC Web Service utility library (OWSLib)
OWSLib is a Python package for client programming with Open Geospatial Consortium (OGC) web service (OWS) interface standards, and their related content models. It provides a common API for accessing service metadata and wrappers for numerous OGC Web Service interfaces, including WMS, WFS, WCS, WPS, CSW, SOS, WMTS, and OGC API standards. The current version is 0.35.0, released on October 28, 2025. Releases are frequent, with several minor versions per year.
Warnings
- gotcha Many older quickstart examples and tutorials for OWSLib, particularly those demonstrating WMS, use a decommissioned NASA JPL WMS server (`http://wms.jpl.nasa.gov`). Attempting to use this URL will result in connection errors.
- gotcha When working with OGC API services (e.g., OGC API - Features), ensure you import from the correct `owslib.ogcapi` submodule (e.g., `from owslib.ogcapi.features import Features`). These APIs are a modern, RESTful design and are distinct from traditional OGC Web Services (WFS, WMS, etc.), which have their own dedicated modules.
- gotcha Users often encounter `ModuleNotFoundError` for `owslib` or its submodules even after installation. This is frequently caused by Python environment issues, such as the script running in a different environment than where `owslib` was installed (e.g., a default system Python vs. a virtual environment).
- deprecated OWSLib dropped support for Python 3.8 and 3.9 in version 0.33.0 (released March 19, 2025).
Install
-
pip install OWSLib
Imports
- WebMapService
from owslib.wms import WebMapService
- WebFeatureService
from owslib.wfs import WebFeatureService
- WebCoverageService
from owslib.wcs import WebCoverageService
- WebProcessingService
from owslib.wps import WebProcessingService
- CatalogueServiceWeb
from owslib.csw import CatalogueServiceWeb
- SensorObservationService
from owslib.sos import SensorObservationService
- Features
from owslib.ogcapi.features import Features
Quickstart
import os
from owslib.wms import WebMapService
# Using a public WMS server for demonstration
# Note: Older examples might use decommissioned servers (e.g., wms.jpl.nasa.gov).
# Ensure the URL is active and provides WMS capabilities.
# For a robust solution, consider using a well-maintained public WMS or your own.
wms_url = os.environ.get('WMS_SERVER_URL', 'http://ows.mundialis.de/services/service?')
try:
wms = WebMapService(wms_url, version='1.3.0')
print(f"Connected to WMS: {wms.identification.title}")
print(f"Available layers: {list(wms.contents.keys())[:5]}...")
# Example: Get metadata for a specific layer
if 'OSM-WMS' in wms.contents:
layer = wms.contents['OSM-WMS']
print(f"\nLayer 'OSM-WMS' title: {layer.title}")
print(f"Bounding Box: {layer.boundingBoxWGS84}")
else:
print("Layer 'OSM-WMS' not found on this server. Trying first available layer...")
if wms.contents:
first_layer_name = list(wms.contents.keys())[0]
layer = wms.contents[first_layer_name]
print(f"\nLayer '{first_layer_name}' title: {layer.title}")
print(f"Bounding Box: {layer.boundingBoxWGS84}")
else:
print("No layers found on this WMS server.")
except Exception as e:
print(f"Error connecting to WMS server or retrieving data: {e}")
print("Please ensure the WMS_SERVER_URL environment variable is set to a valid WMS endpoint,")
print("or use a known working public WMS server.")