knackpy.app #
App Objects #
class App()
Knackpy is designed around the App class. It provides helpers for querying
and manipulating Knack application data. You should use the App class
because:
- It allows you to query obejcts and views by key or name
- It takes care of localization issues # noqa:E501
- It let’s you download and upload files from your app.
- It does other things, too.
Arguments:
app_idstr - Knack application ID # noqa:E501 string.api_keystr, optional, default=None- Knack API key.metadatadict, optional - The Knack app’s metadata as adict. IfNoneit will be fetched on init. You can find your apps metadata here.tzinfopytz.Timezone, optional - [description]. A pytz.Timezone object. WhenNone, is set automatically based on the app’smetadadata.max_attemptsint - The maximum number of attempts to make if a request times out. Default values that are set inknackpy.api.request.timeoutint, optional - Number of seconds to wait before a Knack API request times out. Further reading: Requests docs.
info #
def info()
Returns a dict of basic app information:
- Number of objects
- Number of scenes
- Number of records
- Number total file size
get #
def get(identifier: str = None,
refresh: bool = False,
record_limit: int = None,
filters: typing.Union[dict, list] = None,
generate=False)
Get records from a knack object or view.
Note that we accept the request params record_limit and filters here
because the user would presumably want to set these on a per-object/view
basis. They are not stored in state. Whereas max_attempts and
timeout are set on App construction and persist in App state.
Arguments:
identifierstr, optional* - an object or view key or name string that exists in the app. If None is provided and only one container has been fetched, will return records from that container.refreshbool, optional - Force the re-querying of data from Knack API. Defaults to False.record_limitint - the maximum number of records to retrieve. IfNone, will return all records.filtersdict or list, optional - A dict or list of Knack API filters.See- https://www.knack.com/developer-documentation/`filters`.generatebool, optional - If True, will return a generator which yields knacky.Record objects instead of return a list of of them.
Returns:
A generator which yields knackpy Record objects.
to_csv #
def to_csv(identifier: str,
*,
out_dir: str = "_csv",
delimiter=",",
record_limit: int = None,
filters: typing.Union[dict, list] = None) -> None
Write formatted Knack records to CSV.
Arguments:
identifierstr - an object or view key or name string that exists in the app.out_dirstr, optional - Relative path to the directory to which files will be written. Defaults to “_csv”.delimiterstr, optional - [description]. Defaults to “,”.record_limitint - the maximum number of records to retrieve. IfNone, will return all records.filtersdict or list, optional - A dict or of Knack API filiters.See- https://www.knack.com/developer-documentation/`filters`.
download #
def download(*,
container: str,
field: str,
out_dir: str = "_downloads",
label_keys: list = None)
Download files and images from Knack records.
Arguments:
containerstr - The name or key of the object from which files will be downloaded.out_dirstr, optional - Relative path to the directory to which files will be written. Defaults to “_downloads”.fieldstr - The Knack field key of the file or image field to be downloaded.label_keyslist, optional - A list of field keys whose values will be prepended to the attachment filename, separated by an underscore.
Returns:
[int]- Count of files downloaded.
record #
def record(*, data: dict, method: str, obj: str)
Create, update, or delete a Knack record.
Arguments:
datadict - The Knack record data payload.methodstr - Choose fromcreate,update, ordelete.objstr, optional - The Knack object key or name which holds the record data.
Returns:
dict- The updated or newly created Knack record data, or, if deleting arecord-{"delete": true}
upload #
def upload(*,
container: str,
field: str,
path: str,
asset_type: str,
record_id: str = None)
Upload a file or image to Knack. This is a two-step process:
- Upload file asset to Knack storage
- Create/update a record that links to the file in storage
Knack docs: https://www.knack.com/developer-documentation/`file`-image-uploads
Arguments:
containerstr - The name or key of the object from which files will be downloaded.fieldstr - The knack field key of the field you’re uploading into.pathstr - The path to the file to be uploaded.asset_typestr - The type of Knack field you’re uploading to. Must befileorimage.record_idstr, optional - The knack record ID to which the upload will be attached. IfNone, will create a new record. Otherwise will update an existing record.