Skip to main content

Distributed Display Protocol (DDP) implementation in Python

Project description

ENTIRELY AI TRANSLATED FROM A DDP LIB I WORKED ON IN RUST!!!

DO NOT TRUST IT! UNTESTED! NOT VETTED! I DONT USE PYTHYON!

Python LED DDP

Distributed Display Protocol (DDP) implementation in Python, translated from the Rust ddp-rs library.

This library allows you to write pixel data to LED strips over the Distributed Display Protocol (DDP) by 3waylabs.

You can use this to stream pixel data to WLED or any other DDP-capable receiver.

Installation

pip install python-led-ddp

For development:

pip install python-led-ddp[dev]

Quick Start

import asyncio
from ddp import DDPConnection
from ddp.protocol import PixelConfig, ID

async def main():
    # Create a connection to your LED controller
    conn = await DDPConnection.create(
        "192.168.1.40:4048",       # Device IP and DDP port
        PixelConfig.default(),      # RGB, 8 bits per channel
        ID.DEFAULT,                 # Default ID
    )

    # Send RGB pixel data (2 pixels: red and blue)
    await conn.write(bytes([
        255, 0, 0,    # First pixel: Red
        0, 0, 255,    # Second pixel: Blue
    ]))

    await conn.close()

asyncio.run(main())

Features

  • Async/await support using asyncio
  • Automatic packet chunking for large pixel arrays
  • Sequence numbering with automatic wrapping
  • Offset support for updating portions of LED strips
  • JSON control messages for device configuration
  • Comprehensive type hints for better IDE support

Examples

The examples/ directory contains several examples:

  • dev.py: Simple color cycling example
  • consoleserver.py: DDP server that displays received packets in the terminal
  • longstrip.py: Demonstrates using offsets with longer LED strips

Run an example:

python examples/dev.py 192.168.1.40:4048

Testing

Run the test suite:

pytest

Run tests with verbose output:

pytest -v

Protocol Overview

DDP is designed for sending real-time data to distributed lighting displays where synchronization may be important. The protocol uses a 10 or 14 byte header followed by pixel data or JSON control messages.

Key Features

  • Small, simple, extensible protocol
  • Efficient packet structure (94.9% efficiency vs 72.7% for E1.31)
  • Support for up to 480 RGB pixels per packet (1440 bytes)
  • Optional timecode support for synchronization
  • JSON-based configuration and status messages

API Documentation

DDPConnection

Main class for sending pixel data to DDP displays.

Methods

  • create(addr, pixel_config, id) - Create a new connection
  • write(data) - Write pixel data starting at offset 0
  • write_offset(data, offset) - Write pixel data at a specific offset
  • write_message(msg) - Send a JSON control message
  • get_incoming() - Get received packets (non-blocking)
  • close() - Close the connection

Protocol Types

  • PixelConfig - Pixel format configuration (RGB, RGBW, etc.)
  • ID - Protocol IDs (DEFAULT, CONTROL, CONFIG, STATUS, etc.)
  • Header - DDP packet header
  • PacketType - Packet type flags
  • TimeCode - Optional timecode for synchronization

License

MIT

Credits

Translated from the Rust ddp-rs library.

DDP protocol specification: http://www.3waylabs.com/ddp/

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

python_led_ddp-1.0.1.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

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

python_led_ddp-1.0.1-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file python_led_ddp-1.0.1.tar.gz.

File metadata

  • Download URL: python_led_ddp-1.0.1.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for python_led_ddp-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1e2fe0628f633ad18fc490a9c4f5e95a0004bd029490ade07859560549cb4204
MD5 323e7d8b90242f0a25249c55bb382dca
BLAKE2b-256 7e96aab9378c779d4200b945ed1353478baed140c04fd9a8bc9553713251d1e4

See more details on using hashes here.

File details

Details for the file python_led_ddp-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: python_led_ddp-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for python_led_ddp-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8c07b534d436e0ec776c235b318c413cde5ddebf5debfb8a437002b14a4dc5c8
MD5 17085a5e97ee9cac37619d0eb3f681fb
BLAKE2b-256 3e66400c2fa569765a02daed3aee0297d3d1c9d1e442ef42a468898439732dc1

See more details on using hashes here.

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