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 ]
}](../../_images/graphviz-d41067f623ab1b509b11277323b2b755d1199bb4.png)
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 artist(*, uri, name=None) Self [source]
Create a
Ref
withtype
ARTIST
.- Return type:
Self
- classmethod directory(*, uri, name=None) Self [source]
Create a
Ref
withtype
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].
- classmethod playlist(*, uri, name=None) Self [source]
Create a
Ref
withtype
PLAYLIST
.- Return type:
Self
-
type:
RefType
The object type, e.g. “artist”, “album”, “track”, “playlist”, “directory”. Read-only.
- class mopidy.models.Track(**data) None [source]
A track.
-
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].
-
last_modified:
- class mopidy.models.Album(**data) None [source]
An album.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- 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].
- 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.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
-
last_modified:
- class mopidy.models.Image(**data) None [source]
An image with a URI and dimensions.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- 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].