Statistics API
The statistics/* commands return listening statistics built from the play history. Every command needs the library.read scope and covers the plays of the authenticated user, unless you ask for other users.
Schema version 99 does not guarantee that the statistics commands are available. Schema version 100 does not guarantee all the result details described on this page. The commands and some result changes did not have a dedicated schema version bump. A server with schema version 101 or newer has all the commands and result details described here. The optional arguments for other users require schema version 103 or newer.
Commands
Section titled “Commands”| Command | Returns |
|---|---|
statistics/play_history |
list[ItemMapping], most recent first |
statistics/top_items |
list[TopItemResult] |
statistics/genre_distribution |
list[DistributionItem] |
statistics/decade_distribution |
list[DistributionItem] |
statistics/play_count |
int |
statistics/plays_over_time |
list[TimeSeriesPoint] |
statistics/listening_activity |
list[HeatmapPoint] |
statistics/listening_time |
list[ListeningTimeItem] |
The result models live in music_assistant_models.statistics.
The command docstrings in the server describe every parameter.
from music_assistant_models.enums import MediaType
top_artists = await client.send_command( "statistics/top_items", media_type=MediaType.ARTIST, period="month", limit=10, timezone="Europe/Berlin",)for entry in top_artists: print(entry["item"]["name"], entry["play_count"])Periods and time zones
Section titled “Periods and time zones”Most commands take a period:
| Period | Covers |
|---|---|
today |
Since local midnight |
week |
The last 7 days |
month |
The last 30 days |
year |
The last 365 days |
all_time |
Everything |
Pass the user’s IANA timezone (for example Europe/Berlin). It sets where today starts and how plays fall into hours, days and weeks. It defaults to UTC, so a client that leaves it out shows buckets that are shifted for most users. An unknown period or time zone fails with InvalidDataError.
limit is capped at 500 on play_history, top_items, genre_distribution, decade_distribution and listening_time. A limit below 1 fails with InvalidDataError.
Other users
Section titled “Other users”Every command except statistics/play_history takes users, a list of user ids or usernames, and all_users, to combine the plays of several users. Asking for someone else’s plays needs the users.impersonate scope and fails with InsufficientPermissions without it. Both arguments require API schema version 103 or newer.
Result details
Section titled “Result details”-
Items in
play_historyandtop_itemsareItemMappingreferences. Theiravailableflag reflects known library and provider availability, but does not guarantee that the item can still be played. History can outlive the library. -
Albums and artists count the plays of their tracks:
play_countandtop_itemscount the album’s tracks for an album and the tracks an artist is credited on for an artist. -
plays_over_timereturns a complete series, oldest first. Every bucket from the start of the period (or the first play, forall_time) through the current one is included, with0for buckets without plays. It returns an empty list when the period holds no plays at all. Thetimestampformat depends ongranularity:Granularity Timestamp hour2026-10-29 14:00:00day2026-10-29week2026-10-26, the Monday the week starts onmonth2026-10 -
listening_activityreturns oneHeatmapPointper hour of day (0-23) and weekday (0is Monday) that has plays. Missing cells mean no plays. -
listening_timesums the durations of completed plays of library tracks, in minutes. Withgroup_by="artist"each result carries the artist initem, so two artists with the same name stay separate. Withgroup_by="genre",itemisnull. -
Genre and decade results only count library tracks with a known genre or album year.
Music Assistant is a project of the Open Home Foundation.