sonos-websocket
An asynchronous Python library to communicate with Sonos devices over websockets.
What it is and what it does
sonos-websocket is an asynchronous Python library that lets you control Sonos speakers programmatically over WebSocket connections. It wraps the Sonos WebSocket API to provide async/await-friendly methods for tasks like playing audio clips, adjusting volume, and managing playback. The library depends only on aiohttp for HTTP communication and is designed for Python 3.11+.
A key feature is audio clip playback, which overlays new audio on top of currently playing music while automatically lowering the background volume and restoring it when the clip finishes—useful for alerts and text-to-speech integration. The library can be used as a standalone script (passing device IP, audio URI, and volume parameters) or integrated into larger home automation or notification systems.
Use it for:
- Overlay text-to-speech alerts or notifications on Sonos speakers without interrupting music playback.
- Build home automation routines that trigger audio clips on Sonos devices in response to events.
- Programmatically control Sonos speaker volume and playback from Python applications or services.
- Create multi-room audio coordination scripts that manage playback across multiple Sonos devices.
- Integrate Sonos control into IoT or smart home platforms that use async Python.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Async Python library for communicating with Sonos devices over WebSocket connections, enabling remote control and audio playback features like audio clips and volume management.
Yes, if you need to control Sonos devices from Python and want async/await support. The library is actively maintained, has low install friction, carries a permissive MIT license, and has no known vulnerabilities. Beta status and small community (6 stars) mean you may encounter edge cases or limited documentation, but the core functionality is straightforward and the dependency footprint is minimal.
Install
sonos-websocket on PyPI
pip
pip install sonos-websocketuv
uv add sonos-websocketpoetry
poetry add sonos-websocketInstalling sonos-websocket
Before you install
Low install friction with a single pure-Python dependency (aiohttp). Actively maintained with recent commits and a Beta stability rating.
License in practice
MIT License permits unrestricted use, modification, and distribution with minimal restrictions—suitable for both commercial and open-source projects.
Quickstart
pip install sonos-websocket
import asyncio
from sonos_websocket import SonosWebsocket
async def main():
async with SonosWebsocket('192.168.1.88') as sonos:
await sonos.play_audio_clip('https://example.com/audio.mp3', volume=15)
asyncio.run(main())
Requires Python 3.11 or later; target Sonos device must be reachable on the network and support WebSocket communication.
Verify before relying
- Which Sonos device models and firmware versions are supported by this library.
- Whether audio clip playback works with all Sonos speaker types or only specific models.
- Performance characteristics and latency when controlling multiple devices simultaneously.
Package facts
| License | MIT License (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — aiohttp |
| Maintenance | actively maintained — 63 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 101,468/month — #12,932 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sonos_websocket-0.2.0-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
playsoundPlays audio files (MP3, WAV) and URLs from…
permissive · top 15,000 on PyPI
roonapiPython client library for the Roon music server…
permissive · top 15,000 on PyPI
socoSoCo is a Python library for programmatic…
permissive · top 15,000 on PyPI
wiimwiim provides a Python API to discover,…
permissive · top 15,000 on PyPI
plexwebsocketAsync library that connects to Plex media…
permissive · top 15,000 on PyPI
pulsectlProvides a high-level Python interface to…
permissive · top 15,000 on PyPI
libsoundtouchControl Bose Soundtouch devices over the…
permissive · top 15,000 on PyPI
python-songpalPython library for controlling Sony audio…
copyleft · top 15,000 on PyPI
python-oscpython-osc implements Open Sound Control (OSC)…
unclear · top 15,000 on PyPI
pybluControl and query BluOS audio players over the…
permissive · top 15,000 on PyPI