Skip to main content

EmBody protocol codec

PyPI Status Python Version License

Tests

pre-commit Ruff

This is a Python based implementation library for the Aidee EmBody communication protocol.

Features

  • High-performance message decoding with O(1) lookup using optimized message registries
  • Comprehensive protocol support for all EmBody message types
  • Robust error handling with detailed error messages and optional CRC validation bypass
  • Type-safe implementations with full type annotations for better IDE support
  • Zero dependencies for the core library
  • Extensive test coverage ensuring protocol compliance

Requirements

  • This library does not require any external libraries
  • Requires Python 3.12+

Installation

You can install embody codec via pip from PyPI:

pip install embody-codec

Usage Examples

Basic Message Encoding/Decoding

from embodycodec import codec

# Create and encode a heartbeat message
heartbeat = codec.Heartbeat()
encoded_data = heartbeat.encode()

# Decode received data
decoded_msg = codec.decode(encoded_data)
print(f"Received: {type(decoded_msg).__name__}")

Working with Attributes

from embodycodec import codec, attributes

# Create a set attribute message
attr = attributes.BatteryLevelAttribute(value=85)
msg = codec.SetAttribute(attribute_id=attr.attribute_id, value=attr)
encoded = msg.encode()

# Decode and access attribute value
decoded = codec.decode(encoded)
print(f"Battery level: {decoded.value.value}%")

Error Handling

from embodycodec import codec
from embodycodec.exceptions import CrcError, DecodeError

try:
    # Decode with CRC validation
    msg = codec.decode(data)
except CrcError:
    # Handle CRC error - optionally decode anyway
    msg = codec.decode(data, accept_crc_error=True)
except DecodeError as e:
    print(f"Decode failed: {e}")

Upgrading to 2.0.0

Every break below is the removal of an API that never worked correctly. Nothing here changes behaviour that was previously right.

codec.SendFileResponse.crc is renamed to file_crc. The old name collided with Message.crc, which holds the message footer CRC and is assigned during decode — so the file CRC was silently overwritten. Reading .crc on this class never returns the file CRC, so it must be replaced rather than left alone:

SendFileResponse(crc=x)   ->  SendFileResponse(file_crc=x)
response.crc              ->  response.file_crc

file_codec.BatteryDiagnostics.length() returns 26, not 24. It excluded the two-byte timestamp that every other message counts, so a parser walking a file by advancing 1 + length() desynced by two bytes on every such record. If you compensated for this, remove the compensation.

file_codec.BatteryDiagnostics.struct_format is gone, replaced by unpack_format (the name its base class actually reads). Note this is the file_codec class; the unrelated types.BatteryDiagnostics.struct_format is unchanged.

file_codec.PulseBlockEcg.encode() and PulseBlockPpg.encode() raise NotImplementedError. They previously returned two zero bytes regardless of contents. File-format messages are produced by the device and are decode-only.

One fix that needs no code change but does change bytes on the wire: SetAttribute now writes the true payload length for variable-length attributes (ModelAttribute, VendorAttribute, SystemStatusNamesAttribute, SystemStatusAttribute, PulseRawListAttribute). It previously wrote 0, so a conforming parser dropped those values. Fixed-size attributes encode exactly as before.

Changelog

See the releases page for the changelog.

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the MIT license.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

Inspiration collected from Cookiecutter UV template.

Download files

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

Source Distribution

embody_codec-2.0.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

embody_codec-2.0.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file embody_codec-2.0.0.tar.gz.

File metadata

  • Download URL: embody_codec-2.0.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for embody_codec-2.0.0.tar.gz
Algorithm Hash digest
SHA256 587d54358f554328e2c08c701d178bf6db790c974cd342239a56e3de60d86bf4
MD5 4d1966afa45d97758449e3abd3c545ea
BLAKE2b-256 e9c80cb1a2421254482803505abc546c82beb1d0ce0c85a5a0cc857429884cbe

See more details on using hashes here.

File details

Details for the file embody_codec-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: embody_codec-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for embody_codec-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d22293527da93aa32acb15ed55612e79dfbe8be6f7358eed45a9722340836b3e
MD5 79fb4eeabb9ec2dfaaf1dd866a5520f8
BLAKE2b-256 2992e219df6425bce3fe59270860a28dadc5c4afa3b92ed2b485e0ad816c9166

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 files

1.0.40

2 files

1.0.39

2 files

1.0.38

2 files

1.0.37

2 files

1.0.36

2 files

1.0.35

2 files

1.0.34

2 files

1.0.32

2 files

1.0.31

2 files

1.0.30

2 files

1.0.29

2 files

1.0.28

2 files

1.0.27

2 files

1.0.26

2 files

1.0.25

2 files

1.0.24

2 files

1.0.23

2 files

1.0.22

2 files

1.0.21

2 files

1.0.20

2 files

1.0.19

2 files

1.0.18

2 files

1.0.17

2 files

1.0.16

2 files

1.0.15

2 files

1.0.14

2 files

1.0.13

2 files

1.0.12

2 files

1.0.11

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 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