Skip to main content

A Python API wrapper for interacting with Knack applications.

Project description

Knackpy

A Python client for interacting with Knack applications.

Installation

Knackpy requires Python v3.6+.

pip install knackpy

Features

  • Object and view-based requests
  • Filters
  • Parsing of fieldnames and field labels
  • Create and update records
  • CSV output
  • File downloads

Quick Start

Get data from a Knack view.

>>> from knackpy import Knack

>>> kn = Knack(
      scene='scene_34',
      view='view_10',
      app_id='abc123'
    )

>>> kn.data_raw
[{'field_1': 30424, 'field_1_raw': 30424, 'field_2': '11/18/2016'},...]

Provide a list of the view's reference objects to return humanized field names.

>>> kn = Knack(
      scene='scene_34',
      view='view_10',
      ref_obj=['object_1', 'object_2'],
      app_id='myappid',
      api_key='topsecretapikey'
    )

>>> kn.data
[{'store_id': 30424, 'inspection_date': 1479448800000, 'id': '58598262bcb3437b51194040'},...]

Or retrieve data directly from an object.

>>> kn = Knack(
      obj='object_1',
      app_id='abc123',
      api_key='topsecretapikey'
    )

>>> kn.data
[{'store_id': 30424, 'inspection_date': 1479448800000, 'id': '58598262bcb3437b51194040'},...]

You can also pass a filter to your object-based requests.

>>> filters = {
      'match': 'and',
      'rules': [
        {
          'field':'field_10',
          'operator':'is',
          'value':'No'
        },
        {
          'field':'field_11',
          'operator':'is',
          'value':'Yes'
        }
      ]
    }

>>> kn = Knack(
      obj='object_1',
      app_id='abc123',
      api_key='topsecretapikey',
      filters=filters
    )

Field metadata is available when working with objects or when reference objects have been specified.

>>> kn.fields
{'field_1': {' ': 'store_id', 'key': 'field_1,required': False, 'type': 'auto_increment'},...}

>>> kn.fieldnames
['store_id', 'inspection_date', 'store_status',...]

>>> kn.field_map
{'store_id' : 'field_1', 'store_status' : 'field_2',...}

You can download files for the records you retrieve from a view. Files are overwritten by default:

 >>> kn.download(overwrite=False) # Writes all new files to `_downloads` directory

>>> kn.download(
  destination="my_downloads", # Overwrites existing files in `my_downloads` directory
  label_fields=["Attachment ID"], # Prepends the "Attachment ID" value to the filename
  download_fields=["Photo", "Document"] # downloads files from these specific fields only
)

Write an instance to csv.

>>> kn.to_csv('data.csv')
"store_id","inspection_date","store_status"
"30424","11-18-2016","OPEN"
"30200","10-01-2013","CLOSED"
...

Create a new record.

>>> import knackpy

>>> record = {'field_1': 30424}

>>> response = knackpy.record(
      record,
      obj_key='object_12',
      api_id='myappid',
      api_key='topsecretapikey',
      method='create'
    )

{ 'id':'6a204bd89f3c8348afd5c77c717a097a', field_1': 30424, ...}

Update a record.

>>> import knackpy

>>> record = {'id':'6a204bd89f3c8348afd5c77c717a097a','field_1': 2049}

>>> response = knackpy.record(
      record,
      obj_key='object_12',
      app_id='myappid',
      api_key='topsecretapikey',
      method='update'
    )

{ 'id':'6a204bd89f3c8348afd5c77c717a097a', field_1': 2049, ...}

Get an app's configuration data (objects, scenes, etc.)

>>> from knackpy import get_app_data

>>> my_app = get_app_data('myAppIdString')

>>> my_app['name']

'John's Amazing App'

License

As a work of the City of Austin, this project is in the public domain within the United States.

Additionally, we waive copyright and related rights of the work worldwide through the CC0 1.0 Universal public domain dedication.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

knackpy-0.0.13-py2.py3-none-any.whl (9.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file knackpy-0.0.13-py2.py3-none-any.whl.

File metadata

  • Download URL: knackpy-0.0.13-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.22.0 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.1 CPython/3.6.4

File hashes

Hashes for knackpy-0.0.13-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d5573e02bf604f82fcf0cdcdb85b601d86e87a540b12bc0abda07e7747430ecd
MD5 89860b3a6733564cc835eae956aaef8b
BLAKE2b-256 cca4ef6c3a63158ba5b0aa7d0117b781fe8fec961a832ece23c0cb0ff49feb5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page