Skip to main content

pympacds-gpio

GPIO server service for pympacds. Monitors GPIO line state and edge events and exposes reads, writes, and change notifications over D-Bus.

Features

  • Reads (get_value, get_lines) and writes (set_value) of GPIO lines over D-Bus, with per-output-line default (reset) values (get_default_value / set_default_value).
  • Edge-event watching (line_changed signal) driven by the kernel gpiod edge-event API, polled asynchronously with a short timeout so the event loop is never stalled.
  • Kernel-side debounce via debounce_us (passed to libgpiod), and active_low inversion for watched lines. No software debounce.
  • A configurable line-name mapping ([gpio.linemap]) so lines can be referenced by human-readable name or numeric offset on the D-Bus API.
  • Runtime configuration: [gpio] keys are writable via the framework ConfigContract.
  • Exports the framework HealthContract (always) and ConfigContract (opt-in via [dbus] contract_config = true) alongside the GPIO contract.

Why gpiod

The service uses the gpiod Python bindings (libgpiod v2 API) because it is the reference userspace interface to the kernel GPIO character-device subsystem: line requests, edge events, and debounce are all handled in the kernel. It is isolated in this service's own package, so the core pympacds framework keeps its zero-dependency property.

Installation

Using PIP

pip install pympacds-gpio

Using pip installs the Python package only — the D-Bus policy, systemd unit, and udev rule are not installed. You can still run the service directly with pympacds-gpio -c /etc/pympacds/gpio.ini, or register and enable it system-wide with the admin script. Since there is no packaged unit, pass the pip-installed executable via --program so the unit is generated:

sudo pympacds-admin setup                      # one-time: user, log dir, D-Bus policy
sudo pympacds-admin install gpio \
    --program "$(command -v pympacds-gpio)" \
    --config /etc/pympacds/gpio.ini --start

Under pip you must also grant access to /dev/gpiochip* yourself (see Device access below); the udev rule ships only with the Debian package.

Alternatively, install the Debian package (see below), which already ships the unit, policy, and udev rule.

Using PPA

Debian packages are provided through launchpad ppa (dargor0/mpacds):

sudo add-apt-repository ppa:dargor0/mpacds
sudo apt update
sudo apt install python3-pympacds-gpio

The package installs the service system-wide (executable, systemd unit, D-Bus policy, udev rule, and the gpio.ini.example config) and depends on python3-pympacds.

Repository has been tested on Ubuntu (plucky, resolute, stonking) and Debian (stable, testing, unstable).

Configuration

The service reads its parameters from the [gpio] INI section and the optional [gpio.linemap] section (see config/gpio.ini.example):

Key Default Description
chip "" GPIO chip path (empty = auto-detect)
lines "" Comma-separated line names/offsets to expose and read
watch_lines "" Lines watched for edge events
edge both Edge to watch: rising, falling, both
debounce_us 0 Kernel debounce period (µs) for watched lines
active_low false Invert line logic for watched lines
output_lines "" Lines driven as outputs
default_values "" line=value pairs for output defaults (e.g. relay1=0,5=1)

The [gpio.linemap] section maps human-readable names to offsets (btn = 0). Names must not begin with a digit.

Run with:

pympacds-gpio -c /etc/pympacds/gpio.ini

Device access (permissions)

The service does not require root. Access to /dev/gpiochip* is granted via a udev rule (shipped by the Debian package) that assigns the device to the gpio group with mode 0660; add the service user to the gpio group:

sudo usermod -aG gpio <service-user>

D-Bus API

Interface org.pympacds.GPIO at object path /org/pympacds/gpio:

Member Type Description
get_value(line) get_value(s) -> b Read a line's value
set_value(line, value) set_value(sb) -> b Set an output line
get_default_value(line) get_default_value(s) -> b Default (reset) value of an output
set_default_value(line, value) set_default_value(sb) -> b Set the default value
get_lines() get_lines() -> s JSON values of all exposed lines
status() status() -> s JSON chip/line configuration + values
line_changed(name, offset, value) signal (sub) Emitted on a watched edge event
watched_lines property (as) List of watched lines

A line argument is a decimal offset or a [gpio.linemap] name, resolved number-first-then-name. An unresolvable line produces a D-Bus error reply.

The framework HealthContract (at .../health) and ConfigContract ([dbus] contract_config = true) are also exported.

Metadata

Release files for pympacds-gpio 0.1.2

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

Source distribution (sdist)

Source distribution for pympacds-gpio 0.1.2
File Size Uploaded
pympacds_gpio-0.1.2.tar.gz 18.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pympacds-gpio 0.1.2
File Interpreter ABI Platform
pympacds_gpio-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 28.4 kB

Release files / pympacds_gpio-0.1.2.tar.gz

Download URL pympacds_gpio-0.1.2.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4a8fe661ba5fd62f122347c67ea4793d5ebe850479d30624b4b325f99a2fdf1b
BLAKE2b-256 checksum
How to use checksums
6112cdeb0dd5dd4ecde72c52406b980d18198f54cadc0d7ecb09c74bb532c2ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / pympacds_gpio-0.1.2-py3-none-any.whl

Download URL pympacds_gpio-0.1.2-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03f6dd483e2986285e8515000f370fe30db4a532aefd17ee771f606e0b09bce9
BLAKE2b-256 checksum
How to use checksums
3e009474fe1389d7db113b49a7db9aad29f75a92422602c00cad4763d8523553
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.0

2 release files

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