Skip to main content

Python bindings for libgpiod

Project description

gpiod

These are the official Python bindings for libgpiod.

The gpiod library has been vendored into this package for your convenience and this version of gpiod is independent from your system package.

Binary wheels are not provided. The source package requires python3-dev.

Rationale

The new character device interface guarantees all allocated resources are freed after closing the device file descriptor and adds several new features that are not present in the obsolete sysfs interface (like event polling, setting/reading multiple values at once or open-source and open-drain GPIOs).

Unfortunately interacting with the linux device file can no longer be done using only standard command-line tools. This is the reason for creating a library encapsulating the cumbersome, ioctl-based kernel-userspace interaction in a set of convenient functions and opaque data structures.

Breaking Changes

As of v2.0.2 we have replaced the unofficial, pure-Python "gpiod". The official gpiod is not backwards compatible.

You should ensure you specify at least v2.0.2 for the official API. Versions 1.5.4 and prior are the deprecated, unofficial, pure-Python bindings.

Installing

You will need python3-dev, on Debian/Ubuntu you can install this with:

sudo apt install python3-dev

And then install gpiod with:

pip install gpiod

You can optionally depend upon your system gpiod by installing with:

LINK_SYSTEM_LIBGPIOD=1 pip install gpiod

If you still need the deprecated pure-Python bindings, install with:

pip install gpiod==1.5.4

Examples

Check a GPIO chip character device exists:

import gpiod

gpiod.is_gpiochip_device("/dev/gpiochip0")

Get information about a GPIO chip character device:

import gpiod

with gpiod.Chip("/dev/gpiochip0") as chip:
    info = chip.get_info()
    print(f"{info.name} [{info.label}] ({info.num_lines} lines)")

Blink an LED, or toggling a GPIO line:

import time

from gpiod.line import Direction, Value

LINE = 5

with gpiod.request_lines(
    "/dev/gpiochip0",
    consumer="blink-example",
    config={
        LINE: gpiod.LineSettings(
            direction=Direction.OUTPUT, output_value=Value.ACTIVE
        )
    },
) as request:
    while True:
        request.set_value(LINE, Value.ACTIVE)
        time.sleep(1)
        request.set_value(LINE, Value.INACTIVE)
        time.sleep(1)

Testing

The test suite for the python bindings can be run by calling:

make python-tests-run

from the libgpiod/bindings/python directory as root (necessary to be able to create the gpio-sims used for testing).

Linting/Formatting

When making changes, ensure type checks and linting still pass:

python3 -m venv venv
. venv/bin/activate
pip install mypy ruff
mypy; ruff format; ruff check

Ideally the gpiod library will continue to pass strict checks:

mypy --strict

Project details


Download files

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

Source Distribution

gpiod-2.3.0.tar.gz (57.3 kB view details)

Uploaded Source

Built Distributions

gpiod-2.3.0-cp313-cp313-musllinux_1_2_x86_64.whl (101.2 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

gpiod-2.3.0-cp313-cp313-musllinux_1_2_aarch64.whl (101.7 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ ARM64

gpiod-2.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (103.0 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

gpiod-2.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (103.2 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

gpiod-2.3.0-cp312-cp312-musllinux_1_2_x86_64.whl (101.1 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

gpiod-2.3.0-cp312-cp312-musllinux_1_2_aarch64.whl (101.5 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ ARM64

gpiod-2.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (103.1 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

gpiod-2.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (103.3 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

gpiod-2.3.0-cp311-cp311-musllinux_1_2_x86_64.whl (101.2 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

gpiod-2.3.0-cp311-cp311-musllinux_1_2_aarch64.whl (101.6 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ ARM64

gpiod-2.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (103.5 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

gpiod-2.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (103.6 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

gpiod-2.3.0-cp310-cp310-musllinux_1_2_x86_64.whl (99.5 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

gpiod-2.3.0-cp310-cp310-musllinux_1_2_aarch64.whl (99.9 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ ARM64

gpiod-2.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (101.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

gpiod-2.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (102.2 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

gpiod-2.3.0-cp39-cp39-musllinux_1_2_x86_64.whl (98.8 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

gpiod-2.3.0-cp39-cp39-musllinux_1_2_aarch64.whl (99.3 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ ARM64

gpiod-2.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (101.1 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

gpiod-2.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (101.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

File details

Details for the file gpiod-2.3.0.tar.gz.

File metadata

  • Download URL: gpiod-2.3.0.tar.gz
  • Upload date:
  • Size: 57.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for gpiod-2.3.0.tar.gz
Algorithm Hash digest
SHA256 daa840ed5b691e7078a9cf21c79fe813b9a91c3ed0bdbafae0181c7b98b80300
MD5 56787b7098b447c3876e7325bd474ecf
BLAKE2b-256 8f74cb43c6e2fe74cf1567160ccbf54db176f72481e5ac58567684a262672c7c

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5b82d05e86c72f11de32bef0abee76192c7fb60a216470c76e822bb5c207fc9b
MD5 c605e1c9ffb1cc7f871a76cb0dfb60c5
BLAKE2b-256 049039845f3c357fe5925c404f138f81b2db2eb30e0333c5ab08e41bdbf124a6

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp313-cp313-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 626808ec493f954edfe4b8860842fd9fbbdcdc65209c6efdb02e81acd6b9afdc
MD5 11fd5529d11dc0493cf6e4efbc7a8f70
BLAKE2b-256 699b01983ca816929667d09735f22316d14d03b5a9c003d2341d507fce167559

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 660b613e5b88a9376fae85197b66e04e2381e04c98e234c3d3f70d567b52ee18
MD5 4b5249f5c8e34977760d7eefca74d54b
BLAKE2b-256 3ff11fc0c546ae4e7350615d98796df50e13235bbf5f0dfeab272f2f2a548671

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7fdc3f63a277f8ae193f0c9b565bbd48e525e94c39cd463acd7b06250bf26507
MD5 47fac7191b9dc17f7cbf1ef11852e313
BLAKE2b-256 a108c68d099da0eb545e83132978d3e556803bd3fa90bcfc14d0842d78fa4718

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 40bb477f09bad2d716e7b04405c8b3156f2bc009d235cc2f576a86cee7de2f74
MD5 928175b71ec7f7e9e8c29b62ef736870
BLAKE2b-256 e4f04e6cac036971891678aaf31324b209ab2573ad8b22dd31bd3c63b75005f9

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp312-cp312-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 6f828513d456ed0ca4f9d5e2c02ca6337cd2b4e0934e1dc22c5398b8ab90fbe1
MD5 7d752dec9faa4b3e062b1f7b34b0c2fd
BLAKE2b-256 5158078331e62b9f7c633cf961a8a4db85b97ffb059d21ff365a2a57ea8c7a39

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d7f34b8594d40b95ffb0c28f798fd44c38bf5199d56c6fd6d578d5ba106018f7
MD5 336d08f14be60f4bd9116e14df0fc9ad
BLAKE2b-256 8b15175710d6eb9f0e63646c7540ba93ca49ff26693cf87b414f7369e34c6f45

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9c6b680b27092daa5fc9bad651329fd2195c9bc78d9956c40e8b6d1c73927397
MD5 8f8cb788e128eb5a68138a557481628e
BLAKE2b-256 856495b821e38ddeb0a2eeec51d7d7b1c7bbdde9e4a821bcf1b674d882ec22af

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b37fe1fed6a0b322d1a9f7468b3e0af968a617eaeead028c9707279732282735
MD5 3898c166048fcd01c69caf68f2a12152
BLAKE2b-256 3fbc7165061d092792119cd3ad86e2d57f684a8a967b2798f0f5cf717fd92f36

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp311-cp311-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 af326d54819fa5e6266b61fb96798e775659a5438c2b599943b7ecdf2e327ec2
MD5 ddd949d1386c8b58a22d6c1563a1a826
BLAKE2b-256 a5c52a2194dc2962ff7ea3b546b750a7b67be7712ed62f9c4e654f1a27ae6264

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8bac91d79b69ac2fe2f05c8e6615b987142eb9fa9f856a30bf68e97e891d5b1b
MD5 0c9dfe4a37e92e24b0be0cd42f113a21
BLAKE2b-256 3af31c35dbda126b16d7e8aa368cf50979f0b31054021ddf48b7034c49d7a54c

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8c6e39522d1e1038ac3d3ef41cd7a8e5d69b58ecfcf35fbf4510a4ba3904e63f
MD5 ae079511f1b902175ca9c9f27c60ad98
BLAKE2b-256 af62fa5642bedab7966970218e516b7abe39afa936ecee561011b9a348e5a107

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5ec70e71ff7232abed94444ec3dce76a089af6449980d32116210e8e45b4142b
MD5 49cccb775acd6ee8a1c7a30e3ba01889
BLAKE2b-256 e028f456e8b3fb661478217badd3674ca38a0fee9de05d7f0473c9320bba4607

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp310-cp310-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp310-cp310-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 78aaad927dcd66d59ed6141ab3c57b03afa3e9e1118c6713c5196f460b561c7c
MD5 b77ee73f959767bc9bd6c708eb38bc8a
BLAKE2b-256 d841c65963406fdb1842386cf2eaca5e776a7810f1a2fb15f1e6b56461c73f4e

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a33f6520e848d17d1405b9a898b4a1f8db2c367446f1fe1337eedc4da42fc58c
MD5 44c5ae0830f5082f3e378ebc2b141989
BLAKE2b-256 40cb82b4084fbbcbdb842d22ee1add1e55acca0cf90c09553cf5a8429b0ec011

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 31bf55730069830f1b58f5301149d83ad78caf4ef9a2ca5c6350111dbe24e356
MD5 fe4f369e085ac7311f9ba99c9a23f25e
BLAKE2b-256 2efd02d0205beac5203de1f42d3862f82fa09d38076b3d115bec2784c21159a5

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c610ca3d665c4fc964d1fbcc3f4b27a07ba393fefd50bf47c7781aadb1f6348d
MD5 e314ff7c667e85f65f1c66e2280eae21
BLAKE2b-256 d94b08ac7b9092b117f4f57b1b77fc5b9fb39ea5b8418fd9f0bba6b58531f90e

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp39-cp39-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp39-cp39-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 29bdac916cbfaf62efe09bebd01ee404aac7b86fa85507dbeced7687bcea6784
MD5 20b0de0dc590283bec6d18cf384d044b
BLAKE2b-256 45a46af660118689dbc6e3b9d3b20a89bc0a883a7fd61a4be34fe626a5a88f81

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae29e14db26633f37ebfc315124687a0ec39f963e8a188c234821c81ee8c5964
MD5 78afecfb0806798ac4036d24b109ce95
BLAKE2b-256 f90f5f52d3dc76f67875b04acfccd385123f54a5ac844a884d0f0449a6076ce6

See more details on using hashes here.

File details

Details for the file gpiod-2.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for gpiod-2.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 906d640a80ff0f9012c1c948692099f5320f9d4e0cd77d4659e8a2af26e95df7
MD5 fd60ba1d358493736a1f01da2f34b2f6
BLAKE2b-256 a88142c134ac8728094266dd2daf8ab924e01410b784c771f6608e8a8ae92cf4

See more details on using hashes here.

Supported by

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