Skip to main content

pygeodata

Reproducible geospatial pipelines, locally.

pygeodata is built around the declarative programming principle: you should be able to describe what data you want, not how to produce it. You declare a spatial spec — a CRS, transform and shape — once. Every dataset and figure in your project receives that spec and knows how to adapt. The framework is the orchestrator: it decides whether to compute or return from cache, resolves reprojection, propagates invalidation when code changes, and keeps a permanent record of what ran and when.

This is the declarative model that SQL offers for databases, applied to local geospatial analysis in Python.

from pygeodata import Data, SpatialSpec, get_config, load
from pygeodata.processors import Reprojector
from dataclasses import dataclass

get_config().update(spec=SpatialSpec.from_raster_file('reference.tif'))

@dataclass
class ElevationLoader(Data):
    @property
    def processor(self):
        return Reprojector('data/elevation.tif')

@dataclass
class SlopeLoader(Data):
    def _process(self, spec):
        process(ElevationLoader(), spec)
        gdal.DEMProcessing(self.ensure_processed_path(spec), ElevationLoader().get_processed_path(spec), 'slope')

# Both lines check the cache, recompute only what's stale, and return the result.
# Change ElevationLoader's code → both caches are invalidated automatically.
elevation = load(ElevationLoader())
slope     = load(SlopeLoader())

How it works

Every Data, Table, or Figure class is fingerprinted by hashing the AST of its source code, the ASTs of all its transitive dependencies, and its parameter values. That fingerprint, combined with the spatial spec, is the cache key. If it matches what's on disk, the cached file is returned. If not, the class is reprocessed and the new fingerprint is written.

The hash is AST-based, not text-based: reformatting your code or editing a comment never triggers a rerun. It is also independent of the Python version — pygeodata serialises the AST itself — so a cache stays valid when you upgrade Python or share it with a machine running another version.

source_hash      SHA256(AST of the class)
dep_tree_hash    SHA256(source_hash of all transitive dependencies)
instance_hash    SHA256(dep_tree_hash + params)           
state_hash       SHA256(instance_hash + spec)             

Everything lands in a content-addressed store:

data_processed/
  {state_hash}/
    elevation_loader.tif
    meta.json                       ← cache key + metadata
    parameters.json                 ← params at time of run
    spec.json                       ← spec at time of run

tables/
  {state_hash}/
    summary_table.html              ← rendered output (Table's ext)
    meta.json
    parameters.json
    spec.json

.source/
  code/{source_hash}/
    source.py                       ← every version of every class
    source.json
  snapshots/{dep_tree_hash}/
    tree.json                       ← full dependency tree at time of run
    graph.pdf

Defining loaders

Subclass Data for datasets, Figure for plots, Table for rendered summary tables. Use a processor property for standard reprojection/rasterization, or override _process directly for anything else. Parameters are plain instance attributes — dataclasses work perfectly.

# Delegate to the built-in Reprojector
@dataclass
class LAILoader(Data):
    moment: str   # 'min', 'mean', 'max', ...

    @property
    def processor(self):
        return Reprojector(
            f'data/lai/LAI_{self.moment}.vrt',
            resampling=Resampling.average,
            scales=0.1,
        )

# Full control
class SlopeLoader(Data):
    driver = RioXArrayDriver()

    def _process(self, spec):
        process(ElevationLoader(), spec)
        gdal.DEMProcessing(
            self.ensure_processed_path(spec),
            ElevationLoader().get_processed_path(spec),
            'slope',
        )

The SpatialSpec

SpatialSpec holds the CRS, an affine transform, and a pixel shape. It can be partially defined — just a CRS, no transform — and processors can resolve it from the source file. The spec flows through the pipeline automatically; you set it once in config and never pass it manually unless you need to.

# From an existing raster
spec = SpatialSpec.from_raster_file('reference.tif')

# Or build it explicitly
spec = SpatialSpec(
    crs=CRS.from_string('EPSG:3035'),
    transform=Affine.translation(left, top) * Affine.scale(1000, -1000),
    shape=(height, width),
)

get_config().update(spec=spec)

# After that, just ask for things
load(ElevationLoader())   # spec injected automatically
load(LAILoader('mean'))

# or ask for a specific spec
load(ElevationLoader(), spec)
load(LAILoader('mean'), spec)

Composing pipelines

Data instances can be parameters of other Data instances. The full dependency graph is tracked — changing any upstream class invalidates all downstream caches automatically.

@dataclass
class FeatureCorrelationLoader(Data):
    feature: Data    # e.g. ElevationLoader()
    variable: Data

    def _process(self, spec):
        feat = load(self.feature, spec)
        var  = load(self.variable, spec)
        # ... compute correlation ...

Co-outputs

When one computation produces multiple outputs — a regression that yields a slope, standard error, and p-value simultaneously — _process can yield sibling artifacts instead of returning. Each yielded artifact gets its own cache entry and is independently re-usable.

@dataclass
class RegressionLoader(Data):
    param: Literal['beta', 'se', 'p']

    def _process(self, spec):
        beta, se, p = run_regression(spec)
        write(RegressionLoader('beta'), beta)
        write(RegressionLoader('se'), se)
        write(RegressionLoader('p'), p)
        yield RegressionLoader('beta')
        yield RegressionLoader('se')
        yield RegressionLoader('p')

Figures

Figure works identically to Data — same caching, same hashing, same registry — but outputs go to figures/ and the default extension is png. There is no load() method; figures are outputs only.

Table is the same kind of class as Figure — outputs go to tables/, default extension html, no load(). A Table subclass's _process loads whatever Data it wants to summarise and writes the rendered HTML itself, typically df.to_html(). The registry browser renders that HTML directly in the entry's detail pane, the same way it renders a Figure's PNG.

@dataclass
class FigureElevation(Figure):
    def _process(self, spec):
        da = load(ElevationLoader(), spec)
        da.plot()
        plt.savefig(self.ensure_processed_path(spec), dpi=300)
        plt.close()

The registry browser

pygeodata browse opens a local web UI that shows the full state of your project — classes, cached results, versions of every class that run.

  • Classes — all tracked subclasses, with staleness indicators when code or dependencies have changed since the last run
  • Entries — every (class × params × spec) combination processed, with parameter tables, spatial spec details, and links to output files
  • Code view — the full version history of any class; browse what the code looked like when a specific result was produced

Cache management

from pygeodata import load_from_hash

# Load any cached output by its (truncated) state hash — no re-running required.
da = load_from_hash('cc71cf42816b')
from pygeodata import clean_cache

clean_cache(dry_run=True)    # preview what would be deleted
clean_cache(dry_run=False)   # delete stale entries

clean_cache walks data_processed/, tables/, and figures/ and removes any directory whose state hash no longer matches the live hash of the corresponding class. Classes that have been renamed or removed from the codebase are flagged for manual confirmation.

A TrackedObject subclass passed as a parameter never enters the dependency tree, so the default check reports such an entry as current even when the pipeline correctly rebuilds it. Pass check_class_params=True to validate those too — it is opt-in because an entry whose parameters.json is missing then counts as stale.

from pygeodata.cache import clean_source_registry

clean_source_registry(dry_run=True)    # preview orphaned .source/ entries
clean_source_registry(dry_run=False)   # delete them

clean_source_registry removes orphaned code snapshots and dependency trees from .source/. It keeps the latest snapshot per class and anything referenced by a live cache entry — everything else is prunable.

Both are also available from the CLI, where they preview by default and delete only with --no-dry-run:

pygeodata clean-cache                        # preview
pygeodata clean-cache --no-dry-run           # apply
pygeodata clean-cache --check-class-params   # also validate class-valued params
pygeodata clean-source                 # preview
pygeodata clean-source --no-dry-run    # apply

The rest of the command line inspects state without running anything. It reads your classes from source by default — no project code is executed, so it also works on a read-only copy of a project without its heavy dependencies; --import-all imports the modules instead:

pygeodata classes                 # staleness per class: C source changed, D deps changed
pygeodata entry list              # one row per cache entry: S stale, F other format, ? unknown class
pygeodata entry show cc71cf       # full detail for one entry (any unique hash prefix)
pygeodata catalog info            # who wrote the catalog, and how it differs from disk
from pygeodata.cache import rebuild_registry

rebuild_registry()   # wipe and rewrite all .source/ entries from current classes

Installation

conda install -c conda-forge pygeodata
# or
pip install pygeodata

Optional features:

conda install -c conda-forge python-graphviz    # or: pip install pygeodata[viz]
conda install -c conda-forge pygeodata-browser  # or: pip install pygeodata[browser]

License

MIT

Metadata

Release files for pygeodata 0.5.1

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

Source distribution (sdist)

Source distribution for pygeodata 0.5.1
File Size Uploaded Provenance Actions
pygeodata-0.5.1.tar.gz 531.4 kB With provenance Details for pygeodata-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pygeodata 0.5.1
File Interpreter ABI Platform Actions
pygeodata-0.5.1-py3-none-any.whl Python 3 none any Details for pygeodata-0.5.1-py3-none-any.whl

Total release size: 646.6 kB

Release files / pygeodata-0.5.1.tar.gz

Download URL pygeodata-0.5.1.tar.gz
Size 531.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f53c34f40f231fc80fb29792ebd1c6f1318d73bb49301b842d75c4076bb479bb
BLAKE2b-256 checksum
How to use checksums
8d91cbfbefe33c7be0237626b217465c025e732f4e07a0b85f9714b3eefc1cb2
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 6, 2026.

Transparency log

Release files / pygeodata-0.5.1-py3-none-any.whl

Download URL pygeodata-0.5.1-py3-none-any.whl
Size 115.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
186e54af892e843c3062873790574ac3dd3607079c8bdd9273385614fa168f91
BLAKE2b-256 checksum
How to use checksums
6598545bc46b15ba38608700d6d66c4df1c74f345421f8452385123de297e436
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 6, 2026.

Transparency log

Security for pygeodata 0.5.1

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 pygeodata-0.5.1.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 6, 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.

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