Music Assistant Client

1.3.5 · active · verified Fri Apr 17

`music-assistant-client` is the official asynchronous Python client library for Music Assistant, a powerful server that unifies various music sources (streaming services, local files) into a single library. It allows programmatic interaction with your Music Assistant instance to manage playback, browse libraries, and more. The current version is 1.3.5, with frequent updates focused on stability and new features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a Music Assistant server, retrieve server information, and list available music providers. Remember to replace `http://localhost:8095` with the actual URL of your Music Assistant instance.

import asyncio
from music_assistant_client import MusicAssistantClient
from music_assistant_client.exceptions import MusicAssistantError

async def main():
    # Replace with your Music Assistant server URL (e.g., http://192.168.1.100:8095)
    mass_client = MusicAssistantClient("http://localhost:8095")
    try:
        # Connect to the Music Assistant server
        await mass_client.connect()
        print(f"Connected to Music Assistant: {mass_client.server_info.server_version}")

        # Example: List available music providers
        providers = await mass_client.music.get_music_providers()
        print("\nMusic Providers:")
        for provider in providers:
            print(f"- {provider.name} (type: {provider.type.value})")

        # Example: Get all artists (might be large)
        # artists = await mass_client.music.get_all_artists()
        # print(f"\nTotal artists: {len(artists)}")

    except MusicAssistantError as e:
        print(f"Error connecting to Music Assistant: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
    finally:
        # Ensure the connection is properly closed
        await mass_client.disconnect()

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →