Skip to main content

Music Assistant Client

Python client to interact with the Music Assistant Server API


A project from the Open Home Foundation

Installation

pip install music-assistant-client

Authentication

Starting with Music Assistant Server schema version 28, authentication is required to connect to the server. The client supports multiple authentication methods:

The recommended approach is to use a long-lived token. You can create Long Lived tokens in the Music Assistant web interface in your profile settings. You can also obtain one using the login_with_token() helper:

from music_assistant_client import login_with_token, MusicAssistantClient

# Login and get a long-lived token
user, token = await login_with_token(
    "http://your-server:8095",
    "your_username",
    "your_password",
    token_name="My Application"
)

# Save the token securely for future use
print(f"Your token: {token}")

# Use the token to connect
async with MusicAssistantClient("http://your-server:8095", None, token=token) as client:
    await client.start_listening()

2. Manual Token Management

You can also manually manage the authentication process:

from music_assistant_client import login, MusicAssistantClient

# Step 1: Login to get an access token
user, access_token = await login(
    "http://your-server:8095",
    "your_username",
    "your_password"
)

# Step 2: Connect with the access token and create a long-lived token
async with MusicAssistantClient("http://your-server:8095", None, token=access_token) as client:
    long_lived_token = await client.auth.create_token(name="My Application")

# Step 3: Use the long-lived token for future connections
async with MusicAssistantClient("http://your-server:8095", None, token=long_lived_token) as client:
    await client.start_listening()

3. Using Username and Password Directly

For simple scripts or testing, you can use the login_with_token() helper which handles everything:

from music_assistant_client import login_with_token, MusicAssistantClient

user, token = await login_with_token(
    "http://your-server:8095",
    "username",
    "password"
)

async with MusicAssistantClient("http://your-server:8095", None, token=token) as client:
    await client.start_listening()

Backward Compatibility

The client automatically detects the server schema version and only requires authentication for schema version 28 and above. Connections to older servers (schema < 28) will continue to work without authentication.

SSL/TLS Support

The client supports HTTPS connections. For servers with valid certificates, simply use an https:// URL:

async with MusicAssistantClient("https://music.example.com", None, token=token) as client:
    await client.start_listening()

For self-signed certificates or custom CAs, provide an SSL context:

import ssl

ssl_context = ssl.create_default_context(cafile="/path/to/ca-bundle.pem")
async with MusicAssistantClient("https://music.local", None, token=token, ssl_context=ssl_context) as client:
    await client.start_listening()

All authentication helper functions also accept an optional ssl_context parameter. You can also simply pass in a aiohttp Client with the ssl context already set.

API Reference

Client Class

MusicAssistantClient(server_url, aiohttp_session=None, token=None, ssl_context=None)

  • server_url: The URL of the Music Assistant server (e.g., http://mass.local:8095 or https://music.example.com)
  • aiohttp_session: Optional aiohttp ClientSession to use
  • token: Optional authentication token (required for schema >= 28)
  • ssl_context: Optional SSL context for HTTPS connections (for custom CAs or self-signed certificates)

Controllers:

The client provides several controllers for interacting with different aspects of the server:

  • client.auth - Authentication and user management
  • client.music - Music library operations (browse, search, get tracks/albums/artists/playlists, etc.)
  • client.players - Player control and information
  • client.player_queues - Queue management for players
  • client.config - Server configuration management

Example Usage

import asyncio
from music_assistant_client import MusicAssistantClient, login_with_token

async def main():
    # Get a token (do this once and save it)
    user, token = await login_with_token(
        "http://localhost:8095",
        "admin",
        "password"
    )

    # Connect to the server
    async with MusicAssistantClient("http://localhost:8095", None, token=token) as client:
        # Subscribe to events
        def on_event(event):
            print(f"Received event: {event}")

        client.subscribe(on_event)

        # Start listening for events
        await client.start_listening()

asyncio.run(main())

Error Handling

The client raises specific exceptions for authentication errors:

  • AuthenticationRequired: Raised when connecting to schema >= 28 without a token
  • AuthenticationFailed: Raised when the token is invalid or expired
  • LoginFailed: Raised when username/password authentication fails
from music_assistant_models.errors import AuthenticationRequired, AuthenticationFailed, LoginFailed

try:
    async with MusicAssistantClient(server_url, None, token=token) as client:
        await client.start_listening()
except AuthenticationRequired:
    print("Please provide an authentication token")
except AuthenticationFailed:
    print("Invalid or expired token")
except LoginFailed:
    print("Invalid username or password")

Metadata

Release files for music-assistant-client 1.8.0

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

Source distribution (sdist)

Source distribution for music-assistant-client 1.8.0
File Size Uploaded Provenance Actions
music_assistant_client-1.8.0.tar.gz 56.9 kB Without provenance Details for music_assistant_client-1.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for music-assistant-client 1.8.0
File Interpreter ABI Platform Actions
music_assistant_client-1.8.0-py3-none-any.whl Python 3 none any Details for music_assistant_client-1.8.0-py3-none-any.whl

Total release size: 112.9 kB

Release files / music_assistant_client-1.8.0.tar.gz

Download URL music_assistant_client-1.8.0.tar.gz
Size 56.9 kB
Tags Source
SHA-256 checksum
How to use checksums
96983c43720e9c5dc6d41485fe8fa6dc9177cb60c023864f8286d97f44418de9
BLAKE2b-256 checksum
How to use checksums
8919c8689de5755a45c14ab22d1c903b5db553e99d7ebd727e7089860f0ddad0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / music_assistant_client-1.8.0-py3-none-any.whl

Download URL music_assistant_client-1.8.0-py3-none-any.whl
Size 56.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2a278b3991937b12bc973188960af6abd08bf15b248b0ea29b195add8bf547c
BLAKE2b-256 checksum
How to use checksums
6a933f8e9a838a6ca236c4e80c85ff07f79721294b6da2becf352a2467e38482
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for music-assistant-client 1.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.8.0 This release

2 release files No provenance

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