一个蟒蛇接口
pylast的Python项目详细描述
Pylast
与Last.fm和其他api兼容网站(如Libre.fm)的python接口。
使用pydoc实用程序获得用法帮助,或参见tests/获取示例。
安装
通过PIP安装:
pip install pylast
安装最新的开发版本:
pip install -U git+https://github.com/pylast/pylast
或从requirements.txt:
-e git://github.com/pylast/pylast.git#egg=pylast
注意:
- pylast 3.0.0+支持python3.5+(#265)
- pylast 2.2.0-2.4.0支持python2.7.10+、3.4、3.5、3.6、3.7。
- pylast 2.0.0-2.1.0支持python2.7.10+、3.4、3.5、3.6。
- Pylast 1.7.0-1.9.0支持Python2.7、3.3、3.4、3.5、3.6。
- Pylast 1.0.0-1.6.0支持Python2.7、3.3和3.4。
- pylast 0.5支持python 2,3。
- pylast<;0.5支持python 2。
功能
- 简单的公共接口。
- 访问last.fm web服务公开的所有数据。
- 四处寻找支持。
- 全面向对象设计。
- 代理支持。
- 对某些Web服务调用的内部缓存支持(默认情况下禁用)。
- 支持其他与API兼容的网络,如libre.fm。
- python 3友好(从0.5开始)。
开始
下面是一些简单的代码示例。为了从pylast创建任何对象,您需要一个Network
对象,该对象表示last.fm或任何其他api兼容的社交音乐网络。您可以为last.fm获得一个预先配置的,并按如下方式使用:
importpylast# You have to have your own unique two values for API_KEY and API_SECRET# Obtain yours from https://www.last.fm/api/account/create for Last.fmAPI_KEY="b25b959554ed76058ac220b7b2e0a026"# this is a sample keyAPI_SECRET="425b55975eed76058ac220b7b4e8a054"# In order to perform a write operation you need to authenticate yourselfusername="your_user_name"password_hash=pylast.md5("your_password")network=pylast.LastFMNetwork(api_key=API_KEY,api_secret=API_SECRET,username=username,password_hash=password_hash)# Now you can use that object everywhereartist=network.get_artist("System of a Down")artist.shout("<3")track=network.get_track("Iron Maiden","The Nomad")track.love()track.add_tags(("awesome","favorite"))# Type help(pylast.LastFMNetwork) or help(pylast) in a Python interpreter# to get more help about anything and see examples of how it works
hugovk/lastfm-tools和tests/中的更多示例。
测试
tests/目录包含与last.fm的集成和单元测试,以及大量代码示例。
对于集成测试,您需要在last.fm上有一个测试帐户,该帐户将与测试数据和一个api密钥和秘密混杂在一起。复制example_test_pylast.yaml以测试pylast.yaml并填写凭据,或者将它们设置为环境变量,如:
exportPYLAST_USERNAME=TODO_ENTER_YOURS_HERE exportPYLAST_PASSWORD_HASH=TODO_ENTER_YOURS_HERE exportPYLAST_API_KEY=TODO_ENTER_YOURS_HERE exportPYLAST_API_SECRET=TODO_ENTER_YOURS_HERE
运行所有单元和集成测试:
pip install pytest flaky mock pytest
或者只运行一个测试用例:
pytest -k test_scrobble
在覆盖范围内运行:
pytest -v --cov pylast --cov-report term-missing coverage report # for command-line report coverage html # for HTML report open htmlcov/index.html
日志记录
从您自己的代码启用:
importloggingimportpylastlogging.basicConfig(level=logging.DEBUG)network=pylast.LastFMNetwork(...)
从pytest启用:
pytest --log-cli-level debug -k test_album_search_images