Skip to main content

Douyu Live Stream Protocol - minimal library for encoding/decoding danmu messages.

Project description

dyproto

Douyu Live Stream Protocol - minimal library for encoding/decoding danmu messages.

Installation

# Core (encoding/decoding only)
pip install dyproto

# With room discovery
pip install dyproto[discovery]

Quick Start

from dyproto import pack, unpack, MessageBuffer

# Encode a message to bytes
data = pack({"type": "chatmsg", "content": "Hello"})

# Decode bytes to message
msg = unpack(data)  # {"type": "chatmsg", "content": "Hello"}

# For streaming, use MessageBuffer
buffer = MessageBuffer()
buffer.add_data(raw_bytes)
for msg_dict in buffer.get_messages():
    process(msg_dict)

API

Core Functions

Function Description
pack(msg_dict) Encode dict to bytes (serialize + encode)
unpack(data) Decode bytes to dict (decode + deserialize)
encode_message(msg_str) Encode string to bytes
decode_message(data) Decode bytes to string
serialize_message(msg_dict) Serialize dict to Douyu KV format
deserialize_message(msg_str) Deserialize Douyu KV format to dict

Buffer

Class Description
MessageBuffer UTF-8 safe buffer for streaming packet reassembly

Types

Type Description
MessageType Enum of recognized Douyu message types
PacketHeader Dataclass for packet header fields

Constants

Constant Description
DOUYU_WS_URL Default WebSocket URL
CLIENT_MSG_TYPE Client message type (689)
SERVER_MSG_TYPE Server message type (690)

Room Discovery (optional)

from dyproto.discovery import resolve_room_id, get_danmu_server

# Resolve vanity URL to numeric ID
room_id = resolve_room_id("longzhu")  # -> 6657

# Get danmu WebSocket servers
urls, room_id = get_danmu_server(6657)
# -> (['wss://danmuproxy.douyu.com:8506/', ...], 6657)

Requires dyproto[discovery].

License

MIT

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

dyproto-0.1.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

dyproto-0.1.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file dyproto-0.1.1.tar.gz.

File metadata

  • Download URL: dyproto-0.1.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dyproto-0.1.1.tar.gz
Algorithm Hash digest
SHA256 46ec0adbba3a3c4ef1983fde1a183528b81603cde445e3a0508d5f686508de49
MD5 8c8d889036db209cd654a5244574bc4e
BLAKE2b-256 a9aafd158e7b617ba8dddb5270388e451e9c52576d7e446a3a77ed0fa42996ad

See more details on using hashes here.

File details

Details for the file dyproto-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dyproto-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dyproto-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa864b0067723d102853827c89acdf745f35a70af2f5a716c3c2bae53f301a4f
MD5 5d091b33851fc9489b8e4f256923a413
BLAKE2b-256 559c0d7065108d3c5e2e8351ecd577cae4dcb1c95afbfbaa90035fb6d923ac68

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