Skip to content

Data models

These immutable data models are used for all data transfer inbetween the backend, core, and frontend layers, as described in the architecture.

Relationships

---
  config:
    class:
      hideEmptyMembersBox: true
---
classDiagram
  direction TB

  class Ref
  class Album
  class Artist
  class Directory
  class Image
  class Playlist
  class TlTrack
  class Track
  class SearchResult

  Ref ..> "0..1" Directory
  Ref ..> "0..1" Artist
  Ref ..> "0..1" Track
  Ref ..> "0..1" Album
  Ref ..> "0..1" Playlist

  Album --> "0..*" Artist
  Album --> "0..*" Track

  Playlist --> "0..*" Track

  Track --> "0..1" Album
  Track --> "0..*" Artist

  TlTrack --> "1" Track

  SearchResult --> "*" Track
  SearchResult --> "*" Artist
  SearchResult --> "*" Album

Immutability

All fields are type checked and immutable. In other words, they can only be set through the class constructor during instance creation.

If you want to modify a model, use the model.replace() method to create a copy of the model with the desired modifications. 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(uri='an-uri', name='Christmas Carol', length=171)
>>> track1
Track(uri='an-uri', name='Christmas Carol', artists=frozenset(), album=None,
composers=frozenset(), performers=frozenset(), genre=None, track_no=None,
disc_no=None, date=None, length=171, bitrate=None, comment=None,
musicbrainz_id=None, last_modified=None)
>>> track2 = track1.replace(length=37)
>>> track2
Track(uri='an-uri', name='Christmas Carol', artists=frozenset(), album=None,
composers=frozenset(), performers=frozenset(), genre=None, track_no=None,
disc_no=None, date=None, length=37, bitrate=None, comment=None,
musicbrainz_id=None, last_modified=None)

mopidy.models

Classes:

  • Album

    An album.

  • Artist

    An artist.

  • Image

    An image with a URI and dimensions.

  • ModelType

    Enumeration of model types.

  • Playlist

    A playlist.

  • Ref

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

  • SearchResult

    A search result.

  • TlTrack

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

  • Track

    An audio track.

Album

Bases: BaseModel

An album.

Methods:

  • replace

    Return a new instance with updated fields.

  • serialize

    Serialize the model to a dict.

Attributes:

  • artists (frozenset[Artist]) –

    A set of album artists.

  • date (DateOrYear | None) –

    The album release date. A string formatted as "YYYY" or "YYYY-MM-DD".

  • musicbrainz_id (UUID | None) –

    The MusicBrainz ID of the album.

  • name (str | None) –

    The album name.

  • num_discs (NonNegativeInt | None) –

    The number of discs in the album.

  • num_tracks (NonNegativeInt | None) –

    The number of tracks in the album.

  • uri (Uri | None) –

    The album URI.

artists class-attribute instance-attribute

artists: frozenset[Artist] = frozenset()

A set of album artists.

date class-attribute instance-attribute

date: DateOrYear | None = Field(
    default=None, pattern="^\\d{4}(-\\d{2}-\\d{2})?$"
)

The album release date. A string formatted as "YYYY" or "YYYY-MM-DD".

musicbrainz_id class-attribute instance-attribute

musicbrainz_id: UUID | None = None

The MusicBrainz ID of the album.

name class-attribute instance-attribute

name: str | None = None

The album name.

num_discs class-attribute instance-attribute

num_discs: NonNegativeInt | None = None

The number of discs in the album.

num_tracks class-attribute instance-attribute

num_tracks: NonNegativeInt | None = None

The number of tracks in the album.

uri class-attribute instance-attribute

uri: Uri | None = None

The album URI.

replace

replace(**updated_fields: Any) -> Self

Return a new instance with updated fields.

serialize

serialize() -> dict[str, Any]

Serialize the model to a dict.

Artist

Bases: BaseModel

An artist.

Methods:

  • replace

    Return a new instance with updated fields.

  • serialize

    Serialize the model to a dict.

Attributes:

  • musicbrainz_id (UUID | None) –

    The MusicBrainz ID of the artist.

  • name (str | None) –

    The artist name.

  • sortname (str | None) –

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

  • uri (Uri | None) –

    The artist URI.

musicbrainz_id class-attribute instance-attribute

musicbrainz_id: UUID | None = None

The MusicBrainz ID of the artist.

name class-attribute instance-attribute

name: str | None = None

The artist name.

sortname class-attribute instance-attribute

sortname: str | None = None

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

uri class-attribute instance-attribute

uri: Uri | None = None

The artist URI.

replace

replace(**updated_fields: Any) -> Self

Return a new instance with updated fields.

serialize

serialize() -> dict[str, Any]

Serialize the model to a dict.

Image

Bases: BaseModel

An image with a URI and dimensions.

Methods:

  • replace

    Return a new instance with updated fields.

  • serialize

    Serialize the model to a dict.

Attributes:

  • height (NonNegativeInt | None) –

    Height of the image in pixels.

  • uri (Uri) –

    The image URI.

  • width (NonNegativeInt | None) –

    Width of the image in pixels.

height class-attribute instance-attribute

height: NonNegativeInt | None = None

Height of the image in pixels.

uri instance-attribute

uri: Uri

The image URI.

width class-attribute instance-attribute

width: NonNegativeInt | None = None

Width of the image in pixels.

replace

replace(**updated_fields: Any) -> Self

Return a new instance with updated fields.

serialize

serialize() -> dict[str, Any]

Serialize the model to a dict.

ModelType

Bases: StrEnum

Enumeration of model types.

Attributes:

ALBUM class-attribute instance-attribute

ALBUM = 'album'

An album.

ARTIST class-attribute instance-attribute

ARTIST = 'artist'

An artist.

DIRECTORY class-attribute instance-attribute

DIRECTORY = 'directory'

A directory.

PLAYLIST class-attribute instance-attribute

PLAYLIST = 'playlist'

A playlist.

TRACK class-attribute instance-attribute

TRACK = 'track'

A track.

Playlist

Bases: BaseModel

A playlist.

Methods:

  • replace

    Return a new instance with updated fields.

  • serialize

    Serialize the model to a dict.

Attributes:

  • last_modified (NonNegativeInt | None) –

    The playlist modification time in milliseconds since Unix epoch.

  • length (NonNegativeInt) –

    The number of tracks in the playlist.

  • name (str | None) –

    The playlist name.

  • tracks (tuple[Track, ...]) –

    The playlist's tracks.

  • uri (Uri) –

    The playlist URI.

last_modified class-attribute instance-attribute

last_modified: NonNegativeInt | None = None

The playlist modification time in milliseconds since Unix epoch.

length property

length: NonNegativeInt

The number of tracks in the playlist.

name class-attribute instance-attribute

name: str | None = None

The playlist name.

tracks class-attribute instance-attribute

tracks: tuple[Track, ...] = ()

The playlist's tracks.

uri instance-attribute

uri: Uri

The playlist URI.

replace

replace(**updated_fields: Any) -> Self

Return a new instance with updated fields.

serialize

serialize() -> dict[str, Any]

Serialize the model to a dict.

Ref

Bases: BaseModel

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.

Methods:

Attributes:

  • name (str | None) –

    The object name.

  • type (ModelType) –

    The object type, e.g. "artist", "album", "track", "playlist", "directory".

  • uri (Uri) –

    The object URI.

name class-attribute instance-attribute

name: str | None = None

The object name.

type instance-attribute

type: ModelType

The object type, e.g. "artist", "album", "track", "playlist", "directory".

uri instance-attribute

uri: Uri

The object URI.

album classmethod

album(*, uri: Uri, name: str | None = None) -> Self

Create a Ref with type ALBUM.

artist classmethod

artist(*, uri: Uri, name: str | None = None) -> Self

Create a Ref with type ARTIST.

directory classmethod

directory(*, uri: Uri, name: str | None = None) -> Self

Create a Ref with type DIRECTORY.

playlist classmethod

playlist(*, uri: Uri, name: str | None = None) -> Self

Create a Ref with type PLAYLIST.

replace

replace(**updated_fields: Any) -> Self

Return a new instance with updated fields.

serialize

serialize() -> dict[str, Any]

Serialize the model to a dict.

track classmethod

track(*, uri: Uri, name: str | None = None) -> Self

Create a Ref with type TRACK.

SearchResult

Bases: BaseModel

A search result.

Methods:

  • replace

    Return a new instance with updated fields.

  • serialize

    Serialize the model to a dict.

Attributes:

albums class-attribute instance-attribute

albums: tuple[Album, ...] = ()

The albums matching the search query.

artists class-attribute instance-attribute

artists: tuple[Artist, ...] = ()

The artists matching the search query.

tracks class-attribute instance-attribute

tracks: tuple[Track, ...] = ()

The tracks matching the search query.

uri class-attribute instance-attribute

uri: Uri | None = None

The search result URI.

replace

replace(**updated_fields: Any) -> Self

Return a new instance with updated fields.

serialize

serialize() -> dict[str, Any]

Serialize the model to a dict.

TlTrack

TlTrack(tlid: TracklistId, track: Track, **_: Any)

Bases: BaseModel

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 you can extract its values like this:

(tlid, track) = tl_track

Methods:

  • replace

    Return a new instance with updated fields.

  • serialize

    Serialize the model to a dict.

Attributes:

tlid class-attribute instance-attribute

tlid: TracklistId = Field(..., ge=1)

The tracklist ID.

track instance-attribute

track: Track

The track.

replace

replace(**updated_fields: Any) -> Self

Return a new instance with updated fields.

serialize

serialize() -> dict[str, Any]

Serialize the model to a dict.

Track

Bases: BaseModel

An audio track.

Methods:

  • replace

    Return a new instance with updated fields.

  • serialize

    Serialize the model to a dict.

Attributes:

album class-attribute instance-attribute

album: Album | None = None

The track album.

artists class-attribute instance-attribute

artists: frozenset[Artist] = frozenset()

A set of track artists.

bitrate class-attribute instance-attribute

bitrate: NonNegativeInt | None = None

The track's bitrate in kbit/s.

comment class-attribute instance-attribute

comment: str | None = None

The track comment.

composers class-attribute instance-attribute

composers: frozenset[Artist] = frozenset()

A set of track composers.

date class-attribute instance-attribute

date: DateOrYear | None = Field(
    default=None, pattern="^\\d{4}(-\\d{2}-\\d{2})?$"
)

The track release date. A string formatted as "YYYY" or "YYYY-MM-DD".

disc_no class-attribute instance-attribute

disc_no: NonNegativeInt | None = None

The disc number in the album.

genre class-attribute instance-attribute

genre: str | None = None

The track genre.

last_modified class-attribute instance-attribute

last_modified: NonNegativeInt | None = None

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 class-attribute instance-attribute

length: DurationMs | None = None

The track length in milliseconds.

musicbrainz_id class-attribute instance-attribute

musicbrainz_id: UUID | None = None

The MusicBrainz ID of the track.

name class-attribute instance-attribute

name: str | None = None

The track name.

performers class-attribute instance-attribute

performers: frozenset[Artist] = frozenset()

A set of track performers.

track_no class-attribute instance-attribute

track_no: NonNegativeInt | None = None

The track number in the album.

uri instance-attribute

uri: Uri

The track URI.

replace

replace(**updated_fields: Any) -> Self

Return a new instance with updated fields.

serialize

serialize() -> dict[str, Any]

Serialize the model to a dict.