Install & Compatibility
Where this runs
tested against v0.35.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.456s · 38.2MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.2s · import 0.420s · 39MB
38MB installed
● package 38MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
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
✗ from owslib.wfs import WebFeatureService (for OGC API - Features)
OGC API - Features (formerly WFS 3) is a separate module with a different API design. Use `owslib.ogcapi.features` for these services.
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.")
Debug
Known issues
gotchaMany 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.fixAlways verify WMS/WFS/etc. server URLs from official and up-to-date sources. Use a known active public WMS server or your own. For example, `http://ows.mundialis.de/services/service?` is a commonly used public WMS.
affects: All versions (due to external server change)
gotchaWhen 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.fixUse `from owslib.ogcapi.features import Features` for OGC API - Features, `from owslib.ogcapi.coverages import Coverages` for OGC API - Coverages, etc. Do not try to use `WebFeatureService` for OGC API - Features.
affects: All versions supporting OGC API (0.26.0 onwards)
gotchaUsers 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).fixAlways ensure you are activating the correct Python virtual environment before installing and running scripts that use OWSLib. Verify the Python interpreter being used by your script (e.g., `import sys; print(sys.executable)`).
affects: All versions
deprecatedOWSLib dropped support for Python 3.8 and 3.9 in version 0.33.0 (released March 19, 2025).fixEnsure your environment uses Python 3.10 or newer. OWSLib's `requires_python` is `>=3.10`.
affects: >=0.33.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'owslib'
This error occurs because the 'owslib' package is either not installed in your Python environment or there's a case sensitivity mismatch in the import statement. Python treats 'OWSLib' and 'owslib' as different modules.
fixEnsure the package is correctly installed using `pip install owslib` and that your import statement uses the correct lowercase casing: `import owslib` or `from owslib.wms import WebMapService`.
AttributeError: 'NoneType' object has no attribute 'attrib'
This error typically arises when `owslib` attempts to access an attribute (`.attrib`) on an XML element that it expected to find but was `None`. This often means a specific XML tag or attribute expected in a WMS, WFS, or CSW capabilities document or a record is missing or structured differently than anticipated by OWSLib.
fixInspect the XML capabilities document or service response from the OGC service URL being queried to understand why the expected element is `None`. You may need to handle cases where certain elements are optional or check the `owslib` documentation for the specific service/version to ensure correct parsing or provide more robust error handling in your code for missing attributes.
TypeError: getfeature() got an unexpected keyword argument 'format'
This error indicates that the `getfeature` method of a `WebFeatureService` object was called with an argument named 'format', but the specific WFS version or `owslib` implementation expects 'outputFormat' instead.
fixWhen calling `getfeature`, use `outputFormat` as the keyword argument instead of `format`. For example, change `wfs.getfeature(..., format='GML2')` to `wfs.getfeature(..., outputFormat='GML2')`.
AttributeError: module 'cgi' has no attribute 'parse_qsl'
This error occurs in Python 3 environments when `owslib` (or a dependency) attempts to use `cgi.parse_qsl`. This function was removed from the `cgi` module in Python 3.8 and is no longer directly available in later Python 3 versions. This usually points to an `owslib` version incompatibility with your Python interpreter.
fixUpgrade `owslib` to a newer version that is compatible with your Python 3 environment (e.g., `pip install --upgrade owslib`). Alternatively, if the issue persists with the latest `owslib`, you might need to use a `urllib.parse.parse_qsl` for URL parsing directly if you're working with custom URL manipulations, but ideally, `owslib` itself should handle this internally in compatible versions.
Upgrade
Version history
0.36.0latest on PyPI · released Jun 4, 2026
Audit
Dependencies
lxmlrequiredRequired for XML parsing.
python-dateutilrequiredProvides powerful extensions to the standard Python datetime module.
requestsrequiredAn elegant and simple HTTP library for Python.
PyYAMLrequiredYAML parser and emitter for Python.