pySimplePID
A small deterministic PID controller library for Python.
Usage
from pySimplePID import PID
pid = PID(kp=2.0, ki=0.1, target=22.0)
thermal_output = pid.update(current_value=20.5)
pid.set_target(24.0)
kp is required. ki and kd default to 0.0; any component with a gain of
zero is disabled. Output is capped between -100 and 100 by default, where
positive values heat and negative values cool.
Elapsed time is measured internally between calls to update(). Tests and
simulations can inject a custom clock with time_function.
PID Output Limits for Heating and Cooling
The PID output sign is conventional:
positive output -> heat
negative output -> cool
Use output_min and output_max to match the actuators available in your
system.
| System type | output_min |
output_max |
Meaning |
|---|---|---|---|
| Heating only | 0.0 |
100.0 |
Output can only add heat |
| Cooling only | -100.0 |
0.0 |
Output can only remove heat |
| Heating and cooling | -100.0 |
100.0 |
Positive heats, negative cools |
Heating Only
Use this when the system can add heat but cannot actively cool:
pid = PID(
kp=2.0,
ki=0.1,
target=22.0,
output_min=0.0,
output_max=100.0,
)
Output range:
0% ... 100%
Cooling Only
Use this when the system can remove heat but cannot actively heat, such as a Peltier used only for cooling:
pid = PID(
kp=2.0,
ki=0.1,
target=5.0,
output_min=-100.0,
output_max=0.0,
)
Output range:
-100% ... 0%
For a cooling actuator that expects a positive drive value, invert the sign:
cooling_drive = max(0.0, -pid.update(current_temperature))
Heating and Cooling
Use this when the system has both actuators, or one bidirectional actuator:
pid = PID(
kp=2.0,
ki=0.1,
target=22.0,
output_min=-100.0,
output_max=100.0,
)
Output range:
-100% ... 100%
Then split the output by sign:
output = pid.update(current_temperature)
heating_drive = max(0.0, output)
cooling_drive = max(0.0, -output)
Temperature Simulation
The examples include a minimal first-order radiator model in
examples/models.py. It is intentionally not part of the library API:
from models import TemperatureRadiator
from pySimplePID import PID
pid = PID(kp=30.0, ki=0.2, target=22.0)
radiator = TemperatureRadiator(
initial_temperature=16.0,
ambient_temperature=12.0,
heat_capacity=120.0,
heat_loss_coefficient=2.0,
)
thermal_output = pid.update(radiator.current_temperature)
temperature = radiator.step(thermal_output, dt=1.0)
The model uses:
temperature += (thermal_power - heat_loss_coefficient * (temperature - ambient))
/ heat_capacity
* dt
Examples
PYTHONPATH=src python3 examples/basic_pid.py
PYTHONPATH=src python3 examples/temperature_radiator.py
The temperature example prints CSV-style data:
time,temperature,target,thermal_output
There is also an optional Qt example with live charts and editable PID
parameters. Its PID interval control changes how often the controller is
sampled while the radiator model continues to run on a fixed fast timestep.
Heating and cooling power fields convert PID output percentage into watts:
for example, 10 % output with 5 W heating power applies 0.5 W.
python3 -m pip install '.[gui]'
PYTHONPATH=src python3 examples/temperature_radiator_qt.py
The SiPM/Peltier Qt example uses a thin aluminium thermal mass, a small SiPM heat load, ambient exchange, and Peltier cooling:
PYTHONPATH=src python3 examples/sipm_qt.py
Tests
PYTHONPATH=src python3 -m unittest discover -s tests
Metadata
Release files for pySimplePID 0.1.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 | |
|---|---|---|---|---|
| pysimplepid-0.1.0.tar.gz | 6.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pysimplepid-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.9 kB
Release files / pysimplepid-0.1.0.tar.gz
| Download URL | pysimplepid-0.1.0.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a939de91c1b0ccede823357c5f66f0949f4a3941d82ecaa57a599845e8a9e42e
|
|
BLAKE2b-256 checksum How to use checksums |
670eda0b1b4b25745ff9976bc0ab313945e564d5f2182a49c513f0726aae6637
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Release files / pysimplepid-0.1.0-py3-none-any.whl
| Download URL | pysimplepid-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
25d1034c3f1488e82c8e6c1b0b148c056702bfb6e0a8030a69a7b967e83fc087
|
|
BLAKE2b-256 checksum How to use checksums |
7dbd2154b6f81015559e00e2852804aaddce6d01fcb6cd5380070e8b7941a595
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Security for pySimplePID 0.1.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.