Skip to main content

Interlocking

One track, one train.
Easy to run. Explicit to control.

Interlocking is a framework for managing background task execution in distributed environments. The name comes from the railway interlocking system, which prevents two trains from entering the same track at the same time. Exclusive control is at the core of the library. Using a railway metaphor, it manages the lifecycle of batch tasks (exclusive control, run records, and CLI integration) in a single, consistent way.

Features

  • Exclusive control: The same task never runs concurrently.
  • Run records: Stores the result of the most recent run and hands it over to the next one (Coupler).
  • CLI integration: Builds a command line from type hints and reports the result through the exit code.
  • Pluggable: Extend behavior with a Station (storage backend) or TrainMiddleware.

Installation

pip install interlocking

To use S3 as the storage backend:

pip install "interlocking[aws]"

Requires Python 3.11 or later.

Quick start

# tasks.py
from typing import Annotated
from interlocking import Line, Coupler

line = Line()

@line.track(name="daily", help="Daily job")
def daily_task(c: Coupler, target_date: Annotated[str, "Target date (YYYY-MM-DD)"]) -> dict:
    last_id = c.last_data.get("last_id", 0)
    # ... do the work ...
    return {"last_id": 9999}
# main.py
import sys

from interlocking import TrainDispatcher, LocalStation, InterlockingCLI

dispatcher = TrainDispatcher(
    station=LocalStation(base_path=".interlocking"),
    lines={"batch": "tasks:line"},
)

cli = InterlockingCLI(dispatcher=dispatcher, prog="my-task", description="Batch tasks")
sys.exit(cli.execute(cli.parse_args()))  # report the result via exit code
# `start` makes the intent to run explicit: without it, nothing runs
python main.py start batch daily --target-date 2026-04-01

# Release a stuck lock (a separate management operation)
python main.py abort batch daily

License

MIT

Metadata

Release files for interlocking 0.3.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 interlocking 0.3.0
File Size Uploaded Provenance Actions
interlocking-0.3.0.tar.gz 28.3 kB Without provenance Details for interlocking-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 61.8 kB

Release files / interlocking-0.3.0.tar.gz

Download URL interlocking-0.3.0.tar.gz
Size 28.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b519ec19422c38ac09bd83fe0a6f48629b7c3f263b682fc9c3f1fe65a03558c9
BLAKE2b-256 checksum
How to use checksums
a36c1b9d518a7fa004112ca37e3e02a5b69ea73a3fed039299f172001032120e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / interlocking-0.3.0-py3-none-any.whl

Download URL interlocking-0.3.0-py3-none-any.whl
Size 33.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ab37f812fd69ae64248b930e4a6d212f60b7ad2d4abb85ee11346d73dfbd82c
BLAKE2b-256 checksum
How to use checksums
d60f63aaeccabe7de565b10f88f34cbd703ea578cf3381f765ab8931dab6f693
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for interlocking 0.3.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.

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