Skip to main content

csp-lab

A local CubeSat Space Protocol lab powered by libcsp. It runs two simulated nodes and a ZMQ hub in Docker. The Python CLI and MCP server provide the same diagnostic operations.

Quick start

With uv and Docker Compose installed and Docker running:

uvx csp-lab up --protocol 2
uvx csp-lab ping 2
uvx csp-lab down

The published Python package uses its matching prebuilt Docker image, so this does not require a source checkout or a local libcsp build. You can also install the CLI with uv tool install csp-lab and run csp-lab directly.

Why use it?

The lab gives you a repeatable place to try CSP v1 and v2, check whether simulated nodes respond, and inspect failures through the CLI or MCP tools. It is useful when developing CSP integrations or experimenting with an MCP client without arranging physical CubeSat hardware.

Requirements

  • Python 3.10 or newer and uv
  • Docker with Compose

The native code is built against the pinned libcsp v2.1 submodule. That library supports CSP protocol v1 and v2 at runtime. The Docker image uses Linux because recent libcsp releases do not provide maintained native macOS support. See versioning policy for the supported combinations.

Lab state is stored in ~/.local/state/csp-lab or under XDG_STATE_HOME when set, so commands work from any directory.

Start and stop operations using the same state directory are protected by a process lock. An overlapping operation fails with a retry message. State is saved atomically; if a state file is corrupt or unsupported, csp-lab down can still stop the lab and remove that file. If down cannot finish Docker cleanup, it retains the state so you can retry.

If a lab was started by the earlier checkout-based CLI, run csp-lab down from that checkout once before switching to uvx from another directory. The CLI recognizes and removes the earlier path-based Docker project there.

To test CSP v1, start a fresh lab with up --protocol 1. up refuses to change the protocol of an existing lab; run down first. The two versions never share a running network.

The CLI commands are up, down, status, topology, ping <address>, and doctor. status checks whether the hub and both nodes are running in Docker. Use --json for machine-readable output. ping and doctor return a nonzero exit code when a node does not respond. Addresses must be 1–31 for CSP v1 or 1–16383 for CSP v2. The demo nodes use addresses 2 and 3; the probe uses address 4.

MCP

Start the lab first, then configure an MCP client to launch csp-lab mcp over stdio:

{
  "mcpServers": {
    "csp-lab": {
      "command": "uvx",
      "args": ["csp-lab", "mcp"]
    }
  }
}

With uv tool install, set the command to csp-lab and the argument to mcp. GUI clients may not see the shell's PATH; use the full path to uvx or the installed csp-lab executable when needed. For a local clone after uv sync, use /absolute/path/to/csp-lab/.venv/bin/csp-lab as the command. Keep the lab running in a separate terminal while using the MCP tools.

The stdio server provides csp_topology, csp_ping, and csp_diagnose. It does not expose commands that reboot, shut down, or read or write node memory. The simulated server binds only the CSP ping service port.

Python tests

This checkout includes a context-managed Python API and an automatically discovered pytest fixture. Use uv sync --locked to run them from a clone. For PyPI installations, install csp-lab[pytest]>=0.2.0 in the test environment once that version is available.

from csp_lab import Lab

with Lab(protocol=2) as lab:
    assert lab.ping(2).reachable
    print(lab.topology().nodes)
import pytest

@pytest.mark.csp_lab(protocol=2)
def test_node_responds(csp_lab):
    assert csp_lab.ping(2).reachable

Tests using csp_lab share a lab for the pytest session by default. Use @pytest.mark.csp_lab(scope="function") for a fresh lab per test; protocol 1 and 2 use separate projects. The fixture skips when Docker or Compose is unavailable. An interrupted process can leave containers behind: list their project names with docker ps -a --filter label=com.docker.compose.project --format '{{.Label "com.docker.compose.project"}}' | sort -u, then run csp-lab cleanup <csp-lab-py-project> for the affected project.

Local development

From a clone of this repository:

git submodule update --init --recursive
uv sync --locked
uv run --locked csp-lab up --protocol 2 --build
uv run --locked csp-lab ping 2 --json
uv run --locked csp-lab doctor --json
uv run --locked csp-lab down

--build compiles the native image from this checkout, so it needs the libcsp submodule. Without --build, the CLI uses the image matching its own version from GHCR.

What is tested

uv run --locked pytest checks protocol validation, unavailable Docker, cleanup after a failed start, and unresponsive nodes without requiring Docker. Run uv run --locked ruff check src/csp_lab tests and uv run --locked mypy src/csp_lab for lint and types. The Docker integration flow exercises real libcsp, ZMQ, CLI diagnostics, and MCP for both protocol versions:

bash test/integration.sh

The GitHub Actions workflow is configured to run both checks on Ubuntu with Docker Compose. The integration script uses its own temporary XDG_STATE_HOME and unique CSP_LAB_PROJECT, and cleans only those resources on exit, including after a failure. It does not adopt checkout-based legacy labs. If cleanup fails, it reports the project and retains the temporary state for recovery.

Scope and license

This lab uses the pinned libcsp release as a build dependency and selects CSP v1 or v2 as a runtime protocol. It does not build against historical libcsp 1.x releases or operate mixed-version networks. ZMQ is the only transport in this lab. The project is licensed under MIT; the libcsp submodule retains its own license. Thanks to the libcsp and ZeroMQ projects that make the image possible; their licenses and source links are listed in THIRD_PARTY_NOTICES.md.

Metadata

Release files for csp-lab 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 csp-lab 0.2.0
File Size Uploaded Provenance Actions
csp_lab-0.2.0.tar.gz 13.4 kB With provenance Details for csp_lab-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for csp-lab 0.2.0
File Interpreter ABI Platform Actions
csp_lab-0.2.0-py3-none-any.whl Python 3 none any Details for csp_lab-0.2.0-py3-none-any.whl

Total release size: 28.9 kB

Release files / csp_lab-0.2.0.tar.gz

Download URL csp_lab-0.2.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ae82c070eee8c475a010c598909bad1706f09ebdf6000d892744152daee67c22
BLAKE2b-256 checksum
How to use checksums
a9587ba9344b3cc83cad345f21177245a59476e8faf36be07a07e6ba006d1a37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 4, 2026.

Transparency log

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

Download URL csp_lab-0.2.0-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8447c64abf57a2904fd2bd173bba3478e4db02578864211c9994bc88d49116e
BLAKE2b-256 checksum
How to use checksums
f10d6fb125ebc3770a79236a034bd9fb804e824ec573220dc80991f8ab014be8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 4, 2026.

Transparency log

Security for csp-lab 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 csp_lab-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 4, 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