pycmc
pycmc.album.
charts
Query the charts for the given album of a selected streamer type.
https://api.chartmetric.com/api/album/:id/:type/charts
Parameters
stype: string streaming platform, choose from
stype
‘applemusic’, ‘itunes’ or ‘amazon’ * cmid: string or int chartmetric album ID * start_date: string start data in ISO format * end_date: string end date in ISO format
cmid
start_date
end_date
Returns
A list of dictionaries of the chart for the given album.
get_album_ids
Query all the related album IDs given a specific ID type.
https://api.chartmetric.com/api/album/:type/:id/get-ids
id_type: string of the type of ID, choose from
id_type
‘chartmetric’, ‘upc’, ‘spotify’, ‘itunes’, ‘deezer’ * specific_id: specific ID corresponding to the id_type
specific_id
A list of dictionaries with various types of ID.
metadata
Query the album metadata endpoint given the chartmetric ID.
https://api.chartmetric.com/api/album/:id
cmid: string or int Chartmetric album ID
A dictionary of album metadata.
playlists
Query the album playlist placement API endpoint.
https://api.chartmetric.com/api/album/:id/:platform/:status/playlists
start_date: string ISO date
end_date: string ISO date
stype: string streaming platform, choose from ‘spotify, ‘applemusic’, or ‘deezer’
status: string ‘current’ or ‘past’
status
indie: Boolean true if playlist created by major labels
indie
limit: int number of entries to be returned, maximum acceptable is 100
limit
A list of dictionaries of playlists for the album.
stats
Query the statistics from the given streaming platform, specifically popularity for Spotify.
https://api.chartmetric.com/api/album/:id/:platform/stats
stype: string streaming platform type, only ‘spotify’
start_date: string of start date in ISO format
end_date: string of end date in ISO format
A list of dictionaries of the statistics for an album on a streaming platform.
tracks
Query the tracks included in a given album.
https://api.chartmetric.com/api/album/:id/tracks
Parametrs
A list of dictionaries of the tracks in an album.
tunefind
Query the album tunefind stats given the Chartmetric ID.
https://api.chartmetric.com/api/album/:id/tunefind
A list of dictionaries of tunefind stats.
pycmc.artist.
albums
Get the albums for the artist given CMID.
https://api.chartmetric.com/api/artist/:id/albums
cmid: string or int Chartmetric artist ID
A dictionary of artist metatdata.
Get the given type of charts for the artist.
https://api.chartmetric.com/api/artist/:id/:type/charts
chart_type: string type of charts to pull, choose from’spotify_viral_daily’, ‘spotify_viral_weekly’,
chart_type
‘spotify_top_daily’, ‘spotify_top_weekly’, ‘applemusic_top’, ‘applemusic_daily’, ‘applemusic_albums’, ‘itunes_top’, ‘itunes_albums’, ‘shazam’, ‘beatport’ * cmid: string or int Chartmetric artist ID * start_date: string of start data in ISO format * end_date: string of end date in ISO format
A list of dictionaries of specific type of charts for the given artist.
cpp_data
Get the historical CPP data for the given artist.
https://api.chartmetric.com/api/artist/:id/cpp
cpp_stat: string CPP statistic to pull, choose from’rank’, ‘score’
cpp_stat
start_date: string of start data in ISO format
A list of dictionaries with the specific CPP statistics for the given artist.
fanmetrics
Query the Chartmetric API for artist fan metrics.
https://api.chartmetric.com/api/artist/:id/stat/:source
start_date: string ISO date %Y-%m-%d
end_date: string ISO date %Y-%m-%d
dsrc: string data source, choose from’spotify’, ‘facebook’, ‘twitter’, ‘instagram’,
dsrc
‘youtube_channel’, ‘wikipedia’, ‘bandsintown’, ‘soundcloud’ * valueCol: None or string specific data field returned, choose from’followers’, ‘popularity’, ‘listeners’, ‘talks’, ‘subscribers’
valueCol
A nested dict, {valueCol: [fanmetrics]}. Fanmetrics are dictionaries of time-series statistics.
{valueCol: [fanmetrics]}
get_artist_ids
Get all the linked artist IDs using a given type of ID.
https://api.chartmetric.com/api/artist/:type/:id/get-ids
id_type: string type of input ID, choose fromchartmetric’, ‘spotify’, ‘itunes’, ‘deezer’
specific_id: specific ID corresponding to the id_type
A list of dictionaries of linked artist IDs.
get_artists
Get the statistics of artists filtered by given metrics.
https://api.chartmetric.com/api/artist/:type/list
id_type: string indicating the field for filtering,’sp_monthly_listeners’ (spotify monthly listeners),
‘sp_followers’ (spotify followers), ‘sp_popularity’ (spotify popularity), ‘sp_listeners_to_followers_ratio’, ‘fs_likes’ (Facebook fan count), ‘fs_talks’ (Facebook people talking about count), ‘ycs_views’ (Youtube channel views), ‘ycs_subscribers’ (Youtube channel subscribers), ‘ws_views’ (Wikipedia pages views), ‘ss_followers’ (Soundcloud followers) * min_thres: minimum threshold for filtering * max_thres: maximum threshold for filtering * offset: number of offsets to shift the timeframe
min_thres
max_thres
offset
A list of dictionaries of the filtered artists.
listening
Query the Chartmetric API for Spotify’s WherePeopleListen stats.
https://api.chartmetric.com/api/artist/:id/where-people-listen
cmid: string or int chartmetric artist ID
start_date: string ISO start date for stats
A dictionary of top listening cities with stats.
Query the CHartmetric API for artist metadata.
https://api.chartmetric.com/api/artist/:id
Get the playlists containing the artist on the specific streaming platform.
https://api.chartmetric.com/api/artist/:id/:type/:status/playlists
dsrc: string data source, choose from’spotify’, ‘applemusic’, or ‘deezer’
status: string indicating status of pulled playlists,either ‘current’ or ‘past’
A list of dictionaries of playlists on the data source for the given artist.
related
Get the related artists for the given artist.
https://api.chartmetric.com/api/artist/:id/relatedartists
limit: int number of entries to be returned,maximum acceptable is 50
A list of dictionaries of related artists.
Get the tracks for the given artist.
https://api.chartmetric.com/api/artist/:id/tracks
A list of dictionaries of the artist’s tracks.
Query the Chartmetric API for artist tunefind data.
https://api.chartmetric.com/api/artist/:id/tunefind
A list of dictionaries of tunefind data for the given artist.
urls
Query the artist URL endpoint given the chartmetric ID and return the streaming/social/service URLs.
https://api.chartmetric.com/api/artist/:id/urls
A dictionary of various URLs for the artist.
from github.com/kennethreitz/background
pycmc.background.
callback
default_n
run
task
credentials
Utilities for the pycmc api credentials interface.
See credentials_manager for usage details.
credentials_manager
pycmc.credentials.
Check
Check that the CMCREDENTIALS environment variable is extant within the environment.
CMCREDENTIALS
It is important that this causes failure as early in the client init phase as possible. DefaultCredentials will throw if a refreshtoken is unavailable.
DefaultCredentials
refreshtoken
boolean True if CMCREDENTIALS exists AND the dictionary contains a non-empty string for the refreshtoken string, otherwise False.
boolean
True
False
Set the default (only refreshtoken) into the CMCREDENTIALS environment variable, warn the user and raise a KeyError exception.
KeyError
refreshtoken: the refresh token queried from the Chartmetric API
FetchAccessToken
Use the refreshtoken to fetch the access and other credentials from chartmetric.com.
A Python Requests response object in dictionary form with keys:
token,
token
expires_in,
expires_in
refresh_token,
refresh_token
scope.
scope
Raises for any non-200 response. See the Requests library documentation.
Load
Load the credentials from the environment and return the credentials dictionary.
dict of keys:
dict
scope,
refreshtoken.
PeriodicUpdate
Wrapper method to take a TTL variable, wait, and call UpdateCredentials. Current chartmetric api documentation (Feb-2019) indicates a credential refresh is required every 3600 seconds.
TTL_seconds integer seconds to wait between refreshes
TTL_seconds
repeat default: None; integer loops to repeat; -1 = inf
repeat
None
TTLwait
Update
Use the CMCREDENTIALS environment variable to make a HTTP GET request for the token, lifetime, and scope attributes and subsequently update the CMCREDENTIALS environment variable.
Varname
The set charmetric credentials environment variable name.
Credential manager for pycm. Load, store (globally), and automagically update credentials given response TTL seconds.
You probably shouldn’t do anything with this manually! All you need to do is set your CMCREDENTIALS environment variable to your JSON string of your Chartmetric API token.
>>> import credential_manager as cm >>> print(cm.token) >>> print(cm.refreshtoken) >>> print(cm.expires_in) # gives actual seconds to expiry as integer >>> print(cm.scope) Note: The ``expires_in`` global variable here IS NOT a string, as is required for the api queries; here it is the actual representative TTL count since our last refresh. **Don't forget to str(expires_in)** for API use.
pycmc.credentials_manager.
UpdateCredentials
TODO Write documentation here.
pycmc.curator.
lists
Get the chart of curators on the given streaming platfrorm.
https://api.chartmetric.com/api/curator/:platform/lists
stype: string streaming platform, choose from’spotify’, ‘applemusic’, or ‘deezer’
limit: int number of entries returned; maximum acceptable is 100
offset: int offset of entries returned
indie: boolean True to return the charts not curated by major labels
social: boolean True to return social url data
social
A Python list of dictionaries of curators.
Get the metadata for the curator on a given streaming platform.
https://api.chartmetric.com/api/curator/:platform/:id/
cmid: string or int Chartmetric curator ID
stype: string streaming platform, choose from’spotify’, ‘applemusic’, ‘deezer’
A dictionary of curator metadata.
Get the playlists by the curator on the given streaming platform.
https://api.chartmetric.com/api/curator/:platform/:id/playlists
cmid: string or in Chartmetric curator ID
A Python list of dictionaries of playlist by the curator
pycmc.playlist.
evolution
Get the playlist evolution stats, given artist, album or track CMID.
https://api.chartmetric.com/api/playlist/by/:type/:id/playlist-evolution
cmid: string Chartmetric {byType} ID
byType: string type of evolution stats requested, choose from’artist’, ‘track’, ‘album’
byType
A nested dict, keys being
‘playlistDataPerDate’ (dicts indexed by dates),
‘statsDataPlot’ (list of lists)
‘playlistDataPlot’ (list of lists)
Get the list of playlists, given the streaming platform.
https://api.chartmetric.com/api/playlist/:streamingType/lists
stype: string streaming platform, choose from’spotify’, ‘applemusic’, ‘deezer’ or ‘amazon’
sort: string column to sort the playlists by, e.g. ‘followers’, ‘last_updated’
sort
country: string country code
country
limit: int number of playlists to return,maximum acceptable is 100
offset: offset of entries to be returned
indie: boolean True to return indie playlists
A list of dicts of playlists.
Get the metadata for the playlist on streaming platform given CMID.
https://api.chartmetric.com/api/playlist/:platform/:id
cmid: string or int Chartmetric playlist ID
A dictionary of playlist metadata.
snapshot
Get the snapshot of all tracks in a playlist given CMID on a given streaming platform for a given date.
https://api.chartmetric.com/api/playlist/:platform/:id/snapshot
date: string date in ISO format %Y-%m-%d
date
A list of dictionaries of tracks contained in the playlist.
Get the current or past tracks contained in a playlist given CMID on a given streaming platform.
https://api.chartmetric.com/api/playlist/:platform/:id/:span/tracks
span: string ‘past’ or ‘current’
span
pycmc.track.
Get the charts of certain type containing this given track since a specified start date.
https://api.chartmetric.com/api/track/:id/:type/charts
chart_type: string type of chart, choose from’spotify_viral_daily’, ‘spotify_viral_weekly’,
‘spotify_top_daily’, ‘spotify_top_weekly’, ‘applemusic_top’, ‘applemusic_daily’, ‘applemusic_albums’, ‘itunes_top’, ‘amazon’, ‘itunes_albums’, ‘shazam’, ‘beatport’ * cm_track_id: string or int Chartmetric track ID * start_date: string ISO date * end_date: string ISO date
cm_track_id
A list of dictionaries of the charts data.
get_track_ids
Get all related track IDs for a given track by a specific ID. There can be multiple corresponding Spotify and iTunes IDs for some tracks.
https://api.chartmetric.com/api/track/:type/:id/get-ids
id_type: string type of track ID,’chartmetric’ (for cm_track), ‘isrc’,
‘spotify’, ‘itunes’ * matching_id: specific track ID that matches the type
matching_id
A list of dictionaries of the related track IDs.
Get the metadata for the track given CMID.
https://api.chartmetric.com/api/track/:id
cmid: string or int Chartmetric track ID
dictionary of track metadata
playlist_snapshot
Get the snapshot of playlists on the platform containing the track for a given date.
https://api.chartmetric.com/api/track/:id/:platform/playlists/snapshot
platform: string ‘spotify’, ‘applemusic’, ‘deezer’
platform
date: string ISO date
limit: int number of entries to be returned; maximum acceptable is 100
offset: int offset of entries to be returned
A list of dictionaries of playlists data.
Get the current or past playlists containing the track on the given streaming platform.
https://api.chartmetric.com/api/track/:id/:platform/:status/playlists
platform: string ‘spotify’, ‘applemusic’, ‘deezer’, ‘amazon’
status: string ‘past’ or ‘current’
start_date: string ISO start date
end_date: string ISO end date, default today
indie: bool, False for playlist curated by major label
offset: int offset of entries, use this to recursively acquire
Get the value time-series for the given track on the given platform. Specifically, get popularity for Spotify, views for YouTube and count for Shazam.
https://api.chartmetric.com/api/track/:id/:platform/stats
cm_track_id: string or int Chartmetric track ID
platform: string of streaming platform, choose from’spotify’, ‘youtube’, ‘shazam’
start_date: string date in ISO format
end_date: string date in ISO format, default is today
A list of dictionaries of the track value stats time-series.
Get the Tunefind stats given the track.
https://api.chartmetric.com/api/track/:id/tunefind
A list of dictionaries of Tunefind data.
utilities.py
Utilities for the pycmc api interface.
pycmc.utilities.
BaseURL
FindProcess
Return a list of processes matching given name.
name: string process name
name
list of items matching process ‘name’
ProjectRootDir
Return path to root directory of project with trailing slash.
string path with trailing /
RequestData
Build chartmetric data object and call requests.get with constructed data.
urlhandle: string additional url after base
urlhandle
with a leading and without ending slash * params: dictionary of keyword data to send in the query string, specific to the particular api endpoint
params
A dictionary with keys url, headers and params.
RequestGet
Method to call requests.get with data.
data: dictionary with at least the followingkey:value pairs: url, headers, params
data
A dictionary of request data.
Utility waiting function for the credentials.PeriodicUpdate method.
func: function PeriodicUpdate from the credentials.py module
func
credentials.PeriodicUpdate method instantiation
strDateToday
Simple method to return the string date of today as given by the datetime module.
Specifically, a string is returned in ISO Year-Month-Day format.
A Python str representing the ISO date.
str
strWeekday
Given a ISO string date return the nearest target weekday.
target
date: The date around which the caller would like target searched.
target: Weekday number as in the datetime Standard Library Module.
datetime
The ISO YYYY-MM-DD string representation of the nearest given weekday.