Package: pycmc
pycmcPython Chartmetric ClientA Python client for the Chartmetric API. Query artists, their music,
and where their fans listen, byMusicfox.And do it all in Python.InstallationWe highly recommend you installpycmcinto some type ofvirtual environment.Then you should use pip or the like:pipinstallpycmcorpipenvinstallpycmc# latest releaseUsingPipenvyou may need to pin the version, unless you allow for pre-releases. We don't have a beta or alpha qualifier but view this software
as such.And don't forget you need an API subscription and subsequently, auth keys for Chartmetric --see below.⚠Remember: You're not done yet; you'll need to set an authentication environment variable for queries.Quick startIf you're already setup with your environment variable, you can query Rihanna's metadata with a quick call to theartistmodule:>>>importpycmc>>>rihanna_metadata=pycmc.artist.metadata(cmid=2316)Yep, it's that simple."You should remember that it's peace of mind you're after and not just a fixed machine."-- Robert Pirsig, via PhaedrusAuthenticationChartmetric requires an authorization process to query their API. You can
see theirdocs here.Add theCMCREDENTIALSenvironment variableForpycmcyou need to set a single
environment variable,CMCREDENTIALS, to equal your JSON authentication string of the following:{"token":"","scope":"","expires_in":"","refreshtoken":"your-chartmetric-token-here",}🔎Be sure the above is astringwhen you set your environment variable.How to set uppycmcauthenticationSave the JSON file above to disk and note the absolute directory.Using your absolute directory below,# REQUIRED - Set your environment variableexportCMCREDENTIALS=$(catpath/to/credentials/file.json)# OPTIONAL - Remove the .json file you createdrm-rfpath/to/credentials/file.jsonDesignTo somewhat follow the API design of chartmetric and make our lives easier here,
we'll roughly adhere to the following module design where thepycmcpackage
contains the following modules:albumartistchartscuratorplaylisttrackcredentialscredentials_managerutilitiesEach module above provides (most) methods for a specific endpoint
to the chartmetric.com API, (mostly) labelled as their GET endpoints.For example,>>>'API ALBUM META URL'='https://api.charmetric.io/api/album/:id'Album MetadataTo get an album's metadata just call the metadata function:>>> import pycmc
>>> pycmc.album.metadata('chartmetricID') # return dict of album metatdataSpotify top chartsObviously we'll start with the elephant in the room and get the top
charts from Spotify.What was the US jamming to on the first day of the new year?>>> cstracks = pycmc.charts.spotify.tracks(date='2019-01-01', )Apple Music videos chartsWhat videos are charting in Apple Music on the same day as above?>>> applemusic_vcharts = pycmc.charts.itunes.videos(date='2019-01-01')Track metatdataLet's get some metadata on the trackBelieve Itby PARTYNEXTDOOR and Rihanna:>>> believe_it = pycmc.track.metadata(cmid='28856569', )Reference DocumentationWe have hosted documentation over at our docs sitepycmc.docs.musicfox.io, which review the many endpoints offered by
the Chartmetric API.Problems? Ideas?We'd love to hear your feedback. Please use the Github for communication aboutpycmc.🐛 Bug Reports 🐞Please report bugs or problems in ourissuesin the Github repository.🍨 Feature RequestsIf you have an idea for a feature or suggestion, please open an issue the Github repository. Please describewhatyou're trying to
accomplish and your idea to fix it withpycmc. We'll work through next steps on our end, or together if you'd like to contribute.Contibutions topycmcContributions are quite welcome and it's very easy to get started.We ❤ community contributions!Do note, we do require a contributor license agreement such
that contributors' contributions are protected property, outside of the
"open-source" MIT license covering code here.Please see ourCONTRIBUTING.mdto get started.pycmcdevelopmentEnvironment setupCreate an.envfile in the application directory:touch pycmc/.envand populate with:exportCMCREDENTIALS="your-key"Jump into your dev shell:pipenvshellAnd populate your environment:sourcepycmc/.env🎉 🎸 You're ready to rock! 🎸 🎉Running the test suiteYou'll obviously need to have an API key for Chartmetric to run tests.ℹ️ The test suite is slowed to ~6s per request to the Chartmetric
API to protect production usage of the same keys, likely an issue (which we've handled herein) since
the API is rate limited.️Run testspytest--cov=pycmctestsUpload to the coverage tracker manuallyFirst, DM@thinkjrsfor the codecov token, which you'll need
to set below.Coverage is typically updated automagically but if you need to manually generate the coverage onhttps://codecov.io/gh/musicfox/pycmc, run:exportCODECOV_TOKEN="token-from-@thinkjrs"./upload_coverage.bashfrom your bash shell after running tests.CI/CD on GCPpycmchas a runner that builds a Python container, runs tests, and builds
the documentation site when new commits are pushed. As of December 2020 this is private
within the Musicfox Google Cloud Platform account.Currently, you can track these builds in the action platform after you've been
given access to the repo.Coming soon! We are planning to migrate to another
solution in the near future along with full tox-support (multiple python package build tests).