Skip to main content

linuxpy

linuxpy Python Versions License CI

Source Documentation

Human friendly interface to linux subsystems using python.

Provides python access to several linux subsystems like V4L2, GPIO, Led, thermal, input and MIDI.

There is experimental, undocumented, incomplete and unstable access to USB.

Requirements:

  • python >= 3.11
  • Fairly recent linux kernel
  • Installed kernel modules you want to access

And yes, it is true: there are no python libraries required! Also there are no C libraries required. Everything is done here through direct ioctl, read and write calls. Ain't linux wonderful?

Installation

From within your favorite python environment:

$ pip install linuxpy

To run the examples you'll need:

$ pip install linuxpy --group=examples

To develop, run tests, build package, lint, etc you'll need:

$ pip install linuxpy --group=dev

Subsystems

GPIO ⚡

from linuxpy.gpio import Device

with Device.from_id(0) as gpio:
    info = gpio.get_info()
    print(info.name, info.label, len(info.lines))
    l0 = info.lines[0]
    print(f"L0: {l0.name!r} {l0.flags.name}")

# output should look somethig like:
# gpiochip0 INT3450:00 32
# L0: '' INPUT

Check the GPIO user guide and GPIO reference for more information.

Input 🕹️

import time
from linuxpy.input.device import find_gamepads

pad = next(find_gamepads())
abs = pad.absolute

with pad:
    while True:
        print(f"X:{abs.x:>3} | Y:{abs.y:>3} | RX:{abs.rx:>3} | RY:{abs.ry:>3}", end="\r", flush=True)
        time.sleep(0.1)

Check the Input user guide and Input reference for more information.

Led 💡

from linuxpy.led import find

caps_lock = find(function="capslock")
print(caps_lock.brightness)
print(caps_lock.max_brightness)

Check the LED user guide and LED reference for more information.

MIDI Sequencer 🎹

$ python

>>> from linuxpy.midi.device import Sequencer, event_stream

>>> seq = Sequencer()
>>> with seq:
        port = seq.create_port()
        port.connect_from(14, 0)
        for event in seq:
            print(event)
 14:0   Note on              channel=0, note=100, velocity=3, off_velocity=0, duration=0
 14:0   Clock                queue=0, pad=b''
 14:0   System exclusive     F0 61 62 63 F7
 14:0   Note off             channel=0, note=55, velocity=3, off_velocity=0, duration=0

Check the MIDI user guide and MIDI reference for more information.

Thermal and cooling 🌡️

from linuxpy.thermal import find

with find(type="x86_pkg_temp") as tz:
    print(f"X86 temperature: {tz.temperature / 1000:6.2f} C")

Check the Thermal and cooling user guide and Thermal and cooling reference for more information.

Video 🎥

Video for Linux 2 (V4L2) python library

Without further ado:

>>> from linuxpy.video.device import Device
>>> with Device.from_id(0) as cam:
>>>     for i, frame in enumerate(cam):
...         print(f"frame #{i}: {len(frame)} bytes")
...         if i > 9:
...             break
...
frame #0: 54630 bytes
frame #1: 50184 bytes
frame #2: 44054 bytes
frame #3: 42822 bytes
frame #4: 42116 bytes
frame #5: 41868 bytes
frame #6: 41322 bytes
frame #7: 40896 bytes
frame #8: 40844 bytes
frame #9: 40714 bytes
frame #10: 40662 bytes

Check the V4L2 user guide and V4L2 reference for more information.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linuxpy-0.25.0.tar.gz (457.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linuxpy-0.25.0-py3-none-any.whl (460.8 kB view details)

Uploaded Python 3

File details

Details for the file linuxpy-0.25.0.tar.gz.

File metadata

  • Download URL: linuxpy-0.25.0.tar.gz
  • Upload date:
  • Size: 457.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.4

File hashes

Hashes for linuxpy-0.25.0.tar.gz
Algorithm Hash digest
SHA256 7b234291babc6176a1fe239624f8e1907fc89dc5f7397809360e50e0531c7752
MD5 dcfb032c8812c27f110a19c6b2503a66
BLAKE2b-256 2cb0742fb50fd38b473b2d0335f6ec894618baaeb572380968f73c974b130f50

See more details on using hashes here.

File details

Details for the file linuxpy-0.25.0-py3-none-any.whl.

File metadata

  • Download URL: linuxpy-0.25.0-py3-none-any.whl
  • Upload date:
  • Size: 460.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.4

File hashes

Hashes for linuxpy-0.25.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab94bde0d3902effa0d385e27eee898fcd2253edce1f738fa52abd9f23f0afd0
MD5 1d11de296304aa8ee37c1ecfe6d574a0
BLAKE2b-256 182806061c91bda0e992c8fc44de0b69aa7148f2114f130b1fabf5f3dd205cc3

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.25.0 This release

2 files

0.24.0

2 files

0.23.0

2 files

0.22.0

2 files

0.21.0

2 files

0.20.0

2 files

0.19.0

2 files

0.18.0

2 files

0.17.0

2 files

0.16.0

1 file

0.15.0

1 file

0.14.0

1 file

0.13.0

1 file

0.12.0

1 file

0.11.0

1 file

0.10.0

1 file

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page