Skip to main content

pygeoapi-yaml

A pygeoapi provider for YAML files. pygeoapi reads the YAML file directly, so you don't need to convert it to GeoJSON first.

YAML and JSON map almost one to one, so GeoJSON can be written in YAML as it is: a FeatureCollection in a YAML file is served unchanged. YAML adds what is pleasant when you keep data by hand: comments, long texts that stay readable, and clean diffs in git. Data kept by hand is often a plain list of records, as in a CSV file, so the provider reads that too: you say where the id and the geometry are.

This provider publishes such a file as an OGC API - Features collection. The YAML file stays the source of truth. pygeoapi answers in GeoJSON, as it does for every other provider.

Status: alpha, read-only. See Status and roadmap.

Install

pip install pygeoapi-yaml

It needs pygeoapi 0.24 or later, in the same Python environment.

Configure

Declare the provider in your pygeoapi configuration by its Python path. A file can be written in one of three ways.

A list of records, with coordinates in two fields

# observations.yaml
- id: obs-1
  name: Mont Royal
  lat: 45.5
  lon: -73.6
  seen: 2026-05-01
  tags: [birds, park]
- id: obs-2
  name: Somewhere unknown   # no coordinates: geometry is null
  seen: 2026-07-20
providers:
  - type: feature
    name: pygeoapi_yaml.provider.YAMLProvider
    data: /data/observations.yaml
    id_field: id
    title_field: name
    time_field: seen          # optional, enables ?datetime=
    geometry:                 # optional, as in the CSV provider
      x_field: lon
      y_field: lat

Records under a key, with a GeoJSON geometry in a field

# trails.yaml
title: Trails
trails:
  - code: T1
    name: Lakeshore
    path:
      type: LineString
      coordinates: [[-73.60, 45.50], [-73.58, 45.51]]
providers:
  - type: feature
    name: pygeoapi_yaml.provider.YAMLProvider
    data: /data/trails.yaml
    items_key: trails         # where the list is
    id_field: code
    geometry:
      field: path             # a GeoJSON geometry

With no geometry setting at all, every item is served with geometry: null. This is fine for data that isn't spatial.

A GeoJSON FeatureCollection, written in YAML

type: FeatureCollection
features:
  - type: Feature
    id: 123-456
    geometry: {type: Point, coordinates: [125.6, 10.1]}
    properties: {name: Dinagat Islands}

This needs no setting beyond data. id_field is used only for features without an id.

A directory of YAML files

data can also be a directory. All the YAML files under it, in its subdirectories too, make one collection:

  • each file can hold items in any of the layouts above;
  • or a file can be a single item, written as a mapping (without items_key).
notes/
  home.yaml               # page: /home, notes: [...]
  guides/install.yaml
  template.yaml           # left out, see exclude
providers:
  - type: feature
    name: pygeoapi_yaml.provider.YAMLProvider
    data: /data/notes
    items_key: notes          # in each file
    id_field: id
    pattern: '*.yaml'         # the default
    exclude:                  # file names or paths in the directory
      - template.yaml

Items come in the order of their files' paths (guides/install.yaml before home.yaml). Hidden files and directories (starting with .) are skipped. An invalid file is logged and left out, and the others are still served.

Behaviour

  • Queries. All of these are supported:

    • limit and offset;
    • resulttype=hits;
    • property filters (?name=...);
    • bbox;
    • datetime (an instant or an interval, open with .., on time_field);
    • sortby (several properties allowed);
    • q;
    • properties (select properties);
    • skipGeometry;
    • count: false.
  • Field types are read from all items. Integers and floats in the same field give number. Other mixed types give string. YAML dates give string with format date or date-time, so the queryables are right.

  • YAML values JSON lacks are converted in responses:

    • dates and timestamps become ISO 8601 strings;
    • !!binary becomes base64.
  • Property filters compare typed values: ?count=10 matches 10 and 10.0, and ?checked=true matches a YAML true. If the field holds a list, the filter matches when the list contains the value (?tags=park).

  • q follows OGC API - Records:

    • commas separate alternatives;
    • spaces separate words that must all be found.

    The search ignores case and looks in every text value, including values in lists and nested mappings.

  • bbox never matches an item without geometry. The OGC API - Features specification asks for this. pygeoapi's GeoJSON and CSV providers include such items instead.

  • Sorting puts items without the property last, whether the order is ascending or descending.

  • Ids come from id_field. An item without one gets its position in the list as its id, and a warning is logged, as are duplicate ids.

  • Changes are seen at once. Each file is parsed once, then kept in memory until its modification time or size changes. For a directory, the provider also re-reads the files when one is added or removed, including a file that isn't YAML. No restart is needed. pygeoapi creates a provider for each request, so the parsed copy is shared between them.

  • Empty files (empty, only comments, or []) and missing files give an empty collection, not an error.

  • Safe parsing. The provider uses yaml.safe_load, so a YAML file can never build Python objects or run code. An invalid file gives an error response, with the details in the log.

  • Read-only. OGC API - Features - Part 4 (create, replace, update, delete) is not implemented yet. See the roadmap.

Extending

To read another layout, or to compute properties, subclass YAMLProvider and override _features(document, path). It receives a parsed YAML document and the path of its file, and returns GeoJSON features. With a directory, it is called once for each file. In the features it returns:

  • values can still be YAML values, such as dates;
  • an id can be None.

The provider still takes care of the rest: ids, field types, conversion to JSON, queries and caching. Each subclass keeps its own parsed copy of a file.

from pygeoapi_yaml.provider import YAMLProvider


class MyProvider(YAMLProvider):
    def _features(self, document, path):
        features = super()._features(document, path)
        for feature in features:
            feature['properties']['label'] = feature['properties']['name'].upper()
        return features

Development

python3 -m venv .venv
.venv/bin/pip install -e '.[dev]'
.venv/bin/pytest
.venv/bin/flake8 pygeoapi_yaml tests

There are two kinds of tests:

  • tests/test_yaml_provider.py tests the provider on its own, in the style of pygeoapi's provider tests.
  • tests/test_api.py goes through pygeoapi itself:
    • the configuration is validated against pygeoapi's schema;
    • the OpenAPI document is generated;
    • /collections, /items, /items/{id}, the queryables, an empty collection and a directory are checked.

See CONTRIBUTING.md before opening a pull request.

Status and roadmap

Done (0.1.0, on PyPI):

  • Read-only provider: get_fields, query, get and get_domains.
  • Three file layouts: records, records under items_key, a FeatureCollection.
  • Geometry from x_field/y_field, from a GeoJSON field, or none.
  • Every query parameter pygeoapi passes to a feature provider.
  • The file is read again when it changes; its parsed copy is shared between requests.
  • Subclassing: override _features() to read another layout.
  • Tests for the provider alone and through pygeoapi, checked by mutation testing (each deliberate bug in the provider makes a test fail).
  • Continuous integration: pytest and flake8 on Python 3.12 and 3.13.

Done (0.2.0, on PyPI):

  • A directory of YAML files as a single collection: items in each file, or one item per file; pattern and exclude; read again when a file is added, changed or removed.
  • _features(document, path): subclasses get the path of each file. In 0.1.0 it was _features(document).

Next:

  • CI on both the oldest supported pygeoapi and the latest. For now they are the same: 0.24 is both the minimum and the latest release.
  • Listing on the pygeoapi community plugins page.
  • A cql2 filter (filter=), through pygeofilter, as other providers do.
  • Writing (OGC API - Features - Part 4). This only comes with ruamel.yaml, so that comments and formatting survive a write. Otherwise a write would erase them.
  • Then, on top of it, a catalogue of pygeometa MCF files (YAML metadata, one record per file) served as OGC API - Records.

Authorship

Most of the code, tests and documentation were written by Claude, an AI model made by Anthropic, working in Claude Code. Alexandre Leroux started the project, set its goals and made its design decisions, and directed the work. Commits written with Claude carry a Co-Authored-By: Claude trailer.

Whoever types the code, it is held to the same checks: each behaviour has a test, some tests go through pygeoapi itself, and mutation testing shows that the tests catch deliberate bugs.

License

MIT, like pygeoapi. See LICENSE.

Metadata

Release files for pygeoapi-yaml 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygeoapi-yaml 0.2.0
File Size Uploaded Provenance Actions
pygeoapi_yaml-0.2.0.tar.gz 26.0 kB With provenance Details for pygeoapi_yaml-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pygeoapi-yaml 0.2.0
File Interpreter ABI Platform Actions
pygeoapi_yaml-0.2.0-py3-none-any.whl Python 3 none any Details for pygeoapi_yaml-0.2.0-py3-none-any.whl

Total release size: 40.6 kB

Release files / pygeoapi_yaml-0.2.0.tar.gz

Download URL pygeoapi_yaml-0.2.0.tar.gz
Size 26.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9a322dc10c07fab3bc319493a4b305fdfa1c6e7c6f7ed2fcc5485a78c14ffa7f
BLAKE2b-256 checksum
How to use checksums
d766c4cb454421ef8997efd9e010964ddab2d42bca489ed9979ecc12af3e2736
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / pygeoapi_yaml-0.2.0-py3-none-any.whl

Download URL pygeoapi_yaml-0.2.0-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
080e6e3cfee5de4ee98c4ca31d377222fbf280bf50241e15d2b7fef945381c0f
BLAKE2b-256 checksum
How to use checksums
2fb765bea77f0d65004db0e23f168b00a5cb24a6ba15f22ae5d13b3a641b7d92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for pygeoapi-yaml 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pygeoapi_yaml-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page