Usage¶
Calling API methods¶
There are two ways of calling Ipernity API methods:
The
call()method.The “method property” scheme.
The difference is best shown in an example:
ip = IpernityAPI(key, secret)
# These two calls are equivalent
user_info = ip.call('user.get', userid = 4711)
user_info = ip.user.get(userid = 4711)
Note
All parameters should be passed as keyword arguments.
The response (here:
user_info) is the complete parsed JSON that the API call returns. See Ipernity API output formats for more information.The
api_keyparameter is specified in the constructor ofIpernityAPIand should not be specified in API calls.Requests are automatically signed by PyIpernity.
Iterating over search results¶
PyIpernity provides special methods to iterate smoothly over results that are distributed as multiple “pages”. These generators are:
walk_albums()Iterates over a user’s albums.
walk_album_docs()Iterates over documents in an album.
walk_doc_search()Iterates over the result of a document search.
walk_docs()Iterates over a user’s documents.
walk_data()Generic method, called by the other
walk_*methods.
Interactive mode¶
Added in version 0.3.0.
PyIpernity provides an interactive mode for testing. To get information about the command line options, type
$ python -m ipernity -h
at the shell prompt. If application key and secret are specified in environment variables or a configuration file, you can just start interactive mode with
$ python -m ipernity
Specifying key, secret and token¶
There are three ways to specify the authentication information (in order of precedence):
Command line arguments:
$ python -m ipernity -k <api-key> -s <api-secret> -t <api-token>
Configuration file (default
$HOME/.ipernity.ini):[ipernity] api key = <api-key> api secret = <api-secret> api token = <api-token>
Environment variables:
IPERNITY_API_KEY=<api-key> IPERNITY_API_SECRET=<api-secret> IPERNITY_API_TOKEN=<api-token>
Specifying the token is optional. Some API methods can be called without a
token, and you can get a token with the login command.