PyFactoryIO
PyFactoryIO is a Python library that provides a high-level, modular Modbus interface for interacting with Factory I/O. It allows you to easily connect your Python control logic to Factory I/O simulations, abstracting away the low-level Modbus TCP communication and mapping digital/register inputs and outputs by name.
Features
- Easy Configuration: Map Factory I/O sensors and actuators using descriptive names instead of Modbus addresses.
- Event-Driven & Loop-Based Execution: Provides decorators to run callbacks on state changes, or a continuous control loop for cyclic execution.
- Auto-Mapping: Automatically handles Modbus coils, discrete inputs, holding registers, and input registers.
- Lightweight: Built on top of
pyModbusTCP.
Installation
You can install pyfactoryio directly via pip:
pip install pyfactoryio
Quick Start
1. Configure Factory I/O
Ensure Factory I/O is configured to use the Modbus TCP Server driver. By default, PyFactoryIO listens on 127.0.0.1 port 5020.
2. Basic Example
Here is a simple example demonstrating how to read a sensor and trigger an actuator.
from pyfactoryio import FactoryIOServer
# Define your input and output names in the order they appear in Factory I/O
DI_NAMES = ["Sensor_1", "Start_Button"]
DO_NAMES = ["Conveyor", "Warning_Light"]
# Initialize the server
server = FactoryIOServer(
di_names=DI_NAMES,
do_names=DO_NAMES
)
# Example 1: Event-driven callback
@server.on_change("Start_Button")
def on_start_pressed(value):
if value:
print("Start button pressed!")
server.Conveyor = True
else:
print("Start button released!")
server.Conveyor = False
# Example 2: Continuous control loop
def my_logic(srv):
# This function is called continuously by run_loop
if srv.Sensor_1:
srv.Warning_Light = True
else:
srv.Warning_Light = False
if __name__ == "__main__":
# Start the event loop (e.g., at 10Hz)
server.run_loop(logic_func=my_logic, hz=10)
3. Robotic Sorting Example
A more advanced example demonstrating a robust state machine for a Two-Axis Pick & Place robot. It uses a retroreflective sensor to detect incoming items, a vision sensor to determine their color, and automatically feeds the conveyor belt while sorting items to the left or right belts.
See the full implementation in sorting_robot.py.
Supported Variable Types
- di_names: Digital Inputs (Sensors, Buttons) - Read from Factory I/O via Coils.
- do_names: Digital Outputs (Conveyors, Lights) - Written to Factory I/O via Discrete Inputs.
- ri_names: Register Inputs (Analog Sensors) - Read from Factory I/O via Holding Registers.
- ro_names: Register Outputs (Analog Actuators) - Written to Factory I/O via Input Registers.
License
This project is licensed under the MIT License.
Metadata
Release files for pyfactoryio 0.1.1
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 |
|---|---|---|---|---|
| pyfactoryio-0.1.1.tar.gz | 5.3 kB | With provenance | Details for pyfactoryio-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyfactoryio-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pyfactoryio-0.1.1-py3-none-any.whl |
Total release size: 11.0 kB
Release files / pyfactoryio-0.1.1.tar.gz
| Download URL | pyfactoryio-0.1.1.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
520b3e8f5508df6afdc2760e45d76a4cd79302154481f8a905cd26c43a4b1422
|
|
BLAKE2b-256 checksum How to use checksums |
388c039840dff75c37041c0e5f78b79c56f506f5f7e0e631a6b0949f9a53ba1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jun 5, 2026.
Transparency logRelease files / pyfactoryio-0.1.1-py3-none-any.whl
| Download URL | pyfactoryio-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
150d4ab5f7cf3761166dd073c4dd2070ccd6f1ddce49940f1ac39079f665c69d
|
|
BLAKE2b-256 checksum How to use checksums |
81a26b213f792bdc1c25b1393180978fe94016f2ba76fe31f9e59fccef39444f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jun 5, 2026.
Transparency logSecurity for pyfactoryio 0.1.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyfactoryio-0.1.1.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 Jun 5, 2026.
Transparency logA 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.