Cave Utilities
Python utilities for the CAVE App framework: API validation, data builders, and shared helpers.
Overview
cave_utils is a foundational library for building CAVE applications. It provides:
- API validation: validate
session_datadicts against the full CAVE API spec, with structured error and warning reporting - Data builders: helper classes for constructing hierarchical and date-based group structures
- Shared utilities: logging, geographic calculations, coordinate systems, and argument parsing
It is designed to be embedded in a CAVE API server, but can also be used standalone for testing and data development.
Features
- Validates all 10 top-level CAVE API keys (
settings,appBar,pages,panes,maps,mapFeatures,globalOutputs,groupedOutputs,draggables,extraKwargs) - Cross-field validation with structured error paths (e.g.
maps.data.myMap.currentProjection) - Time-series (
timeValues) and ordering (order) validation built in GroupsBuilderandDateGroupsBuilderfor constructing hierarchical group structures from flat dataGeoUtilsfor shortest-path calculations over geographic networksCustomCoordinateSystemfor converting Cartesian 2D/3D coordinates to lat/long- Runtime type enforcement via
type_enforced
Requirements
- Python ≥ 3.11
Installation
pip install cave_utils
Quick Start
Validating Session Data
from cave_utils import Validator
session_data = {
"settings": {
"iconUrl": "https://example.com/icon.png",
},
"appBar": {
"data": {
"btn_home": {
"icon": "md/MdHome",
"type": "button",
}
}
},
}
result = Validator(session_data=session_data)
# Inspect errors and warnings
for entry in result.log.log:
print(entry)
# Empty list means fully valid
Using GroupsBuilder
from cave_utils.builders.groups import GroupsBuilder
builder = GroupsBuilder(
data=[
{"id": "region_east", "name": "East", "parent": None},
{"id": "state_ny", "name": "New York", "parent": "region_east"},
{"id": "state_ma", "name": "Massachusetts", "parent": "region_east"},
],
id_field="id",
name_field="name",
parent_field="parent",
)
# Serialize to the CAVE API groupedOutputs format
groups_data = builder.serialize()
Public API
| Class | Import | Description |
|---|---|---|
Validator |
from cave_utils import Validator |
Validates a session_data dict against the full CAVE API spec |
LogObject |
from cave_utils import LogObject |
Structured log container for errors and warnings |
Socket |
from cave_utils import Socket |
No-op WebSocket stub for use in tests |
Arguments |
from cave_utils import Arguments |
Parses kwargs, flags, and positional args from raw argument lists |
GeoUtils |
from cave_utils import GeoUtils |
Geographic utilities including shortest-path via scgraph |
CustomCoordinateSystem |
from cave_utils import CustomCoordinateSystem |
Converts 2D/3D Cartesian coordinates to lat/long |
Full API reference: mit-cave.github.io/cave_utils
LLM Docs
cave_utils can generate plain text documentation for all its modules, suitable for use with AI assistants (Claude, Gemini, etc.).
From Python:
from cave_utils import generate_docs
generate_docs("path/to/output_dir")
From the command line:
cave-utils-docs path/to/output_dir
If no directory is specified, docs are written to ./cave_utils_docs/.
The output directory will contain one .txt file per module plus a README.txt index and a PROJECT_README.md with this project overview. You can point your AI assistant at this directory or reference individual files in a system prompt.
Development
Dev dependencies are declared in [project.optional-dependencies] dev in pyproject.toml. Install them with uv sync --extra dev.
| Command | Description |
|---|---|
uv run pytest |
Run all tests |
uv run pytest -v |
Run tests with verbose output |
uv run nox |
Run tests across Python 3.11, 3.12, 3.13, 3.14 |
uv run nox -s tests-3.14 |
Run tests on a single Python version |
uv run python utils/prettify.py |
Format code with autoflake + black |
uv run python utils/docs.py |
Regenerate pdoc documentation |
Running Tests
Tests live in test/. The main test file (test_validator.py) imports every example in test/api_examples/, runs it through Validator, and asserts no errors or warnings are produced. Unit tests exist for each module.
uv run pytest
Hot-Reload with a Cave App
To develop cave_utils against a running Cave App, mount the local source as a Docker volume:
cave run --docker-args "--volume {local_path_to_cave_utils}/cave_utils:/cave_utils"
Then in the Cave App's utils/run_server.sh, add pip install -e /cave_utils before the server starts. Changes to cave_utils source will be reflected on the next API call without rebuilding the container.
Set LIVE_API_VALIDATION_PRINT=True in the Cave App's .env to see validation output on every API command.
Release Process
- Ensure all tests pass and code is formatted:
uv run nox uv run python utils/prettify.py
- Update
versionin bothpyproject.tomlandsetup.cfg - Run tests across all supported Python versions:
uv run nox - Update
VERSIONinutils/docs.pyand regenerate docs:uv run python utils/docs.py
Metadata
Release files for cave-utils 3.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cave_utils-3.7.0.tar.gz | 87.5 kB | Without provenance | Details for cave_utils-3.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cave_utils-3.7.0-py3-none-any.whl | Python 3 | none | any | Details for cave_utils-3.7.0-py3-none-any.whl |
Total release size: 173.9 kB
Release files / cave_utils-3.7.0.tar.gz
| Download URL | cave_utils-3.7.0.tar.gz |
|---|---|
| Size | 87.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a29bd42fe4fa6bc8fca5c997c5192fd42aa8d64befa97193cbdd7ee7cbb93e6
|
|
BLAKE2b-256 checksum How to use checksums |
d528bfed124fae564e4c9e31354025560901476b0ca610645006ce90b0f9d124
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Release files / cave_utils-3.7.0-py3-none-any.whl
| Download URL | cave_utils-3.7.0-py3-none-any.whl |
|---|---|
| Size | 86.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
afbb695536834d726869290a509c02e74147ce2772ae3085bb3bb9f3bc654755
|
|
BLAKE2b-256 checksum How to use checksums |
ccb1e37f99d0f0b572b05f46df8c35a2aaeb5518057ce95012dedc4d63ace76a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Security for cave-utils 3.7.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.