Skip to main content

Py-Micro-HIL

Py-Micro-HIL is a modular, lightweight Hardware-in-the-Loop (HIL) testing framework for Python.
It provides a unified interface for testing embedded systems, sensors, and communication buses
(Modbus RTU, SPI, I2C, UART, GPIO) both on Raspberry Pi hardware and in PC simulation mode.


🚀 Overview

Py-Micro-HIL enables automated functional and integration testing of embedded systems.
It supports both real hardware execution on Raspberry Pi and simulated environments on any PC.

With this framework you can:

  • Write and organize test suites for hardware peripherals.
  • Interface with GPIO, SPI, I2C, UART, or Modbus RTU devices.
  • Use mocks for offline or CI/CD testing.
  • Generate structured HTML and console reports.
  • Integrate easily with pipelines or GitHub Actions.

🔗 Documentation

📚 Full developer and user documentation is available here:
➡️ https://niwciu.github.io/PY_MICRO_HIL


⚙️ Installation

🧰 Option 1 – From PyPI (recommended for most users)

pip install py-micro-hil

🧪 Option 2 – From source (for contributors)

git clone https://github.com/niwciu/PY_MICRO_HIL.git
cd PY_MICRO_HIL
pip install -e .

💡 On your hil test server, you can use the flag --break-system-packages to simplify installation and usage for CI/CD environments:

pip install py-micro-hil --break-system-packages

It will make your life easier whe using it in services like GitHub Actions

dependencies

pymodbus, pytest, smbus2, spidev, pyserial

Developer setup

For development and contribution:

git clone https://github.com/niwciu/PY_MICRO_HIL.git
cd PY_MICRO_HIL
pip install -e .[dev]

🧩 Example usage

1️⃣ Create a configuration file

In the project root for your project hil tests main folder, create a file peripherals_config.yaml, for example:

peripherals:
  gpio:
    - pin: 17
      mode: out
      initial: low
    - pin: 18
      mode: in

Full configuration reference:
📖 Configuration and YAML guide →


2️⃣ Create test files

Create a directory named hil_tests/ and add your test groups there.
Each .py file should start it's name from test and represents a test group.

Example: hil_tests/test_gpio_led.py

from py_micro_hil.assertions import *
from py_micro_hil.framework_API import *

def setup_group():
    TEST_INFO_MESSAGE("Setting up gpio led test group")

def teardown_group():
    TEST_INFO_MESSAGE("Tearing down gpio led test group")

def test_led_toggle():
    gpio = get_RPiGPIO_peripheral()
    gpio.write(17, 1)
    TEST_
    TEST_ASSERT_EQUAL (1, gpio.read(18))

3️⃣ Run the tests

Before running tests check available options by typing:

hiltests --help

Use the built-in CLI runner:

hiltests --config ./peripherals_config.yaml --test-dir ./hil_tests

Generate a starter group from the editable template without executing any tests:

hiltests --create-test-group gpio_smoke ./hil_tests

If both the YAML configuration and the hil_tests folder are in the same directory,
simply open this directory and run:

hiltests

4️⃣ Generate reports

Py-Micro-HIL can generate both console log files and HTML reports.

Example:

hiltests --log ./reports/log.txt

or

hiltests --html ./reports/report.html

Reports can be customized with name and path.
See: Reports and Logging →


💡 Features

  • ✅ Unified test structure (TestFramework, TestGroup, Test)
  • ✅ Automatic setup/teardown with context isolation
  • ✅ YAML-driven configuration system
  • ✅ Dynamic test discovery (tests_group_factory)
  • ✅ Mock peripherals for PC environment (not RPi)
  • ✅ Full logging and HTML report generation
  • ✅ Native CLI interface (hiltests)
  • ✅ Compatible with Raspberry Pi and Linux hosts

🧰 Supported peripherals & protocols

Peripheral Class Description
GPIO RPiGPIO Digital I/O control
PWM RPiPWM, RPiHardwarePWM Software and hardware PWM
UART RPiUART Serial communication via pyserial
I²C RPiI2C SMBus-compatible interface
SPI RPiSPI SPI interface via spidev
1-Wire RPiOneWire DS18B20 temperature sensors via w1-gpio
Modbus RTU ModbusRTU RS-485 communication via pymodbus

🧩 These are the currently implemented peripherals.
You can easily extend the framework by adding your own peripherals in the
src/py_micro_hil/peripherals/ directory and implementing the required abstract interfaces.
The developer documentation includes full guidance on this process.


🤝 Contributing

We welcome contributions from the community!
Please ensure your code follows PEP-8 style and includes tests.

  1. Fork this repository
  2. Clone and install in development mode:
    git clone <link to your fork>.git
    cd PY_MICRO_HIL
    pip install -e .[dev]
    
  3. Create a new branch:
    git checkout -b feature/my-feature
    
  4. Make your changes and test:
    pytest -v
    
  5. Submit a pull request with a clear description and test coverage.

Full contribution guide:
📘 Developer Guide →


📄 License

This project is licensed under a custom non-commercial license.

Commercial use is strictly prohibited without prior written permission. See the LICENSE file for full terms.


myEmbeddedWayBanner


Metadata

Release files for py-micro-hil 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-micro-hil 0.1.8
File Size Uploaded Provenance Actions
py_micro_hil-0.1.8.tar.gz 65.0 kB Without provenance Details for py_micro_hil-0.1.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-micro-hil 0.1.8
File Interpreter ABI Platform Actions
py_micro_hil-0.1.8-py3-none-any.whl Python 3 none any Details for py_micro_hil-0.1.8-py3-none-any.whl

Total release size: 118.5 kB

Release files / py_micro_hil-0.1.8.tar.gz

Download URL py_micro_hil-0.1.8.tar.gz
Size 65.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d3250b77c4fb5f18c071b802fa1204d3c33ebbaad2e3ce20986369161d5505d5
BLAKE2b-256 checksum
How to use checksums
024c091aaad93fbc2d8f9242fb838cc2e0f69b9f9fa8f96ef540f6eb1f685d80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / py_micro_hil-0.1.8-py3-none-any.whl

Download URL py_micro_hil-0.1.8-py3-none-any.whl
Size 53.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
985d1a5de02a3cf58cda652531ef6a38544763e796535e2eb3bf7323216d4c3c
BLAKE2b-256 checksum
How to use checksums
b3573ccfe7ac6f66bc5e5362d60cfc1fafb07fe25d6a5f5a0c47a9532fe99ecc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for py-micro-hil 0.1.8

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.

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