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:
- Loads scalar parameters from
params.yaml - Scans
inputs/for file-based arguments, matched by name to your function parameters - Calls your handler with the combined arguments
- 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 fromparams.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:
Filesubclass: expects a single file in the subdirectoryDirectory: uses the subdirectory path itselfFileCollectionsubclass: 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
773eb445717b6ad1cbd848788982419823a98087e1fd9dc6981f11fd4c4ca6da
|
|
| MD5 |
d50e2dcc2b3087e0601cfe10fad939b8
|
|
| BLAKE2b-256 |
b96898bd52a726437b6f411e3498b32b9284d5a763cbe7beb92a3fe154c24dcd
|
Provenance
The following attestation bundles were made for spadelib-0.1.0.tar.gz:
Publisher:
release-spadelib.yml on krbundy/psae_monorepo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spadelib-0.1.0.tar.gz -
Subject digest:
773eb445717b6ad1cbd848788982419823a98087e1fd9dc6981f11fd4c4ca6da - Sigstore transparency entry: 2187837416
- Sigstore integration time:
-
Permalink:
krbundy/psae_monorepo@0af1c0a2b9ee002ad02dabc2aa6fce0e82a07d2c -
Branch / Tag:
refs/tags/spadelib-v0.1.0 - Owner: https://github.com/krbundy
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-spadelib.yml@0af1c0a2b9ee002ad02dabc2aa6fce0e82a07d2c -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da9be292afe232d5f359eb1474dde7caec805cf7eec1fb951354212e52f4a5af
|
|
| MD5 |
04892247e9606b34b044595a0a881a62
|
|
| BLAKE2b-256 |
50a0408e5890396181ef7e88951e81dbb8948c43c31e9a63da6009c11f8c8d34
|
Provenance
The following attestation bundles were made for spadelib-0.1.0-py3-none-any.whl:
Publisher:
release-spadelib.yml on krbundy/psae_monorepo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spadelib-0.1.0-py3-none-any.whl -
Subject digest:
da9be292afe232d5f359eb1474dde7caec805cf7eec1fb951354212e52f4a5af - Sigstore transparency entry: 2187837426
- Sigstore integration time:
-
Permalink:
krbundy/psae_monorepo@0af1c0a2b9ee002ad02dabc2aa6fce0e82a07d2c -
Branch / Tag:
refs/tags/spadelib-v0.1.0 - Owner: https://github.com/krbundy
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-spadelib.yml@0af1c0a2b9ee002ad02dabc2aa6fce0e82a07d2c -
Trigger Event:
push
-
Statement type: