Skip to main content

Python implementation of the LOVE protocol based on JSON schemas

Project description

❤️ LOVE Protocol for Python

LOVE (Lucy Open Voice Exchange) is a universal messaging protocol for multimodal voice interaction.
This library is the official Python implementation based on JSON schemas.


📦 Installation

pip install love-protocol

Requires: Python ≥ 3.10


🚀 Quick Start

WebSocket Demo

python examples/websocket/server.py
# In a second terminal:
python examples/websocket/client.py

🔧 Features

  • ✅ Full validation using Pydantic (generated models)
  • ✅ Message encoding / decoding (JSON ⇄ Python)
  • ✅ Async handler system with middleware support
  • ✅ In-memory SessionStore
  • ✅ Command-line tool love-validate

💬 LOVE Message Format

All messages follow the same base structure with a type field:

{
  "protocol": "LOVE/1.0",
  "type": "HELLO",
  "device_id": "test-device",
  "timestamp": 1234567890.0
}

Supported message types include:

  • HELLO, HELLO_ACK
  • AUDIO_START, AUDIO_CHUNK, AUDIO_STOP
  • TRANSCRIPTION, INTENT_DETECTED, TTS_OUTPUT
  • WAKEWORD_DETECTED, COMMAND
  • MEDIA_CONTROL, MEDIA_PLAY
  • SENSOR_EVENT
  • ERROR

All types are defined in love_protocol.types.


🧪 Run Tests

PYTHONPATH=. pytest tests

Tests use pytest and pytest-asyncio.


🧰 CLI: love-validate

Validate a raw message from file:

love-validate examples/data/hello.json

Output:

✅ Valid message of type HELLO

If invalid:

❌ Invalid message:
- protocol: expected format LOVE/X.Y
- type: unknown message type 'FOO'

🧠 Handler Example

from love_protocol.handler.handler import LoveHandler

handler = LoveHandler()

@handler.on("HELLO")
async def handle_hello(ctx):
    print("📥 Message:", ctx.message)
    ctx.response = HELLOACK(
        protocol="LOVE/1.0",
        type="HELLO_ACK",
        device_id=ctx.message.device_id,
        timestamp=ctx.message.timestamp,
        session=ctx.message.session
    )

With middleware:

from love_protocol.session.middleware import create_session_middleware

handler.use(create_session_middleware(session_store))

📁 Project Structure (Excerpt)

love_protocol/
├── core/         # encode / decode / validate
├── handler/      # dispatch + middleware
├── types/        # generated message types
├── session/      # SessionStore + lifecycle middleware
├── cli/          # love-validate CLI
├── examples/     # WebSocket demos
└── tests/        # pytest coverage

🧠 SessionStore Example

from love_protocol.session.store import SessionStore

store = SessionStore()
session_id = store.create("kitchen-dot")
session = store.get(session_id)

store.update(session_id, { "state": "active" })

Sessions can be managed automatically via middleware.


📄 License

This project is licensed under the Apache 2.0 License.
You may freely use, modify, and integrate it.

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

love_protocol-0.3.2.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

love_protocol-0.3.2-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file love_protocol-0.3.2.tar.gz.

File metadata

  • Download URL: love_protocol-0.3.2.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for love_protocol-0.3.2.tar.gz
Algorithm Hash digest
SHA256 c6edb7f1ff38ba712f52d6c91f5d9775349b2860b45e56526338a06e2bd302c7
MD5 6ed922ec0453de81e61f5a8006660e37
BLAKE2b-256 5dafc88e78b74b41db8f3a021997c2102aea42d27f0ef638750c1857529a90dc

See more details on using hashes here.

File details

Details for the file love_protocol-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for love_protocol-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e9dcc1bc627c9fabdf3a5052a41c3fd1fa7fbead9a42dbc2f4616f4bb8c0af95
MD5 6ebd13fa931b8fa245db7f3ad478199f
BLAKE2b-256 24be74396cfb79a52a61e3a0438a302032708edf8f756793e21f2d602afcef1b

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