Skip to main content

Interact with KnackHQ API

Project description

# knackhq

Python wrapper for [KnackHQ API](http://knackhq.com/)

<img src="https://travis-ci.org/amancevice/knackhq.svg?branch=master"/>


## Installation

```bash
pip install knackhq
```


## Connect to KnackHQ

Create a `KnackHQClient` instance to begin interacting with KnackHQ. Supply an app ID, an API key, and an optional API endpoint URL to the client. Alternatively, set these values in your environment with:

* `KNACKHQ_APP_ID`
* `KNACKHQ_API_KEY`
* `KNACKHQ_ENDPOINT`

```python
import knackhq

# KNACKHQ_APP_ID = <set in ENV>
# KNACKHQ_API_KEY = <set in ENV>
# KNACKHQ_ENDPOINT = <set in ENV>

client = knackhq.KnackHQClient()
```


## Reading from KnackHQ


### Raw requests

In some cases you may wish to send a raw HTTP request to the KnackHQ JSON API. This will not normally be necessary but it is available:

```python
client.request("https://api.knackhq.com/v1/objects/object_1", 'GET')
client.request("https://api.knackhq.com/v1/objects/object_1", 'POST', body='{key: val}')
```


### Reading Objects

Iterate over objects in an app using the `client` object:

```python
for obj in client:
print obj

# => <KnackHQObject /v1/objects/object_1>
# <KnackHQObject /v1/objects/object_2>
# <KnackHQObject /v1/objects/object_3>
# ...
# <KnackHQObject /v1/objects/object_n>
```

Or, find an object by its key:

```python
obj = client.get_object('object_1')
```

If you are unsure of the key, use the `name` keyword argument to get the object by its name:

```python
obj = client.get_object(name='Customers')
```

Find metadata keys using the `keys()` function. Get metadata on an object using brackets (`[]`):

```python
obj.keys()

# => ['status',
# 'tasks',
# 'name',
# 'inflections',
# 'fields',
# 'connections',
# 'user',
# 'key',
# '_id']

obj['key']

# => 'object_1'
```


### Reading Records

Iterate over records in an object:

```python
for record in obj:
print record

# => <KnackHQRecord /v1/objects/object_1/records/...>
# <KnackHQRecord /v1/objects/object_2/records/...>
# <KnackHQRecord /v1/objects/object_3/records/...>
# ...
# <KnackHQRecord /v1/objects/object_n/records/...>
```

Use the `where()` function to filter records. Where accepts the following keyword-arguments:

* `record_id`
* `page`
* `rows_per_page`
* `sort_field`
* `sort_order`
* `filters`

If `record_id` is provided (and the record exists) `where(record_id=<id>)` will yield a collection of length 1.

Use `filters` to refine your search:

```python
filters = [
{
field: 'field_1',
operator: 'is',
value: 'test'
}, {
field: 'field_2',
operator: 'is not blank'
}
]

for record in obj.where(filters=filters):
print record

# => <KnackHQRecord /v1/objects/object_1/records/...>
# <KnackHQRecord /v1/objects/object_2/records/...>
# <KnackHQRecord /v1/objects/object_3/records/...>
# ...
# <KnackHQRecord /v1/objects/object_n/records/...>
```


## Writing to KnackHQ

*TODO*

Project details


Download files

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

Source Distribution

knackhq-0.0.3.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file knackhq-0.0.3.tar.gz.

File metadata

  • Download URL: knackhq-0.0.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for knackhq-0.0.3.tar.gz
Algorithm Hash digest
SHA256 bb38f954e302f9b681225d720f65a97697fab17f42c5c1d94fa9cd05b1c56e7e
MD5 4cb01d10e68c9aa851c0b4b7fafb6903
BLAKE2b-256 ac369f316b2fdf04ba58ee891edf36881239dfb6e76517f69a5420978cb664a6

See more details on using hashes here.

Supported by

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