Skip to main content

SoCo

SoCo (Sonos Controller) is a Python library that allows you to control Sonos speakers programmatically. It was originally created at Music Hack Day Sydney by Rahim Sonawalla and is now developed by a team of people at its GitHub repository

For more background on the project, please see Rahim’s blog post.

Visit the SoCo documentation for a more detailed overview of the functionailty.

Join the chat at https://gitter.im/SoCo/SoCo Latest PyPI version

WARNING

Sonos has changed the way music service account information is available. This means that currently a group of music service will give authentication issues and cannot be used at all. Known members of this group are: Google Play Music, Apple Music, Amazon Music, Spotify and Napster.

Issue #557 is a meta issue for this problem and you can use that to track progress on solving the issues, but please refrain from posting “me too” comments in there. Also, there is no need to open any more separate issue about this. If you have another music service that should be on the list, comment in #557

As of v0.26.0, nascent music service support has been reinstated, with some known issues. Testing and issue reporting would be appreciated.

Installation

SoCo requires Python 3.6 or newer.

Use pip:

pip install soco

SoCo depends on a number of Python packages. If you use pip to install Soco, the dependencies will be installed automatically for you. If not, you can inspect the requirements in the requirements.txt file.

Basic Usage

You can interact with a Sonos Zone Player through a SoCo object. If you know the IP address of a Zone Player, you can create a SoCo object directly:

>>> from soco import SoCo
>>> my_zone = SoCo('192.168.1.101')
>>> my_zone.player_name
Kitchen
>>> my_zone.status_light = True
>>> my_zone.volume = 6

But perhaps the easiest way is to use the module-level discover function. This will find all the Zone Players on your network, and return a python set containing them:

>>> from soco import discover
>>> for zone in discover():
...        print(zone.player_name)
Living Room
Kitchen

If you prefer a list to a set:

>>> zone_list = list(discover())
>>> zone_list
[SoCo("192.168.1.101"), SoCo("192.168.1.102")]
>>> zone_list[0].mute = True

Of course, you can also play music!

#!/usr/bin/env python
from soco import SoCo

if __name__ == '__main__':
    sonos = SoCo('192.168.1.102') # Pass in the IP of your Sonos speaker
    # You could use the discover function instead, if you don't know the IP

    # Pass in a URI to a media file to have it streamed through the Sonos
    # speaker
    sonos.play_uri(
        'http://ia801402.us.archive.org/20/items/TenD2005-07-16.flac16/TenD2005-07-16t10Wonderboy.mp3')

    track = sonos.get_current_track_info()

    print(track['title'])

    sonos.pause()

    # Play a stopped or paused track
    sonos.play()

Support

If you need support for SoCo, feel free to post your question in the SoCo Gitter Room.

Example Applications

To show off what can be made with SoCo, a simple web application is included in the examples folder.

Screenshot of web app

Screenshot of web app

Features

SoCo supports the following controls amongst others:

  • Play, Pause, Stop

  • Next track, Previous track

  • Volume get and set

  • Mute (or unmute)

  • Get current transport information (if speaker is playing, paused or stopped)

  • Get information about the currently playing track

    • Track title

    • Artist

    • Album

    • Album Art (if available)

    • Track length

    • Duration played (for example, 30 seconds into a 3 minute song)

    • Playlist position (for example, item 5 in the playlist)

    • Track URI

  • Receive events when the player state changes

  • Search for and play music items:

    • Local music library

    • Webradio via TuneIn and music services (still unstable)

    • Saved Sonos favorites, favorite radio stations and shows

  • Switch the speaker’s source to line-in or TV input (if the Zone Player supports it)

  • Manage the Sonos queue:

    • Get the items in the queue

    • Add items to the queue

    • Clear the queue

    • Play a specific song from the queue

  • Join or unjoin speakers from a group

  • Put all Sonos speakers in a network into “party mode”.

  • Get or set alarms

  • Get or set sleep timers

  • Enable or disable surround speakers or subwoofer

  • Get information regarding a home theater setup:

    • If surround speakers or a subwoofer are paired

    • Which audio channel a given speaker handles

  • Get or set the speaker’s bass and treble EQ

  • Toggle the speaker’s loudness compensation, night mode and dialog mode

  • Toggle the white status light on the unit

  • Get the speaker’s information

    • Zone Name

    • Zone Icon

    • UID (usually something like RINCON_XXXXXXXXXXXXXXXXX)

    • Serial Number

    • Software version

    • Hardware version

    • MAC Address

  • Set the speaker’s Zone Name

  • Start a music library update and determine if one is in progress

SoCo also supports lower level access from Python to all Sonos services (e.g. ContentDirectory or RenderingControl).

SoCo Gitter Room

There is a SoCo Gitter discussion room. Feel free to drop by for support, ideas or casual conversation related to SoCo.

License

SoCo is released under the MIT license.

Release files for soco 0.31.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for soco 0.31.3
File Size Uploaded
soco-0.31.3.tar.gz 747.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for soco 0.31.3
File Interpreter ABI Platform
soco-0.31.3-py3-none-any.whl Python 3 none any Details

Total release size: 913.7 kB

Release files / soco-0.31.3.tar.gz

Download URL soco-0.31.3.tar.gz
Size 747.4 kB
Tags Source
SHA-256 checksum
How to use checksums
346f02eee7da065140e77a5a4c9d8a74414394c2d22aba9832fedbcdecbb7d47
BLAKE2b-256 checksum
How to use checksums
9f06ac15f2da2206a9dfdb2349a66dfe4402f9b97f4e904d153ff075d48ff96e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / soco-0.31.3-py3-none-any.whl

Download URL soco-0.31.3-py3-none-any.whl
Size 166.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cf5cc0574d6b505d32db02ce62cf4cd1c75a20e6787d8eac488951631a7c251
BLAKE2b-256 checksum
How to use checksums
63088bf3d0da4e0e7c11adac29dce8634ee6295b4f6d7a1b7019b57d8e5e3920
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.31.4

2 release files

This release

0.31.3 This release

2 release files

0.31.2

2 release files

0.31.1

2 release files

0.30.9

2 release files

0.30.8

2 release files

0.30.7

2 release files

0.30.5

2 release files

0.30.3

2 release files

0.30.2

2 release files

0.30.1

2 release files

0.30.0

2 release files

0.29.1

2 release files

0.28.1

2 release files

0.28.0

2 release files

0.27.1

2 release files

0.27.0

2 release files

0.26.3

2 release files

0.26.0

2 release files

0.25.2

2 release files

0.25.1

2 release files

0.24.1

2 release files

0.23.2

2 release files

0.23.1

2 release files

0.23.0

2 release files

0.22.6

2 release files

0.22.3

2 release files

0.22.1

2 release files

0.22.0

2 release files

0.21.3

2 release files

0.21.2

2 release files

0.21.1

2 release files

0.21

2 release files

0.20

2 release files

0.19

2 release files

0.18.1

2 release files

0.18

2 release files

0.17

2 release files

0.16

2 release files

0.15

2 release files

0.14

2 release files

0.13

2 release files

0.12

2 release files

0.11.1

2 release files

0.11

2 release files

0.10

2 release files

0.9

2 release files

0.8

2 release files

0.7

1 release file

0.6

1 release file

0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page