spotify-soloist-client 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 James Pickering
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,117 @@
1
+ Metadata-Version: 2.5
2
+ Name: spotify-soloist-client
3
+ Version: 0.1.0
4
+ Summary: A Python client for the Spotify Soloist WebSocket API, with a low-level JSON API and a higher-level Pydantic-typed API.
5
+ Author-email: James Pickering <james_pic@hotmail.com>
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.10
9
+ Requires-Dist: pydantic>=2.0
10
+ Requires-Dist: websockets>=16.1.1
11
+ Description-Content-Type: text/markdown
12
+
13
+ # spotify-soloist-client
14
+
15
+ A Python client for the [Spotify Soloist](https://developer.spotify.com/documentation/soloist) WebSocket API, with a low-level JSON API and a higher-level Pydantic-typed API.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ uv add spotify-soloist-client
21
+ ```
22
+
23
+ Requires Python 3.10+, `websockets`, and `pydantic`.
24
+
25
+ ## Usage
26
+
27
+ ### Connecting to a running service
28
+
29
+ The top-level `connect` context manager connects to an already-running Spotify Soloist (started with `--ws`) and yields the typed client:
30
+
31
+ ```python
32
+ import asyncio
33
+ from spotify_soloist_client import connect
34
+
35
+
36
+ async def main():
37
+ async with connect("127.0.0.1", 9090) as soloist:
38
+ auth = await soloist.get_auth_state()
39
+ print(auth.logged_in, auth.device_name)
40
+
41
+ def on_volume(event):
42
+ print("volume changed:", event.volume)
43
+
44
+ soloist.add_volume_changed_listener(on_volume)
45
+ await soloist.set_volume(42)
46
+
47
+
48
+ asyncio.run(main())
49
+ ```
50
+
51
+ ### Downloading and running a binary
52
+
53
+ The top-level `download_and_run` context manager downloads (and caches) the Soloist build for this platform/arch, starts it, and yields a `ManagedSoloistClient` — a subclass of the main client with extra `update_binary()`, `reload_daemon()` and `update_binary_and_reload()` methods:
54
+
55
+ ```python
56
+ import asyncio
57
+ from datetime import timedelta
58
+ from spotify_soloist_client import download_and_run
59
+
60
+
61
+ async def main():
62
+ async with download_and_run(
63
+ device_name="Kitchen speaker",
64
+ api_key="<your-soloist-api-key>",
65
+ ws="127.0.0.1:0",
66
+ # re-download if the cached binary is older than this (timedelta or seconds)
67
+ max_soloist_age=timedelta(days=80),
68
+ ) as soloist:
69
+ auth = await soloist.get_auth_state()
70
+ print(auth.logged_in)
71
+ await soloist.update_binary_and_reload() # re-download + restart the daemon
72
+
73
+
74
+ asyncio.run(main())
75
+ ```
76
+
77
+ `download_and_run` accepts the same arguments as the Soloist command line (`device_name` and `api_key` are required): `ws`, `data_dir`, `cache_dir`, `cache_size`, `pipewire_device`, `initial_volume`, `single_track`, `pair`, `verbose`, `print_version`, `print_help`.
78
+
79
+ It re-downloads the binary when it is too old — because it fails to start with exit code 10 (build expired) or because it is older than `max_soloist_age`. On exit it closes the client and terminates the daemon.
80
+
81
+ > Note: `update_binary()` re-downloads the cached binary but the running daemon keeps using the build it started with. Use `reload_daemon()` to restart the daemon with the current binary, or `update_binary_and_reload()` to re-download the latest build and restart the daemon with it. After either reload the client reconnects to the new endpoint; note that the port may change (e.g. with `ws="127.0.0.1:0"`).
82
+
83
+ ### Low-level JSON API
84
+
85
+ The low-level `WebSocketClient` is just JSON — its public API is `send` / `add_listener`:
86
+
87
+ ```python
88
+ from spotify_soloist_client import WebSocketClient
89
+
90
+ async with WebSocketClient("127.0.0.1", 9090) as client:
91
+ client.add_listener(lambda event: print("server said:", event))
92
+ await client.send({"type": "command", "command": "get_auth_state"})
93
+ ```
94
+
95
+ ### Higher-level typed API
96
+
97
+ `SoloistClient` (what `connect` and `download_and_run` yield) wraps the WebSocket API with Pydantic models:
98
+
99
+ * **Commands** — `get_auth_state()`, `get_state()`, `get_queue(limit=None)`, `play(uri=None)`, `pause()`, `skip_next()`, `skip_prev()`, `seek(position_ms)`, `set_volume(volume)`, `set_shuffle(enabled)`, `set_repeat_context(enabled)`, `set_repeat_track(enabled)`, `add_to_queue(uri)`, `activate()`, `deactivate()`. Query commands return the parsed event; control commands return a `CommandResult`.
100
+ * **Typed listeners** — one `add_TYPE_listener` method per event type (`auth_state`, `playback_state`, `track_changed`, `playback_changed`, `volume_changed`, `device_changed`, `context_changed`, `options_changed`, `position_sync`, `queue_changed`, `command_result`, `error`). Listeners receive parsed event objects; async listeners are supported; exceptions in listeners are logged, never propagated.
101
+
102
+ Methods don't take timeout arguments. They wait for their response using the caller's cancellation (e.g. `asyncio.timeout`, or tasks in an `asyncio.TaskGroup`); when cancelled, the pending request is cleaned up so the client stays usable.
103
+
104
+ Server-reported errors (e.g. an unauthenticated command) raise `SoloistAPIError` with the server's message.
105
+
106
+ ## Development
107
+
108
+ ```bash
109
+ uv sync
110
+ uv run pytest
111
+ ```
112
+
113
+ Tests run against the mock server (`spotify_soloist_client.mock_server`); no real `soloist` binary is needed.
114
+
115
+ ## License
116
+
117
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,105 @@
1
+ # spotify-soloist-client
2
+
3
+ A Python client for the [Spotify Soloist](https://developer.spotify.com/documentation/soloist) WebSocket API, with a low-level JSON API and a higher-level Pydantic-typed API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ uv add spotify-soloist-client
9
+ ```
10
+
11
+ Requires Python 3.10+, `websockets`, and `pydantic`.
12
+
13
+ ## Usage
14
+
15
+ ### Connecting to a running service
16
+
17
+ The top-level `connect` context manager connects to an already-running Spotify Soloist (started with `--ws`) and yields the typed client:
18
+
19
+ ```python
20
+ import asyncio
21
+ from spotify_soloist_client import connect
22
+
23
+
24
+ async def main():
25
+ async with connect("127.0.0.1", 9090) as soloist:
26
+ auth = await soloist.get_auth_state()
27
+ print(auth.logged_in, auth.device_name)
28
+
29
+ def on_volume(event):
30
+ print("volume changed:", event.volume)
31
+
32
+ soloist.add_volume_changed_listener(on_volume)
33
+ await soloist.set_volume(42)
34
+
35
+
36
+ asyncio.run(main())
37
+ ```
38
+
39
+ ### Downloading and running a binary
40
+
41
+ The top-level `download_and_run` context manager downloads (and caches) the Soloist build for this platform/arch, starts it, and yields a `ManagedSoloistClient` — a subclass of the main client with extra `update_binary()`, `reload_daemon()` and `update_binary_and_reload()` methods:
42
+
43
+ ```python
44
+ import asyncio
45
+ from datetime import timedelta
46
+ from spotify_soloist_client import download_and_run
47
+
48
+
49
+ async def main():
50
+ async with download_and_run(
51
+ device_name="Kitchen speaker",
52
+ api_key="<your-soloist-api-key>",
53
+ ws="127.0.0.1:0",
54
+ # re-download if the cached binary is older than this (timedelta or seconds)
55
+ max_soloist_age=timedelta(days=80),
56
+ ) as soloist:
57
+ auth = await soloist.get_auth_state()
58
+ print(auth.logged_in)
59
+ await soloist.update_binary_and_reload() # re-download + restart the daemon
60
+
61
+
62
+ asyncio.run(main())
63
+ ```
64
+
65
+ `download_and_run` accepts the same arguments as the Soloist command line (`device_name` and `api_key` are required): `ws`, `data_dir`, `cache_dir`, `cache_size`, `pipewire_device`, `initial_volume`, `single_track`, `pair`, `verbose`, `print_version`, `print_help`.
66
+
67
+ It re-downloads the binary when it is too old — because it fails to start with exit code 10 (build expired) or because it is older than `max_soloist_age`. On exit it closes the client and terminates the daemon.
68
+
69
+ > Note: `update_binary()` re-downloads the cached binary but the running daemon keeps using the build it started with. Use `reload_daemon()` to restart the daemon with the current binary, or `update_binary_and_reload()` to re-download the latest build and restart the daemon with it. After either reload the client reconnects to the new endpoint; note that the port may change (e.g. with `ws="127.0.0.1:0"`).
70
+
71
+ ### Low-level JSON API
72
+
73
+ The low-level `WebSocketClient` is just JSON — its public API is `send` / `add_listener`:
74
+
75
+ ```python
76
+ from spotify_soloist_client import WebSocketClient
77
+
78
+ async with WebSocketClient("127.0.0.1", 9090) as client:
79
+ client.add_listener(lambda event: print("server said:", event))
80
+ await client.send({"type": "command", "command": "get_auth_state"})
81
+ ```
82
+
83
+ ### Higher-level typed API
84
+
85
+ `SoloistClient` (what `connect` and `download_and_run` yield) wraps the WebSocket API with Pydantic models:
86
+
87
+ * **Commands** — `get_auth_state()`, `get_state()`, `get_queue(limit=None)`, `play(uri=None)`, `pause()`, `skip_next()`, `skip_prev()`, `seek(position_ms)`, `set_volume(volume)`, `set_shuffle(enabled)`, `set_repeat_context(enabled)`, `set_repeat_track(enabled)`, `add_to_queue(uri)`, `activate()`, `deactivate()`. Query commands return the parsed event; control commands return a `CommandResult`.
88
+ * **Typed listeners** — one `add_TYPE_listener` method per event type (`auth_state`, `playback_state`, `track_changed`, `playback_changed`, `volume_changed`, `device_changed`, `context_changed`, `options_changed`, `position_sync`, `queue_changed`, `command_result`, `error`). Listeners receive parsed event objects; async listeners are supported; exceptions in listeners are logged, never propagated.
89
+
90
+ Methods don't take timeout arguments. They wait for their response using the caller's cancellation (e.g. `asyncio.timeout`, or tasks in an `asyncio.TaskGroup`); when cancelled, the pending request is cleaned up so the client stays usable.
91
+
92
+ Server-reported errors (e.g. an unauthenticated command) raise `SoloistAPIError` with the server's message.
93
+
94
+ ## Development
95
+
96
+ ```bash
97
+ uv sync
98
+ uv run pytest
99
+ ```
100
+
101
+ Tests run against the mock server (`spotify_soloist_client.mock_server`); no real `soloist` binary is needed.
102
+
103
+ ## License
104
+
105
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,45 @@
1
+ [project]
2
+ name = "spotify-soloist-client"
3
+ dynamic = ["version"]
4
+ description = "A Python client for the Spotify Soloist WebSocket API, with a low-level JSON API and a higher-level Pydantic-typed API."
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "James Pickering", email = "james_pic@hotmail.com" }
8
+ ]
9
+ license = "MIT"
10
+ license-files = ["LICENSE"]
11
+ requires-python = ">=3.10"
12
+ dependencies = [
13
+ "websockets>=16.1.1",
14
+ "pydantic>=2.0",
15
+ ]
16
+
17
+ [tool.pytest.ini_options]
18
+ asyncio_mode = "auto"
19
+ asyncio_default_fixture_loop_scope = "function"
20
+ asyncio_default_test_loop_scope = "function"
21
+
22
+ [project.scripts]
23
+ spotify-soloist-client = "spotify_soloist_client:main"
24
+
25
+ [build-system]
26
+ requires = ["hatchling>=1.28,<2", "hatch-vcs>=0.5,<1"]
27
+ build-backend = "hatchling.build"
28
+
29
+ [tool.hatch.version]
30
+ source = "vcs"
31
+
32
+ [dependency-groups]
33
+ dev = [
34
+ "pytest>=9.2.0",
35
+ "pytest-asyncio>=1.5.0",
36
+ ]
37
+
38
+ [tool.hatch.build.targets.sdist]
39
+ include = [
40
+ "src",
41
+ "tests",
42
+ "README.md",
43
+ "LICENSE",
44
+ "pyproject.toml",
45
+ ]
@@ -0,0 +1,116 @@
1
+ """Client for the Spotify Soloist WebSocket API.
2
+
3
+ Two levels of API:
4
+
5
+ * Low-level: :class:`WebSocketClient` -- just JSON. ``send`` / ``add_listener``.
6
+ * Higher-level: :class:`SoloistClient` -- Pydantic-typed commands and listeners.
7
+
8
+ Top-level context managers:
9
+
10
+ * :func:`connect` -- connect to a running Spotify Soloist service.
11
+ * :func:`download_and_run` -- download/cache a Soloist binary for this
12
+ platform, run it, connect to it, and clean up on exit. Yields a
13
+ :class:`ManagedSoloistClient` with extra ``update_binary``,
14
+ ``reload_daemon`` and ``update_binary_and_reload`` methods.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from .client import SoloistClient, WebSocketClient, connect
20
+ from .errors import (
21
+ SoloistAPIError,
22
+ SoloistConnectionError,
23
+ SoloistDownloadError,
24
+ SoloistError,
25
+ SoloistStartupError,
26
+ UnknownEventTypeError,
27
+ UnsupportedPlatformError,
28
+ )
29
+ from .events import (
30
+ AuthState,
31
+ CommandResult,
32
+ ContextChanged,
33
+ Cover,
34
+ Decorations,
35
+ DeviceChanged,
36
+ Entity,
37
+ ErrorEvent,
38
+ Identity,
39
+ OptionsChanged,
40
+ PlaybackChanged,
41
+ PlaybackDecoration,
42
+ PlaybackOptions,
43
+ PlaybackState,
44
+ Position,
45
+ PositionSync,
46
+ QueueChanged,
47
+ QueueEntry,
48
+ TrackChanged,
49
+ VisualIdentity,
50
+ VolumeChanged,
51
+ parse_event,
52
+ )
53
+ from .managed import ManagedSoloistClient, download_and_run
54
+
55
+ __all__ = [
56
+ # top-level context managers
57
+ "connect",
58
+ "download_and_run",
59
+ # clients
60
+ "SoloistClient",
61
+ "WebSocketClient",
62
+ "ManagedSoloistClient",
63
+ # exceptions
64
+ "SoloistError",
65
+ "SoloistConnectionError",
66
+ "SoloistAPIError",
67
+ "SoloistStartupError",
68
+ "SoloistDownloadError",
69
+ "UnknownEventTypeError",
70
+ "UnsupportedPlatformError",
71
+ # events
72
+ "parse_event",
73
+ "Cover",
74
+ "Decorations",
75
+ "Identity",
76
+ "VisualIdentity",
77
+ "PlaybackDecoration",
78
+ "PlaybackOptions",
79
+ "PlaybackState",
80
+ "Position",
81
+ "QueueEntry",
82
+ "Entity",
83
+ "AuthState",
84
+ "TrackChanged",
85
+ "PlaybackChanged",
86
+ "VolumeChanged",
87
+ "DeviceChanged",
88
+ "ContextChanged",
89
+ "OptionsChanged",
90
+ "PositionSync",
91
+ "QueueChanged",
92
+ "CommandResult",
93
+ "ErrorEvent",
94
+ ]
95
+
96
+
97
+ def main() -> None:
98
+ print("spotify-soloist-client: use the async API directly.")
99
+ print()
100
+ print(" # low-level JSON")
101
+ print(" import asyncio")
102
+ print(" from spotify_soloist_client import WebSocketClient")
103
+ print()
104
+ print(" # higher-level typed")
105
+ print(" from spotify_soloist_client import connect")
106
+ print(" # async with connect('127.0.0.1', 9090) as soloist: ...")
107
+ print()
108
+ print(" # or download and run a binary for this platform")
109
+ print(" from spotify_soloist_client import download_and_run")
110
+ print(
111
+ " # async with download_and_run(device_name='...', api_key='...') as soloist: ..."
112
+ )
113
+
114
+
115
+ if __name__ == "__main__":
116
+ main()