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,decodeandframe_lengthfollow the C library exactly; the tests check them against vectors the C code writes (tests/golden_vectors/). -
Controller.querysends 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
0xFFbytes; 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
ReplyMismatchat once, and any other bus error is raised as theOSErrorit is.sendis never retried, since a SET need not be safe to repeat. - 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
-
Controller.get_versionqueries opcode0x00and returns aVersion: theCRUMBS_VERSIONthe device was built with, then its module's major, minor and patch, ascrumbs_build_version_replybuilds them (Opcode 0x00). It is retried as any query is, andtype_id=checks the device's type.decode_versionis the same parse for a caller with its own transport. -
Controller.send_confirmedsends 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 aSetOutcome(APPLIED,REFUSED,REJECTEDorNOT_ADVANCED) with the lastAck. 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.AckMismatchmeans another command was counted in between;AckUnknownthat 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 aCRUMBS_VERSIONbelowACK_MIN_VERSION, andsend_confirmedsends it nothing and raisesReplyMismatch, as it does when the version reply does not decode (decode_version); send to it withsend, unconfirmed.read_ackalone does not check the version: it usually raisesReplyMismatchfor such a device, but one that echoes the opcode with bytes that happen to form a valid record is not caught.decode_ackandclassifyare the same steps for a caller with its own transport. -
Controller.scanreads 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 writes00 00 00 00to every address whose read did not decode, which a CRUMBS peripheral dispatches as an opcode-0x00SET and a 24Cxx EEPROM takes as a page write (Discovery). A scan that writes nothing cannot make a device do anything. -
A
Controllermay be shared between threads: each exchange holds its lock, so one thread's GET is never interleaved with another's. The lock belongs to thatControllerobject and covers only the calls made through it: asendorread, aquery's write, pause, read and retries, the whole ofsend_confirmed, and a wholescan. It does not cover a secondController, even one on the same bus object, a secondLinuxBuson 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 oneController. -
Protocol errors share the base
CrumbsError(FrameError,ReplyMismatch,AckMismatch,AckUnknown); bus errors areOSError. -
LinuxBususes/dev/i2c-Nlike the C library's Linux HAL: theI2C_SLAVEioctl, then a plain write or read. Anything with the samewrite(address, data)andread(address, count)methods works as a bus.
The package version is the CRUMBS library version it matches.
Licence
AGPL-3.0-or-later, like CRUMBS.
Metadata
Release files for crumbs-i2c 0.16.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| crumbs_i2c-0.16.0.tar.gz | 24.9 kB | With provenance | Details for crumbs_i2c-0.16.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| crumbs_i2c-0.16.0-py3-none-any.whl | Python 3 | none | any | Details for crumbs_i2c-0.16.0-py3-none-any.whl |
Total release size: 50.1 kB
Release files / crumbs_i2c-0.16.0.tar.gz
| Download URL | crumbs_i2c-0.16.0.tar.gz |
|---|---|
| Size | 24.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac1cef884f47137005ad98cda08ee9d6a22f9be9442fd53c1ee21c2ad3fc16ae
|
|
BLAKE2b-256 checksum How to use checksums |
b3867bb7a39794e12d5793d99c03f1bb6e0d37b5874b326f1742a6b4dec86f4a
|
| 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 18, 2026.
Transparency logRelease files / crumbs_i2c-0.16.0-py3-none-any.whl
| Download URL | crumbs_i2c-0.16.0-py3-none-any.whl |
|---|---|
| Size | 25.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a594f03d8ef34a5424e9fb4c9178840d0ccdfd1e9bacb2eb6cb49c15539255cc
|
|
BLAKE2b-256 checksum How to use checksums |
baa93763407809ffffe3c77c29454750eabe09001eb91ff3c2eb90c16704c6af
|
| 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 18, 2026.
Transparency logSecurity for crumbs-i2c 0.16.0
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.
Attestation for crumbs_i2c-0.16.0.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 18, 2026.
Transparency logA 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.