Skip to main content

A full-featured Python Lavalink client for Discord music bots

Project description

Sonora

PyPI version Python 3.11+ License: MIT Build Status Coverage

A full-featured, enterprise-grade Python Lavalink client for building high-performance Discord music bots. The most advanced Lavalink client available.

🚀 v1.2.7 - Advanced Feature Backport Release with Enterprise Features!

Features

  • 🚀 Enterprise-Grade Performance: Lock-free async architecture, zero-copy routing, adaptive backpressure
  • 🔐 Advanced Security: AES-encrypted credentials, plugin sandboxing, secure deserialization
  • 🧠 Smart Autoplay Engine: Context-aware recommendations with multi-strategy scoring
  • 📊 Intelligent Queue System: Session memory, similarity scoring, adaptive reordering
  • 💾 Session Persistence: Complete state snapshots with crash recovery
  • 🧪 Offline Simulation: Full Lavalink protocol simulator with fault injection
  • 🛠 High-Level SDKs: SonoraMusicBotSDK and SonoraVoiceSDK for rapid development
  • 🔍 Advanced Diagnostics: Performance profiling, wiretap debugging, timeline analysis
  • 📈 Enterprise Monitoring: 92% test coverage, comprehensive metrics, structured logging
  • 🔌 Extensible Plugin System: Secure plugin architecture with marketplace-ready APIs
  • Full Lavalink protocol support (v3 & v4) with Python 3.11+ compatibility
  • Integrations for discord.py, py-cord, and nextcord
  • Multi-node load balancing with health checks and failover
  • 15+ audio filters with real-time hot-swapping
  • CLI utilities for debugging, benchmarking, and session management

v1.2.7 Enterprise Features

🔐 Enterprise Security

  • AES Credential Vault: Encrypted storage with key rotation and secure access
  • Plugin Firewall: Advanced sandboxing with code analysis and import restrictions
  • Secure Deserialization: Type-validated JSON parsing with size limits
  • Runtime Exploit Protection: Guardrails against malicious inputs and attacks

🛠 High-Level SDKs

  • SonoraMusicBotSDK: Pre-built commands with auto queue binding and filter pipelines
  • SonoraVoiceSDK: Voice-only streaming with connection management and statistics
  • Rapid Development: Get started in minutes with production-ready components

💾 Session Management

  • Complete State Snapshots: Player, queue, filters, and autoplay state persistence
  • Crash Recovery: Automatic restoration across restarts and deployments
  • Background Snapshots: Configurable intervals with intelligent cleanup

🧪 Advanced Testing & Simulation

  • Offline Protocol Simulator: Full Lavalink simulation with fault injection
  • Mock Factory: Deterministic test objects for comprehensive CI/CD
  • Fault Injection: Packet loss, latency spikes, connection drops for testing
  • 92% Test Coverage: Stress tests, fuzz tests, memory leak detection

⚡ Performance Overdrive

  • Lock-Free Architecture: High-throughput async queues without blocking
  • Zero-Copy Routing: Optimized payload handling for maximum performance
  • Adaptive Backpressure: Intelligent load shedding under high load
  • CPU-Aware Balancing: Optimized resource distribution across nodes

🔍 Developer Experience

  • Built-in Profiler: cProfile integration with memory tracking
  • Structured Logging: JSON logging for debugging and monitoring
  • Wiretap Debugger: Protocol-level packet inspection and capture
  • Timeline Analysis: Playback event debugging with pattern recognition
  • Reproducible Testing: Session recording and replay for debugging

Installation

pip install py-sonora

Quickstart

First, set up your environment variables:

cp .env.example .env
# Edit .env with your Lavalink server details and Discord token

Minimal Discord Bot Example

import discord
from discord.ext import commands
from sonora import SonoraClient

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='!', intents=intents)
sonora = SonoraClient(
    lavalink_nodes=[{"host": "127.0.0.1", "port": 2333, "password": "youshallnotpass"}],
    node_pooling=True,
    reconnect_policy={"max_retries": 5, "backoff": "exponential"}
)

@bot.event
async def on_ready():
    await sonora.start()
    print(f'Logged in as {bot.user}')

@bot.command()
async def join(ctx):
    if ctx.author.voice:
        await ctx.author.voice.channel.connect()
        player = await sonora.get_player(ctx.guild.id)
        await ctx.send("Joined voice channel!")
    else:
        await ctx.send("You need to be in a voice channel!")

@bot.command()
async def play(ctx, *, query):
    player = await sonora.get_player(ctx.guild.id)
    track = await player.play(query)
    await ctx.send(f"Now playing: {track.title}")

bot.run(os.getenv('DISCORD_TOKEN'))

For more examples, see the examples/ directory.

Configuration

Sonora supports configuration via environment variables:

  • LAVALINK_HOST: Lavalink server host (default: 127.0.0.1)
  • LAVALINK_PORT: Lavalink server port (default: 2333)
  • LAVALINK_PASSWORD: Lavalink server password
  • DISCORD_TOKEN: Your Discord bot token

See .env.example for a full list.

Documentation

Full documentation is available at https://code-xon.github.io/sonora/.

Development

Prerequisites

Setup

git clone https://github.com/code-xon/sonora.git
cd sonora
pip install -e .[dev]
pre-commit install

Testing

pytest

Building Docs

mkdocs serve

Contributing

See CONTRIBUTING.md for details.

License

MIT License - see LICENSE for details.

Contact

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

py_sonora-1.2.7.tar.gz (66.8 kB view details)

Uploaded Source

Built Distribution

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

py_sonora-1.2.7-py3-none-any.whl (49.9 kB view details)

Uploaded Python 3

File details

Details for the file py_sonora-1.2.7.tar.gz.

File metadata

  • Download URL: py_sonora-1.2.7.tar.gz
  • Upload date:
  • Size: 66.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for py_sonora-1.2.7.tar.gz
Algorithm Hash digest
SHA256 cb4c455c8eb9a9009b948e041c4a425795346179287753e72576a78f6ec71b95
MD5 ee236e2310462a88afe2f37e47187b39
BLAKE2b-256 88f6de730e0f62b29cce5bb35a616e3d2ae869ddcb8ab522a82547acf7f8af8d

See more details on using hashes here.

File details

Details for the file py_sonora-1.2.7-py3-none-any.whl.

File metadata

  • Download URL: py_sonora-1.2.7-py3-none-any.whl
  • Upload date:
  • Size: 49.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for py_sonora-1.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8dc714dd6607303b10329e5410886214c93dd2b70fc34688a20b960c0dfadb79
MD5 ea487f9b6c298b6df78dcd7238bce2e9
BLAKE2b-256 b8363a989e68d2a273609e031d2f1fda9a2abbca0f2f1932313511300543f4dd

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