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 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 -e .

For development:

pip install -e ".[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.0.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.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_led_ddp-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 ac0a8f6465745c045e1c0e0703e0136374b0445b061c7108ca7f09db93d2cd7f
MD5 924d924f88bea27a7ba8460d7fd163df
BLAKE2b-256 c4b3fec8b4eac0c6093d45cc1a5a7220d16234d80169d1939e8afd1466566e98

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_led_ddp-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56f72c3930e990fc4353f5d66025421400c1296718de4dfbe41a256b7789e1bb
MD5 116e2d103636c0b6b25b7257f89133ef
BLAKE2b-256 3fa829acb22743833bf0da34e7304c7aea404df287f4d3dd6f1acdafcb90dd40

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