OGC Web Service utility library (OWSLib)

0.35.0 · active · verified Mon Apr 13

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

Install

Imports

Quickstart

This quickstart demonstrates how to connect to an OGC Web Map Service (WMS) using OWSLib, retrieve its capabilities, and inspect a specific layer's metadata. It fetches the service title and lists a few available layers.

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.")

view raw JSON →