Module ipernity.api¶
Ipernity API Class¶
All funcionality in PyIpernity is available through the IpernityAPI
class.
- class ipernity.api.IpernityAPI(api_key: str, api_secret: str, token: str | Mapping | None = None, auth: str | AuthHandler = 'desktop', url: str = 'https://api.ipernity.com/api/', auth_url_base: str = 'https://www.ipernity.com/apps/authorize')[source]¶
Bases:
objectEncapsulates Ipernity functionality.
See Calling API methods for access to the individual API methods.
- Parameters:
api_key – The API key obtained from Ipernity.
api_secret – The secret belonging to the API key.
token – API token. Can be given as a string or as a mapping. When given as a mapping, the actual token is extracted as
token['token'],token['user']is stored as user information (seeuser_info), andtoken['permissions']is stored aspermissions. The format of the mapping should be like the return data of [auth.getToken].auth – Authentication methop, can be
desktop,webor a subclass ofAuthHandler(not an instance thereof!). The authentication handler is set accordingly.url – API URL, should normally be left alone.
auth_url_base – Base for Authentication URLs, should normally be left alone.
See also
Changed in version 0.3.1: * New argument
auth_url_base* URLs default to HTTPSChanged in version 0.3.0:
authcan be a subclass ofAuthHandler.- property auth: AuthHandler¶
The authentication handler
- property api_key: str¶
The API key generated by Ipernity
Assigning a new value will set
tokento None.Added in version 0.3.0.
- property api_secret: str¶
The API secret generated by Ipernity
Assigning a new value will set
tokento None.Added in version 0.3.0.
- property token: str¶
The authentication token
When setting, the new value can be given as a string or as
dict. If given as a dict, the actual token is extracted astoken['token'].
- property user_info: dict | None¶
Information about the current user
- property permissions: dict | None¶
Information about the current permissions
Added in version 0.1.5.
- has_permissions(permissions: Mapping[str, str] | None) bool[source]¶
Checks if the API has at least the given permissions.
Returns False if the token is
None.Added in version 0.1.5.
- call(method_name: str, **kwargs: api_arg) dict[source]¶
Makes an API call.
- Parameters:
method_name – API method to call
kwargs – API arguments
- Raises:
UnknownMethod – Tried to call a method not contained in [api.methods.getList].
APIRequestError – The API call returned an error, or the HTTP request failed.
Changed in version 0.2.0: An HTTP error raises
APIRequestErrorinstead ofHTTPError.
- upload_file(filename: str, **kwargs: api_arg) str[source]¶
Simplified interface to uploading a file
- Parameters:
filename – The file to be uploaded. Can be relative or absolute.
kwargs – Additional attributes for [upload.file].
- Returns:
The
doc_idof the uploaded file.- Raises:
UploadError – The ticket gets invalid.
- walk_data(method_name: str, elem_name: str | None = None, **kwargs: api_arg) Iterable[dict][source]¶
Iterates over an arbitrary API search/list.
walk_dataguesses the structure of the returned JSON object from the API method used. If this does not work, theelem_nameargument can be given to specify the object keys:If
elem_namecontains dots, the last part is taken to be the innermost key that points to the list of elements to iterate over, while the preceding parts specify the outer keys.If
elem_namedoes not contain dots, the returned JSON is assumed to contain a key “elem_name``+s" pointing to an object that contains a key "``elem_name” that contains the list of results.
- Parameters:
method_name – Search method to call. The method must accept the
pageargument.elem_name – Name of list elements.
kwargs – Argument for the search method. Use
per_pageto set the number of returned elements per method call.
- Yields:
dictcontaining the element data.
- walk_albums(**kwargs: api_arg) Iterable[dict][source]¶
Iterates over a user’s albums.
See the album.getList documentation for possible arguments.
- walk_album_docs(album_id: int, **kwargs: api_arg) Iterable[dict][source]¶
Iterates over the documents of an album.
See the album.docs.getList documentation for optional arguments.
- Parameters:
album_id – The album’s ID.
kwargs – Additional arguments for [album.docs.getList]
- walk_doc_search(**kwargs: api_arg) Iterable[dict][source]¶
Iterates over a search result.
See the doc.search documentation for possible arguments.
- walk_docs(**kwargs: api_arg) Iterable[dict][source]¶
Iterates over a user’s documents.
See the doc.getList documentation for possible arguments.
- walk_folders(**kwargs: api_arg) Iterable[dict][source]¶
Iterates over a user’s folders.
See the folder.getList documentation for possible arguments.
- walk_folder_albums(folder_id: int, **kwargs: api_arg) Iterable[dict][source]¶
Iterates over the albums of a folder.
See the folder.albums.getList documentation for optional arguments.
- Parameters:
folder_id – The folder’s ID.
kwargs – Additional arguments for [folder.albums.getList]