Skip to main content

crumbs-i2c

CRUMBS for Python: the frame, its CRC, and a controller that talks to CRUMBS peripherals over Linux I2C. Pure Python, no dependencies, Python 3.11 or newer.

pip install crumbs-i2c
from crumbs_i2c import Controller, LinuxBus, Message

with LinuxBus("/dev/i2c-1") as bus:
    crumbs = Controller(bus)

    # A SET: one frame written, nothing read back.
    crumbs.send(0x10, Message(type_id=0x01, opcode=0x02, data=b"\x01"))

    # A GET: SET_REPLY names the reply, then it is read and checked.
    reply = crumbs.query(0x10, type_id=0x01, opcode=0x80)
    print(reply.data)

    # Every address in 0x08-0x77 that answers with a CRUMBS frame, by type.
    print(crumbs.scan())

The payload is opaque here: a device family's encoders and parsers, such as bread-crumbs-contracts, build and read data.

What it does

  • encode, decode and frame_length follow the C library exactly; the tests check them against vectors the C code writes (tests/golden_vectors/).

  • Controller.query sends SET_REPLY with the wildcard type, waits 10 ms as the C getters do, reads a full 31-byte frame, trims it to the length its header declares, and checks the reply's opcode and type. A GET is safe to repeat, so the whole exchange is tried again, up to three times in all, when:

    • the reply is corrupt (with a Raspberry Pi as controller, the bus can lose a clock edge around the peripheral's clock stretch unless it runs slowly, so a reply reads correctly up to some byte, then as 0xFF bytes; see When the reply is built);
    • it is the same device's reply to another opcode (a lost SET_REPLY, or a device that restarted);
    • the device did not answer (ENXIO, EREMOTEIO, EIO, ETIMEDOUT, EAGAIN).

    Another device type at the address raises ReplyMismatch at once, and any other bus error is raised as the OSError it is. send is never retried, since a SET need not be safe to repeat.

  • Controller.get_version queries opcode 0x00 and returns a Version: the CRUMBS_VERSION the device was built with, then its module's major, minor and patch, as crumbs_build_version_reply builds them (Opcode 0x00). It is retried as any query is, and type_id= checks the device's type. decode_version is the same parse for a caller with its own transport.

  • Controller.send_confirmed sends a SET and confirms it from the device's acknowledgement (GET_ACK): it checks the device's version reply, reads the acknowledgement (Controller.read_ack), sends, reads it again, and returns a SetOutcome (APPLIED, REFUSED, REJECTED or NOT_ADVANCED) with the last Ack. A frame that did not arrive (all four acknowledgement bytes equal to the baseline, status not none) is sent again, up to three times in all; an acknowledgement that cannot be read after a send is raised rather than answered with a re-send, so a frame is never applied twice because a read failed. AckMismatch means another command was counted in between; AckUnknown that the acknowledgement cannot say, because the device restarted or its counter came round, so the SET is not sent again. The first SET to a device that has counted nothing since it started is never re-sent. A device built with CRUMBS before 0.16.0 has no acknowledgement: its version reply reports a CRUMBS_VERSION below ACK_MIN_VERSION, and send_confirmed sends it nothing and raises ReplyMismatch, as it does when the version reply does not decode (decode_version); send to it with send, unconfirmed. read_ack alone does not check the version. A device built before GET_ACK may raise ReplyMismatch (it answered another opcode's reply) or, if it has nothing staged for 0xFD and returns 0xFF bytes as real pre-0.16.0 firmware does, FrameError once the read keeps failing; to tell ack-capable devices apart, check the version (send_confirmed does) rather than catch read_ack. One that echoes the opcode with bytes that happen to form a valid record is not caught. decode_ack and classify are the same steps for a caller with its own transport.

  • Controller.scan reads each address once and writes nothing. An address with no device, or one that answers with something that is not a frame, is skipped; any other bus error is raised. It is the C scanner's strict mode only. The non-strict mode writes 00 00 00 00 to every address whose read did not decode, which a CRUMBS peripheral dispatches as an opcode-0x00 SET and a 24Cxx EEPROM takes as a page write (Discovery). A scan that writes nothing cannot make a device do anything.

  • A Controller may be shared between threads: each exchange holds its lock, so one thread's GET is never interleaved with another's. The lock belongs to that Controller object and covers only the calls made through it: a send or read, a query's write, pause, read and retries, the whole of send_confirmed, and a whole scan. It does not cover a second Controller, even one on the same bus object, a second LinuxBus on the same /dev/i2c-N, another process on that bus, or a call made on the bus object directly. Any of those can land between a GET's SET_REPLY and its read, and the read then returns the reply the other caller asked for. To share a bus between threads, share one Controller.

  • Protocol errors share the base CrumbsError (FrameError, ReplyMismatch, AckMismatch, AckUnknown); bus errors are OSError.

  • LinuxBus uses /dev/i2c-N like the C library's Linux HAL: the I2C_SLAVE ioctl, then a plain write or read. Anything with the same write(address, data) and read(address, count) methods works as a bus.

The package version is the CRUMBS library version it matches.

Licence

MPL-2.0, like CRUMBS.

Metadata

Release files for crumbs-i2c 0.16.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 crumbs-i2c 0.16.2
File Size Uploaded Provenance Actions
crumbs_i2c-0.16.2.tar.gz 16.9 kB With provenance Details for crumbs_i2c-0.16.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for crumbs-i2c 0.16.2
File Interpreter ABI Platform Actions
crumbs_i2c-0.16.2-py3-none-any.whl Python 3 none any Details for crumbs_i2c-0.16.2-py3-none-any.whl

Total release size: 35.7 kB

Release files / crumbs_i2c-0.16.2.tar.gz

Download URL crumbs_i2c-0.16.2.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cb4b0e5f716bd342cda16a71009f1806f04729f2fcb48711ef1fdeb3128438ee
BLAKE2b-256 checksum
How to use checksums
d3af2459394b8e60cefff9d5a0cda024297c14f63c612df7b62ee657ef907b3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Release files / crumbs_i2c-0.16.2-py3-none-any.whl

Download URL crumbs_i2c-0.16.2-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cde9e271d4a9d3bfcdfbe6270555ab3a0355a02d08aff1d9f494c9d43d78adf4
BLAKE2b-256 checksum
How to use checksums
9696709d36bb8e047cefd1df7270ee621c80bfca0c00f5c27178350478f95a1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Security for crumbs-i2c 0.16.2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for crumbs_i2c-0.16.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

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