Skip to main content

Zero-copy CDR message types for EdgeFirst Perception (ROS 2 + Foxglove + custom)

Project description

edgefirst-schemas (Python)

Zero-copy CDR message types for EdgeFirst Perception. Wraps the edgefirst-schemas Rust crate via PyO3.

pip install edgefirst-schemas

The wheel ships as cp311-abi3 (Python 3.11+, single wheel per OS/arch). For an older Python floor, build from source with --no-default-features --features abi3-py38 — see Build from source.

Quick start

from edgefirst.schemas.builtin_interfaces import Time
from edgefirst.schemas.std_msgs import Header
from edgefirst.schemas.sensor_msgs import Image
import numpy as np

pixels = np.zeros((720, 1280, 3), dtype=np.uint8)
img = Image(
    header=Header(stamp=Time(sec=1, nanosec=0), frame_id="cam"),
    height=720, width=1280, encoding="rgb8",
    is_bigendian=0, step=1280 * 3,
    data=pixels,  # any contiguous buffer-protocol object
)

# Zero-copy view of the pixel data — `np.frombuffer` aliases the same
# bytes the message was constructed with, no copy.
arr = np.frombuffer(img.data, dtype=np.uint8).reshape(720, 1280, 3)

# Wire bytes for transport:
buf = img.to_bytes()
img2 = Image.from_cdr(buf)
assert img2.width == 1280

Forwarding raw CDR bytes without a copy

For publish paths where you want to hand the wire bytes straight to a transport (Zenoh, raw socket, mcap writer), cdr_view() exposes the full CDR buffer (header + payload) as a zero-copy BorrowedBuf:

transport.publish(memoryview(img.cdr_view()))   # zero-copy

to_bytes() is the explicit-copy alternative when the consumer wants an owned bytes value.

Zero-copy contract — BorrowedBuf

Every bulk byte payload (Image.data, Mask.mask, RadarCube.cube, PointCloud2.data, CompressedVideo.data, CompressedImage.data) returns a BorrowedBuf view that aliases the parent message's bytes — not a copy. The BorrowedBuf holds a strong reference to the parent, so it's safe to keep it (or a memoryview derived from it) live after the original message reference is dropped.

Method Returns Cost
borrowed_buf itself wraps the bytes zero-copy, O(1)
np.frombuffer(borrowed_buf, dtype=...) numpy ndarray aliasing the bytes zero-copy, O(1) (Py 3.11+)
memoryview(borrowed_buf) parent-anchored memoryview zero-copy, O(1) (Py 3.11+)
borrowed_buf.tobytes() owned bytes one memcpy
borrowed_buf.view() memoryview (Py 3.11+) / bytes (abi3-py38) zero-copy / one memcpy

Migrating from the pycdr2-backed edgefirst.schemas

This release replaces the pure-Python pycdr2 codec with a Rust-backed pyo3 binding. Wire-format bytes are unchanged — anything encoded by the previous pycdr2 module decodes through from_cdr() and vice-versa — but the Python API surface is narrower and stricter.

What changed at the call site

# pycdr2-backed (old)                    # pyo3-backed (new)
img = Image()                            img = Image(
img.height = 720                             header=Header(stamp=Time(1, 0)),
img.width = 1280                             height=720, width=1280,
img.encoding = "rgb8"                        encoding="rgb8", is_bigendian=0,
img.data = pixels                            step=1280 * 3, data=pixels,
buf = img.serialize()                    )
img2 = Image.deserialize(buf)            buf = img.to_bytes()
                                         img2 = Image.from_cdr(buf)
pycdr2 pattern pyo3 replacement
Foo() then field assignment Foo(field=value, …) constructor only — pyclasses are frozen
.serialize() .to_bytes()
Foo.deserialize(buf) Foo.from_cdr(buf)
msg.data returning bytes msg.data returning BorrowedBuf (zero-copy view); use .tobytes() for the old shape
from_schema(), decode_pcd(), colormap(), registry helpers removed — the legacy module survives only at benches/python/legacy/ for benchmark parity
std_msgs.{String, Int32, Float64, …} primitive wrappers removed — these were pycdr2-generated single-value wrappers; pass raw Python values instead
Mutable dataclass-style instances Frozen pyclasses; rebuild instead of mutate

What stays the same

  • All field names and types match the ROS 2 / Foxglove / EdgeFirst schemas verbatim.
  • Wire-format CDR1 LE bytes are byte-equivalent across versions.
  • The edgefirst.schemas.<submodule> import paths (sensor_msgs.Image, std_msgs.Header, etc.) are preserved.

abi3-py38 builds — typed numpy caveats

The default wheel is cp311-abi3, where the buffer protocol is in the limited API and typed numpy arrays (np.uint16, np.float32, …) work zero-copy as constructor inputs. On the opt-in abi3-py38 build the buffer protocol isn't available; pass arr.tobytes() for typed arrays, and BorrowedBuf.view() returns bytes (one copy) instead of a parent-anchored memoryview. Plain bytes / bytearray / np.uint8 arrays work on either build.

shape = np.array([2, 128, 12, 128], dtype=np.uint16)

# Default cp311-abi3 wheel — works directly:
RadarCube(..., shape=shape, ...)

# abi3-py38 build — pass bytes:
RadarCube(..., shape=shape.tobytes(), ...)

Build from source

Default (cp311-abi3 wheel for Python 3.11+):

maturin develop --release --manifest-path crates/python/Cargo.toml

abi3-py38 wheel (for embedded targets pinning an older Python):

maturin build --release \
  --manifest-path crates/python/Cargo.toml \
  --no-default-features --features abi3-py38

Cross-compile manylinux2014 wheels via zig:

maturin build --release --zig --compatibility manylinux2014 \
  --target aarch64-unknown-linux-gnu \
  --manifest-path crates/python/Cargo.toml

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

edgefirst_schemas-3.5.0.tar.gz (919.8 kB view details)

Uploaded Source

Built Distributions

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

edgefirst_schemas-3.5.0-cp311-abi3-win_amd64.whl (638.4 kB view details)

Uploaded CPython 3.11+Windows x86-64

edgefirst_schemas-3.5.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (701.6 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

edgefirst_schemas-3.5.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (671.9 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

edgefirst_schemas-3.5.0-cp311-abi3-macosx_11_0_arm64.whl (648.8 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

edgefirst_schemas-3.5.0-cp311-abi3-macosx_10_12_x86_64.whl (681.7 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file edgefirst_schemas-3.5.0.tar.gz.

File metadata

  • Download URL: edgefirst_schemas-3.5.0.tar.gz
  • Upload date:
  • Size: 919.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for edgefirst_schemas-3.5.0.tar.gz
Algorithm Hash digest
SHA256 f133242208895da897bf536ec82c5e4a49a96c579a4399b889596c937c0654d8
MD5 7077ba85c1a39f4c6fcda23370bed5c3
BLAKE2b-256 fe9521041ecd19427baf072959c1957031e330c82dad4b3f7acf48a5cc1ce947

See more details on using hashes here.

Provenance

The following attestation bundles were made for edgefirst_schemas-3.5.0.tar.gz:

Publisher: release.yml on EdgeFirstAI/schemas

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file edgefirst_schemas-3.5.0-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for edgefirst_schemas-3.5.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 beb683637c46169a5a58c2334ec5088b7f02324e1eab9857bd3b2d705918ec9e
MD5 e3cc5cfb51d6d4c279b2a18f8d0f4543
BLAKE2b-256 7463253d171e708d5a3593a81fe92ca8edbb4ecf86cad94237187412f2fbfd2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for edgefirst_schemas-3.5.0-cp311-abi3-win_amd64.whl:

Publisher: release.yml on EdgeFirstAI/schemas

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file edgefirst_schemas-3.5.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for edgefirst_schemas-3.5.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 444a2692e93e6c1c35490799085622b88adbae18c696b1e907eeebf46cead4d3
MD5 1a217677b17d2db5d712ec1c692786d0
BLAKE2b-256 933290d3eaf3f87502d2743b6728b2413d7f621b4c5c8e094dc879a1f3e69286

See more details on using hashes here.

Provenance

The following attestation bundles were made for edgefirst_schemas-3.5.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on EdgeFirstAI/schemas

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file edgefirst_schemas-3.5.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for edgefirst_schemas-3.5.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 28a3ced8589e7f0875e1587f04b3fa4b2f7f055a958ba329fff3fae7b1156834
MD5 d33b98bc894b16af64775fb0eb1334fa
BLAKE2b-256 5dd35265513b45ffb9b77ca41695a5619f2300154eb8671d6af32fb68a2cef4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for edgefirst_schemas-3.5.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on EdgeFirstAI/schemas

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file edgefirst_schemas-3.5.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for edgefirst_schemas-3.5.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5255820042555f23525f4902e8da93274f6585c0f5ac67a2e7ea1b97b71a42bd
MD5 8553c2af08d0e66d88f14c237b6d2287
BLAKE2b-256 ec8e147c24993d4d5f39bfce1071de00ab27aab7bdfc8cf863de05b7701512c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for edgefirst_schemas-3.5.0-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on EdgeFirstAI/schemas

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file edgefirst_schemas-3.5.0-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for edgefirst_schemas-3.5.0-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 04b029e5c1f673ad488d33120f68d4280b4b3ebf7d2f42d94bb88bb5a76c8e93
MD5 d8985c5faa07f043441a3da3982ea3b4
BLAKE2b-256 91ab5e60d884e508f7292cd576054802bf2c6d6089d9c11d8617482d01f83868

See more details on using hashes here.

Provenance

The following attestation bundles were made for edgefirst_schemas-3.5.0-cp311-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on EdgeFirstAI/schemas

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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