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) orTrainMiddleware.
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.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 |
|---|---|---|---|---|
| interlocking-0.2.0.tar.gz | 27.1 kB | Without provenance | Details for interlocking-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| interlocking-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for interlocking-0.2.0-py3-none-any.whl |
Total release size: 59.4 kB
Release files / interlocking-0.2.0.tar.gz
| Download URL | interlocking-0.2.0.tar.gz |
|---|---|
| Size | 27.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd6f19d724716f72aed249cbfa477e3814a408d4008cf6ca53482bf803769e8b
|
|
BLAKE2b-256 checksum How to use checksums |
17f00f37d001eb45ebd56af771113974f170a41d44fef138fa5c18a76364a314
|
| 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.2.0-py3-none-any.whl
| Download URL | interlocking-0.2.0-py3-none-any.whl |
|---|---|
| Size | 32.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6c33a2374660f2c787a1a8a1e404440dfaecef78c6a176b3590bd884d82a53a4
|
|
BLAKE2b-256 checksum How to use checksums |
b1b382006471f0e684d885d2af76772babda69691531ffeb214af609fd42b65d
|
| 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.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.
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.