skillfed

sonos-websocket

An asynchronous Python library to communicate with Sonos devices over websockets.

sonos-websocket v0.2.0 101.5K downloads/30d#12,932 on PyPI6
Permissive license MIT License Active released

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-websocket

uv

uv add sonos-websocket

poetry

poetry add sonos-websocket

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Topic :: Home AutomationTopic :: Multimedia :: Sound/AudioTopic :: Multimedia :: Sound/Audio :: PlayersTopic :: Software Development :: Libraries :: Python Modules

Tags

sonos device control pythonasync websocket sonossonos audio playback librarysonos home automationsonos clip overlay playbacksonos remote control apipython sonos integration
home-automationasync-iosonos

More Python Modules packages