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.2.1

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.2.1
File Size Uploaded Provenance Actions
interlocking-0.2.1.tar.gz 27.2 kB Without provenance Details for interlocking-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 59.8 kB

Release files / interlocking-0.2.1.tar.gz

Download URL interlocking-0.2.1.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
53d09db8feb94f33e8dc53fdce0ffe74b1066c0c2d7f2f6befd62f73964fe459
BLAKE2b-256 checksum
How to use checksums
a07e6a0018a3ca7795b24db135eb5d8a4b1b32481d4951ce4afb58d1e17cf63c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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.2.1-py3-none-any.whl

Download URL interlocking-0.2.1-py3-none-any.whl
Size 32.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f8ae9e1deb9d35827b202f0566199bc7c790e8264851da49ed849b6eb9ee3b1
BLAKE2b-256 checksum
How to use checksums
6656ed4cec61729f37da46ab31a8cc850bdc694061207231c47dd3953b2eed71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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.2.1

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