mopidy.models — Data models

These immutable data models are used for all data transfer within the Mopidy backends and between the backends and the MPD frontend. All fields are optional and immutable. In other words, they can only be set through the class constructor during instance creation. Additionally fields are type checked.

If you want to modify a model, use the replace() method. It accepts keyword arguments for the parts of the model you want to change, and copies the rest of the data from the model you call it on. Example:

>>> from mopidy.models import Track
>>> track1 = Track(name='Christmas Carol', length=171)
>>> track1
Track(artists=[], length=171, name='Christmas Carol')
>>> track2 = track1.replace(length=37)
>>> track2
Track(artists=[], length=37, name='Christmas Carol')
>>> track1
Track(artists=[], length=171, name='Christmas Carol')

Data model relations

digraph model_relations {
Ref -> Album [ style="dotted", weight=1 ]
Ref -> Artist [ style="dotted", weight=1 ]
Ref -> Directory [ style="dotted", weight=1 ]
Ref -> Playlist [ style="dotted", weight=1 ]
Ref -> Track [ style="dotted", weight=1 ]

Playlist -> Track [ label="has 0..n", weight=2 ]
Track -> Album [ label="has 0..1", weight=10 ]
Track -> Artist [ label="has 0..n", weight=10 ]
Album -> Artist [ label="has 0..n", weight=10 ]

Image

SearchResult -> Artist [ label="has 0..n", weight=1 ]
SearchResult -> Album [ label="has 0..n", weight=1 ]
SearchResult -> Track [ label="has 0..n", weight=1 ]

TlTrack -> Track [ label="has 1", weight=20 ]
}

Data model API

class mopidy.models.Ref(**data) None[source]

Model to represent URI references with a human friendly name and type.

This is intended for use a lightweight object “free” of metadata that can be passed around instead of using full blown models.

classmethod album(*, uri, name=None) Self[source]

Create a Ref with type ALBUM.

Return type:

Self

classmethod artist(*, uri, name=None) Self[source]

Create a Ref with type ARTIST.

Return type:

Self

classmethod directory(*, uri, name=None) Self[source]

Create a Ref with type DIRECTORY.

Return type:

Self

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str | None

The object name. Read-only.

classmethod playlist(*, uri, name=None) Self[source]

Create a Ref with type PLAYLIST.

Return type:

Self

classmethod track(*, uri, name=None) Self[source]

Create a Ref with type TRACK.

Return type:

Self

type: RefType

The object type, e.g. “artist”, “album”, “track”, “playlist”, “directory”. Read-only.

uri: NewType(Uri, str)

The object URI. Read-only.

class mopidy.models.Track(**data) None[source]

A track.

album: Album | None

The track Album. Read-only.

artists: frozenset[Artist]

A set of track artists. Read-only.

bitrate: Optional[Annotated[int]]

The track’s bitrate in kbit/s. Read-only.

comment: str | None

The track comment. Read-only.

composers: frozenset[Artist]

A set of track composers. Read-only.

date: Union[NewType(Date, str), NewType(Year, str), None]

The track release date. Read-only.

disc_no: Optional[Annotated[int]]

The disc number in the album. Read-only.

genre: str | None

The track genre. Read-only.

last_modified: Optional[Annotated[int]]

Integer representing when the track was last modified. Exact meaning depends on source of track. For local files this is the modification time in milliseconds since Unix epoch. For other backends it could be an equivalent timestamp or simply a version counter.

length: Optional[NewType(DurationMs, int)]

The track length in milliseconds or None if there is no duration. Read-only.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

musicbrainz_id: UUID | None

The MusicBrainz ID of the track. Read-only.

name: str | None

The track name. Read-only.

performers: frozenset[Artist]

A set of track performers. Read-only.

track_no: Optional[Annotated[int]]

The track number in the album. Read-only.

uri: Optional[NewType(Uri, str)]

The track URI. Read-only.

class mopidy.models.Album(**data) None[source]

An album.

artists: frozenset[Artist]

A set of album artists. Read-only.

date: Union[NewType(Date, str), NewType(Year, str), None]

The album release date. Read-only.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

musicbrainz_id: UUID | None

The MusicBrainz ID of the album. Read-only.

name: str | None

The album name. Read-only.

num_discs: Optional[Annotated[int]]

The number of discs in the album. Read-only.

num_tracks: Optional[Annotated[int]]

The number of tracks in the album. Read-only.

uri: Optional[NewType(Uri, str)]

The album URI. Read-only.

class mopidy.models.Artist(**data) None[source]

An artist.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

musicbrainz_id: UUID | None

The MusicBrainz ID of the artist. Read-only.

name: str | None

The artist name. Read-only.

sortname: str | None

Artist name for better sorting, e.g. with articles stripped. Read only.

uri: Optional[NewType(Uri, str)]

The artist URI. Read-only.

class mopidy.models.Playlist(**data) None[source]

A playlist.

last_modified: Optional[Annotated[int]]

The playlist modification time in milliseconds since Unix epoch. Read-only.

property length: Annotated[int, Ge(ge=0)]

The number of tracks in the playlist. Read-only.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str | None

The playlist name. Read-only.

tracks: tuple[Track, ...]

The playlist’s tracks. Read-only.

uri: Optional[NewType(Uri, str)]

The playlist URI. Read-only.

class mopidy.models.Image(**data) None[source]

An image with a URI and dimensions.

height: Optional[Annotated[int]]

Optional height of the image or None. Read-only.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

uri: NewType(Uri, str)

The image URI. Read-only.

width: Optional[Annotated[int]]

Optional width of the image or None. Read-only.

class mopidy.models.TlTrack(tlid, track, **_) None[source]

A tracklist track. Wraps a regular track and it’s tracklist ID.

The use of TlTrack allows the same track to appear multiple times in the tracklist.

This class also accepts it’s parameters as positional arguments. Both arguments must be provided, and they must appear in the order they are listed here.

This class also supports iteration, so your extract its values like this:

(tlid, track) = tl_track
model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

tlid: NewType(TracklistId, int)

The tracklist ID. Read-only.

track: Track

The track. Read-only.

class mopidy.models.SearchResult(**data) None[source]

A search result.

albums: tuple[Album, ...]

The albums matching the search query. Read-only.

artists: tuple[Artist, ...]

The artists matching the search query. Read-only.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

tracks: tuple[Track, ...]

The tracks matching the search query. Read-only.

uri: Optional[NewType(Uri, str)]

The search result URI. Read-only.