Skip to main content

Spade block authoring library for Python

Project description

Spade Python Library

The Python library for authoring Spade blocks. Define a handler function, call run(), and the library handles parameter loading, input discovery, and output writing.

Installation

uv add spadelib
uv sync

Quick Start

from spadelib import run, RasterFile

def handler(source: RasterFile, buffer_distance: int) -> RasterFile:
    # Your processing logic here
    result_path = process(source.path, buffer_distance)
    return RasterFile(path=result_path)

if __name__ == "__main__":
    run(handler)

That's it. The run() function:

  1. Loads scalar parameters from params.yaml
  2. Scans inputs/ for file-based arguments, matched by name to your function parameters
  3. Calls your handler with the combined arguments
  4. Writes the return value to outputs/

Types

Use type hints on your handler to control how inputs are loaded and outputs are written.

File Types

Type Description
File Generic single file
RasterFile Raster data (e.g., GeoTIFF)
VectorFile Vector data (e.g., GeoJSON)
TabularFile Tabular data (e.g., CSV)
JsonFile JSON data

Each has a path: str field pointing to the file location.

Directory Type

Type Description
Directory Directory-based input (e.g., shapefiles)

Has a path: str field pointing to the directory.

Collection Types

Type Description
FileCollection Collection of files
RasterFileCollection Collection of raster files
VectorFileCollection Collection of vector files
TabularFileCollection Collection of tabular files

Each has a paths: list[str] field.

How Inputs Are Resolved

The handler's parameter names are matched against two sources:

  • Scalar parameters (str, int, float, bool): loaded from params.yaml
  • File-based inputs: discovered from subdirectories in inputs/, where each subdirectory name matches a parameter name
params.yaml              # scalar args: {"resolution": 10, "method": "nearest"}
inputs/
  reference/
    data.tif             # -> handler(reference=RasterFile(path="inputs/reference/data.tif"))
  target/
    data.tif             # -> handler(target=RasterFile(path="inputs/target/data.tif"))

Type hints determine how each input is constructed:

  • File subclass: expects a single file in the subdirectory
  • Directory: uses the subdirectory path itself
  • FileCollection subclass: collects all files in the subdirectory

Output Handling

Return a typed value from your handler and run() writes it to outputs/:

# Single output
def handler(source: RasterFile) -> RasterFile:
    return RasterFile(path="result.tif")

# Multiple outputs
def handler(source: RasterFile) -> dict:
    return {
        "raster": RasterFile(path="result.tif"),
        "summary": JsonFile(path="stats.json"),
    }

Output names are resolved from block.yaml (if available) or inferred from the return type.

The build() Function

Generate a block manifest from a handler's signature:

from spadelib import build, RasterFile, VectorFile

def handler(raster: RasterFile, buffer: int) -> VectorFile:
    """Converts raster boundaries to vector polygons."""
    ...

manifest = build(handler)
# {'description': 'Converts raster boundaries to vector polygons.',
#  'inputs': {'raster': {'type': 'file', 'format': 'GeoTIFF'},
#             'buffer': {'type': 'number'}},
#  'outputs': {'vector': {'type': 'file', 'format': 'GeoJSON'}}}

Testing

uv run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spadelib-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spadelib-0.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file spadelib-0.1.0.tar.gz.

File metadata

  • Download URL: spadelib-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spadelib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 773eb445717b6ad1cbd848788982419823a98087e1fd9dc6981f11fd4c4ca6da
MD5 d50e2dcc2b3087e0601cfe10fad939b8
BLAKE2b-256 b96898bd52a726437b6f411e3498b32b9284d5a763cbe7beb92a3fe154c24dcd

See more details on using hashes here.

Provenance

The following attestation bundles were made for spadelib-0.1.0.tar.gz:

Publisher: release-spadelib.yml on krbundy/psae_monorepo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spadelib-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spadelib-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spadelib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da9be292afe232d5f359eb1474dde7caec805cf7eec1fb951354212e52f4a5af
MD5 04892247e9606b34b044595a0a881a62
BLAKE2b-256 50a0408e5890396181ef7e88951e81dbb8948c43c31e9a63da6009c11f8c8d34

See more details on using hashes here.

Provenance

The following attestation bundles were made for spadelib-0.1.0-py3-none-any.whl:

Publisher: release-spadelib.yml on krbundy/psae_monorepo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page