Schemas
Base schemas
The base schemas are Pydantic models used to represent track, artist, album or playlist data.
Pydantic schemas for albums.
AlbumData
Bases: BaseModel
Album data representation.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Album name |
id |
str
|
Album id |
uri |
str
|
Spotify URI for the album |
release_date |
date | str
|
The year the album was released. |
Source code in chopin/schemas/album.py
release_date_validate(v)
Format the release date based on the level of detail available.
Pydantic schemas for artists.
ArtistData
Bases: BaseModel
Artist data representation.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the artist |
id |
str
|
Id of the artist |
uri |
str
|
Spotify URI for the artist |
genres |
list[str] | None
|
A list of strings describing the artist genres |
Warning
The 'genres' information is not always available. And it can be quite flaky
Source code in chopin/schemas/artist.py
Pydantic schemas for playlists.
PlaylistData
Bases: BaseModel
Playlist representation.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the playlist |
uri |
str
|
Spotify URI for the playlist |
Source code in chopin/schemas/playlist.py
PlaylistSummary
Bases: BaseModel
Representation of a full playlist. It is used to describe playlists and back them up.
Attributes:
| Name | Type | Description |
|---|---|---|
playlist |
PlaylistData
|
The playlist described |
tracks |
list[TrackData]
|
A list of TrackData in the playlist |
_nb_tracks |
int | None
|
Number of tracks in the playlist |
_total_duration |
float | None
|
Length (in milliseconds) of the playlist |
_nb_artists |
int | None
|
Number of artists in the playlist |
_avg_features |
int | None
|
Average values across the track features |
_avg_popularity |
float | None
|
Average popularity of the tracks in the playlist |
Note
The private attributes are automatically computed in a validator.
Source code in chopin/schemas/playlist.py
__str__()
fill_fields()
Compute field values on initialzation.
Source code in chopin/schemas/playlist.py
serialize_model()
Serialize plalist summaries and add version information.
Source code in chopin/schemas/playlist.py
Pydantic schemas for tracks.
TrackData
Bases: BaseModel
Representation of a track.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Track name |
id |
str
|
Track id |
uri |
str
|
Spotify URI for the track |
duration_ms |
int
|
Duration of the track, in milliseconds |
popularity |
int | None
|
A [0, 100] measure for the track popularity. 100 is most popular |
added_at |
FormattedDate | None
|
A date, when available, for which the track was added in the playlist. |
album |
AlbumData | None
|
The album data |
artists |
list[ArtistData] | None
|
The artists on the track |
features |
list[ArtistData] | None
|
Audio features of the track. |
Warning
By default, tracks sent by the Spotify API do not contain audio feature information. A call to the dedicated endpoint is necessary to fill the attribute.
Source code in chopin/schemas/track.py
to_flatten_dict(**kwargs)
Export the track data as a non-nested dictionary.
datetime_to_date(dt)
Pydantc schemas for users.
UserData
Bases: BaseModel
User representation.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the user |
id |
str
|
The user id |
uri |
str
|
Spotify URI for the user |
Source code in chopin/schemas/user.py
Composer schema
The composer schema is used to configure your playlist composition.
Schemas for playlist composition.
ComposerConfig
Bases: BaseModel
Schema for a composer configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the playlist you wish to create |
description |
str
|
Description for your playlist |
nb_songs |
Annotated[int, Field(gt=0)]
|
Target number of songs for the playlist. |
playlists |
list[ComposerConfigItem] | None
|
A list of playlist names and their weight. |
uris |
list[ComposerConfigItem] | None
|
A list of spotify playlist URIs to pick from directly. |
history |
Annotated[list[ComposerConfigListeningHistory], Field(max_length=3)] | None
|
Include past listening habits and most listened songs. |
Source code in chopin/schemas/composer.py
fill_nb_songs()
From the nb_songs and item weights, compute the nb_songs of each item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Attributes of the composer configuration model. |
required |
Source code in chopin/schemas/composer.py
history_field_ranges_must_be_unique(v)
Check the history items are distinct.
Source code in chopin/schemas/composer.py
parse_yaml(file_path)
classmethod
Read a composer configuration from a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
The YAML file path. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A valid composer configuration model. |
Source code in chopin/schemas/composer.py
ComposerConfigItem
Bases: BaseModel
Base schema for input in the composer configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Annotated[str, extract_uri_from_playlist_link]
|
Name of the item. It should respect the simplify_string nomenclature |
weight |
Annotated[float, Field(ge=0)]
|
Weight of the input in the final composition |
Source code in chopin/schemas/composer.py
extract_uri_from_link(v)
If the value is an https link to spotify, extract the URI data.
This allow users to share full links to their playlists.
Source code in chopin/schemas/composer.py
lower_case_selection_method(selection_method)
Force the selection method to be lower case.
Source code in chopin/schemas/composer.py
ComposerConfigListeningHistory
Bases: BaseModel
Base schema for the configuration section which will add the current user's best songs.
Attributes:
| Name | Type | Description |
|---|---|---|
time_range |
Literal['short_term', 'medium_term', 'long_term']
|
Time criteria for the best tracks. One of short_term (~ last 4 weeks), medium_term (~ last 6 months) or long_term (~ all time). |
weight |
Annotated[float, Field(ge=0)]
|
Weight of the input in the final composition |