Shared PLC-style primitives in Python
Project description
timers-latches
Lightweight, production-ready implementations of PLC-style primitives in Python:
TON — On-delay timer
SR — Set/Reset latch (reset dominant)
These primitives are useful for industrial automation logic, simulations, or anywhere you want PLC-like control behavior in Python.
Installation pip install timers-latches
Or, for development:
git clone https://github.com/yourorg/timers-latches.git cd timers-latches pip install -e .
Usage from timers_latches import TON, SR
--- TON example ---
ton = TON(preset_s=2.0) # 2-second delay for step in range(5): q = ton.update(enable=True, dt_s=0.5) print(f"t={step*0.5:.1f}s, Q={q}")
Q will turn True after 2.0 seconds of accumulated enable time
--- SR example ---
latch = SR(initial=False) print(latch.update(set_=True, reset=False)) # True print(latch.update(set_=False, reset=True)) # False (reset dominates)
API TON(preset_s: float)
preset_s: delay time in seconds (must be ≥ 0).
.update(enable: bool, dt_s: float) -> bool: call once per scan; returns the done bit (Q).
.Q: current output (done bit).
SR(initial: bool = False)
initial: starting state.
.update(set_: bool, reset: bool) -> bool: updates and returns current state. Reset dominates set.
.state: current latched state.
Versioning
Follows Semantic Versioning .
API is stable from 1.0.0 onward.
License
MIT © Your Name / Your Organization
⚡️ This package is intentionally minimal and focused: no dependencies, only core primitives. You can drop it into simulations, control logic, or larger automation frameworks.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file primitives-0.1.0.tar.gz.
File metadata
- Download URL: primitives-0.1.0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
156fd13c04a1cfa568e4602dfa3e0684ae960d99396a7ff2544d47032a9a0c47
|
|
| MD5 |
d30c57e4dd4142f21877643e61d73447
|
|
| BLAKE2b-256 |
a3e65c37751e06ecfa7400b6e27154cd0dcdf3ca40297e0ec2cf6dc0456b14c3
|
File details
Details for the file primitives-0.1.0-py3-none-any.whl.
File metadata
- Download URL: primitives-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da0bd6947d9e06ec533bce8fea3f3fd6c9a6c1b2f83ebe6a8e60ade3004566d5
|
|
| MD5 |
8c72640cbc522d6edca9f70758448fde
|
|
| BLAKE2b-256 |
3130997fc581aefdabad32eecec335372b7ec251551dcae32c5306debd2f3c84
|