Skip to main content

pyrung

Write ladder logic in Python. Test it. Deploy it to CLICK.

pyrung turns a Python with block into a ladder rung: condition on the rail, instruction in the body. Same rungs, same scan order, same timers as the CLICK PLC, with git, pytest, and a debugger around them.

from pyrung import Bool, PLC, Program, rung, out

Button = Bool()
Light = Bool()

with Program() as logic:
    with rung(Button):
        out(Light)

with PLC(logic) as plc:
    Button.value = True
    plc.step()
    assert Light.value is True

Why

CLICK Programming Software ships with no simulator, no version control beyond copies of a .ckp, and no way to test a program short of downloading it to a real PLC. pyrung fills that gap. It is the engine under ClickNick's CLICK Simulator, and a suite of test cases checks it against a real CLICK, case by case. Write and test the logic in Python, then move the same rungs into CLICK.

A simulator, not a substitute for testing. The conformance results come from one CPU (a C2-03CPU with CLICK V4.00), and yours may differ in ways the suite doesn't reach. The known differences are listed. Test on the real machine, with proper safeguards, before anything interacts with people. pyrung and ClickNick are independent projects, not affiliated with or endorsed by AutomationDirect.

Same source, three paths: pyrung_to_ladder() encodes your rungs for ClickNick to paste into CLICK Programming Software; the CircuitPython dialect generates a scan loop for a P1AM-200; or run it as an emulated CLICK over Modbus and test two programs talking to each other with no hardware.

Who it's for

Controls engineers who want to test CLICK logic without hardware. Write with plain tag names, map them to X, Y, C, and DS addresses when you're ready, and let the validator tell you what CLICK's memory banks will and won't accept before you find out at the PLC.

Python developers entering industrial automation. pyrung teaches ladder logic in the language and tools you already have: Python, pytest, and VS Code. Start with Know Python? Learn Ladder Logic.

Makers and P1AM-200 users who want a real scan cycle without writing the plumbing. The same program you tested on your laptop generates a CircuitPython scan loop with timers, counters, Modbus TCP, and SD-backed retentive state.

Quick start

# Requires Python 3.11+
uv add pyrung

Download the starter project (pyrung-starter-VERSION.zip) from the GitHub releases page for ready-to-run examples with CLICK CSV round-trip. For the VS Code debugger, grab pyrung-debug-VERSION.vsix from the same page and install it:

code --install-extension pyrung-debug-VERSION.vsix

A motor with start/stop logic

from pyrung import Bool, Program, rung, latch, reset

Start = Bool()
Stop = Bool()
Running = Bool()

with Program() as logic:
    with rung(Start):
        latch(Running)
    with rung(Stop):
        reset(Running)

Test it

from pyrung import PLC

with PLC(logic) as plc:
    Start.value = True
    plc.step()
    assert Running.value is True

    # Release start — motor stays latched
    Start.value = False
    plc.step()
    assert Running.value is True

    Stop.value = True
    plc.step()
    assert Running.value is False

Map to CLICK hardware when you're ready

from pyrung.click import ClickBlocks, TagMap

x, y, c, t, ct, sc, ds, dd, dh, df, xd, yd, xd0u, yd0u, td, ctd, sd, txt = ClickBlocks()

mapping = TagMap({
    Start:   x[1],    # Physical input  → X001
    Stop:    x[2],    # Physical input  → X002
    Running: y[1],    # Physical output → Y001
})

mapping.validate(logic)                # Checks against CLICK constraints
mapping.to_nickname_file("motor.csv")  # For CLICK programming software

What's included

Core engine

Coils, latches, timers, counters, branching, subroutines, structured tags, and edge detection. Every scan is a pure function, so you can fork, rewind, and diff any state in history.

CLICK dialect

Map tags to X, Y, C, DS, and the other CLICK banks. The validator checks the program against CLICK's memory rules and instruction set. Export the nickname CSV and the ladder for ClickNick to paste. Import an existing project the other way.

CircuitPython dialect

Generate a self-contained scan loop for the P1AM-200 with 35 supported I/O modules, SD-backed retentive storage, watchdog, and Modbus TCP.

Analysis

logic.simplified()["Motor"] resolves a 14-rung interlock chain to the handful of inputs that actually decide it. plc.cause(Running) names why a tag changed. plc.why(Alarm) does it from a tag dump off a faulted machine. plc.how(Running) finds the input changes that reach a state, or says why none can. how() is experimental; the rest is stable.

VS Code debugger

Step through scans rung by rung, set breakpoints on rungs, force tags, and time-travel through history. Watch tags live, see the dependency graph, and record a session to replay later.

Disclaimers

  • Simulation is best-effort. pyrung models CLICK PLC behavior as closely as practical, but it is not a certified simulator. You are responsible for verifying your program on real hardware before production use. The CLICK Conformance page lists what was checked against a real CLICK and the known differences.
  • Modbus is unauthenticated. The emulated CLICK Modbus interface and CircuitPython Modbus TCP server listen on the network with no encryption or access control — standard for Modbus, but keep them off untrusted networks.

Metadata

Release files for pyrung 0.18.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 pyrung 0.18.0
File Size Uploaded Provenance Actions
pyrung-0.18.0.tar.gz 5.5 MB With provenance Details for pyrung-0.18.0.tar.gz

Built distribution (wheel)

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

Total release size: 7.5 MB

Release files / pyrung-0.18.0.tar.gz

Download URL pyrung-0.18.0.tar.gz
Size 5.5 MB
Tags Source
SHA-256 checksum
How to use checksums
f35e5c2fce0e2f0174ce5c0d4a5d5d58dafd6ab3c1b03700cd1ece9333bfbda8
BLAKE2b-256 checksum
How to use checksums
4f79a02681f746335cc99ad8c3cdff8c01d6a3a00d6d13b09d37ff507885945b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Transparency log

Release files / pyrung-0.18.0-py3-none-any.whl

Download URL pyrung-0.18.0-py3-none-any.whl
Size 2.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
8c03408528e9adb034cf15b1f64017bb3d0c1dbc4a553890577c218fae4558f9
BLAKE2b-256 checksum
How to use checksums
8e6adcfcd363a31b5153302715a4674a26e5d4347cc77a75475186a3d41cb6bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Transparency log

Security for pyrung 0.18.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 pyrung-0.18.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 20, 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.

Release history Release notifications | RSS feed

This release

0.18.0 This release

2 release files Full provenance

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