Package: phishnetpy
phishnetpyphishnetpy is a Python client for thePhish.net
API. It works with either Python 2 or 3 and
supports all of the endpoints provided by api.phish.net.InstallationYou guessed it…pip install phishnetpyGetting StartedAs you browse thePhish.net API
documentationyou will see that some API
methods are labeled as “protected”. This means that in order to use
those methods, you must generate an Application Key. To allow both
public and protected usage, there are several setup steps you have to
complete.Public API MethodsFor “public” or “unprotected” API calls, you simply need to instantiate
the PhishNetAPI class, and call the methods for each of the API methods.>>>fromphishnetpyimportPhishNetAPI>>>phishnet=PhishNetAPI()>>>artists=phishnet.artists_get()>>>artists[{'artist':'Phish','slug':'phish','artistid':'1'},{'artist':'Trey Anastasio','slug':'trey-anastasio-band','artistid':'2'},{'artist':'Mike Gordon','slug':'mike-gordon','artistid':'6'},{'artist':'Jon Fishman','slug':'jon-fishman','artistid':'7'},{'artist':'Page McConnell','slug':'page-mcconnell','artistid':'9'}]Attempting to call protected methods without passing in an API key into
the constructor will raisephishnetpy.exceptions.AuthError.>>>phishnet.user_username_check("wilson")Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"./phishnetpy/phishnetpy/decorators.py",line16,inwrapperraiseAuthError("{}requires an API key".format(qual_name_safe(f)))phishnetpy.exceptions.AuthError:PhishNetAPI.user_username_checkrequiresanAPIkeyProtected API MethodsIn order to collect “protected” API methods, you must pass an API key
into the constuctor.>>>fromphishnetpyimportPhishNetAPI>>>my_api_key="<MY API KEY>"# Private API key from http://api.phish.net/keys/>>>phishnet=PhishNetAPI(api_key=my_api_key)>>>phishnet.user_username_check("wilson"){'success':'0','reason':'Sorry! wilson is already taken.'}Methods requiring user authorizationSome protected methods additionally require an auth_key to take actions
on behalf of specific users. This includes submitting reviews, forum
threads, or adding a show to “My Shows”.phishnetpy can make generating auth codes simpler by adding some logic
on top of thepnet.api.*API methods.The simplest way is probably by using theauthorizemethod. In order
to make this method work, you will need both the username and password
of the user you are authorizing (at least the first time).>>>fromphishnetpyimportPhishNetAPI>>>my_api_key="<MY API KEY>"# Private API key from http://api.phish.net/keys/>>>phishnet=PhishNetAPI(api_key=my_api_key)>>>phishnet.authorize('authorized_username','that_users_password')If unsuccessful, thephishnetpy.exceptions.AuthErrorwill be raised.
If successful, the authorized username and auth key will be stored as
attributes on the instance you’re working with.>>>phishnet.username'authorized_username'>>>phishnet.auth_key'ABCD123456789012345'Once those attributes have been set, you can make user-authorized API
calls. For example, lets add, and then removeHalloween
2014to my shows.>>>len(phishnet.user_myshows_get_authorized())7>>>phishnet.user_myshows_add('2014-10-31'){'success':1}>>>len(phishnet.user_myshows_get_authorized())8>>>phishnet.user_myshows_remove('2014-10-31'){'success':1}>>>len(phishnet.user_myshows_get_authorized())7Once authorized, you should not store the user’s password (per the
Phish.net terms).