Music Assistant Client
Actively maintained. Last release 13 days ago, commits in 19 of the last 26 weeks. A safe choice.
pip install music-assistant-clientMusic Assistant Client
Python client to interact with the Music Assistant Server API
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:
1. Using a Long-Lived Token (Recommended)
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()
