pygeoapi

0.23.2 · active · verified Thu Apr 16

pygeoapi is a Python server implementation of the OGC API suite of standards. It enables organizations to deploy RESTful OGC API endpoints using OpenAPI, GeoJSON, and HTML. The current version is 0.23.2, with releases happening roughly every 2-3 months.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart generates a basic `pygeoapi-config.yml` file and provides instructions on how to set the necessary environment variables (`PYGEOAPI_CONFIG`, `PYGEOAPI_OPENAPI`), generate the OpenAPI document, and start the pygeoapi server. Users can then access the API through a web browser or programmatic clients.

import os
import yaml

# Define a minimal pygeoapi configuration
config_content = {
    'server': {
        'bind': {'host': '0.0.0.0', 'port': 5000},
        'url': 'http://localhost:5000/',
        'pretty_print': True
    },
    'logging': {
        'level': 'DEBUG'
    },
    'metadata': {
        'identification': {
            'title': 'My pygeoapi instance',
            'abstract': 'A minimal pygeoapi setup.',
            'keywords': ['geospatial', 'API', 'OGC'],
            'license': {'url': 'https://creativecommons.org/licenses/by/4.0/'}
        },
        'provider': {
            'name': 'pygeoapi',
            'url': 'https://pygeoapi.io/'
        }
    },
    'resources': {
        # Add sample data as needed. E.g., a GeoJSON file
        # 'data': {
        #     'type': 'collection',
        #     'title': 'Sample GeoJSON Data',
        #     'description': 'A sample collection from a GeoJSON file.',
        #     'keywords': ['geojson', 'sample'],
        #     'extents': {
        #         'spatial': {'bbox': [-180, -90, 180, 90]},
        #         'temporal': {'interval': ['1900-01-01T00:00:00Z', '2099-12-31T23:59:59Z']}
        #     },
        #     'provider': {
        #         'type': 'feature',
        #         'name': 'GeoJSON',
        #         'data': 'path/to/your/data.geojson'
        #     }
        # }
    }
}

config_file_path = 'pygeoapi-config.yml'
openapi_file_path = 'pygeoapi-openapi.yml'

with open(config_file_path, 'w') as f:
    yaml.dump(config_content, f, sort_keys=False)

print(f"Generated minimal configuration file: {config_file_path}")
print(f"\nTo run pygeoapi:")
print(f"1. Set the configuration environment variable: ")
print(f"   export PYGEOAPI_CONFIG={config_file_path}")
print(f"2. Generate the OpenAPI document (required for server startup):")
print(f"   pygeoapi openapi generate $PYGEOAPI_CONFIG --output-file {openapi_file_path}")
print(f"3. Set the OpenAPI environment variable: ")
print(f"   export PYGEOAPI_OPENAPI={openapi_file_path}")
print(f"4. Start the server:")
print(f"   pygeoapi serve")
print(f"\nAccess your pygeoapi instance at http://localhost:5000 in your browser.")

view raw JSON →