Skip to main content

Client library for the Knock API

Project description

Knock Python library

Knock API access for applications written in Python.

Documentation

See the documentation for Python usage examples.

Installation

To install from PyPi, run the following:

pip install knockapi

To install from source, clone the repo and run the following:

python setup.py install

Configuration

To use the library you must provide a secret API key, provided in the Knock dashboard.

from knockapi import Knock
client = Knock(api_key="sk_12345")

Usage

Identifying users

from knockapi import Knock
client = Knock(api_key="sk_12345")

client.users.identify(id="jhammond", data={"name": "John Hammond", "email": "jhammond@ingen.net"})

Retrieving users

from knockapi import Knock
client = Knock(api_key="sk_12345")

client.users.get_user(id="jhammond")

Sending notifies

from knockapi import Knock
client = Knock(api_key="sk_12345")

client.notify(
  key="dinosaurs-loose",
  actor="dnedry",
  recipients=["jhammond", "agrant", "imalcolm", "esattler"],
  cancellation_key=alert.id,
  tenant="jurassic-park",
  data={
    "type": "trex",
    "priority": 1
  }
)

Canceling notifies

from knockapi import Knock
client = Knock(api_key="sk_12345")

client.workflows.cancel(
  key="dinosaurs-loose",
  cancellation_key=alert.id,
  recipients=["jhammond", "agrant", "imalcolm", "esattler"],
)

User preferences

from knockapi import Knock
client = Knock(api_key="sk_12345")

# Replaces the preferences for the user
client.preferences.update(
  user_id="jhammond",
  channel_types={'email': True},
  workflows={'dinosaurs-loose': False}
)

# Retrieve the current preferences
client.preferences.get(user_id="jhammond")

Signing JWTs

You can use the pyjwt package to sign JWTs easily. You will need to generate an environment specific signing key, which you can find in the Knock dashboard.

If you're using a signing token you will need to pass this to your client to perform authentication. You can read more about client-side authentication here.

import jwt
import os

private_key = os.getenv("KNOCK_SIGNING_KEY")
encoded = jwt.encode({"sub": "jhammond"}, private_key, algorithm="RS256")

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

knockapi-0.2.3.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

knockapi-0.2.3-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file knockapi-0.2.3.tar.gz.

File metadata

  • Download URL: knockapi-0.2.3.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1

File hashes

Hashes for knockapi-0.2.3.tar.gz
Algorithm Hash digest
SHA256 0084d7c3d6f77eb1f73bcebf0c6c10101f7fbb11cdd1a1dfd3fa672969e12c19
MD5 3aa91ab2e0938f62e8147da5012f7adb
BLAKE2b-256 4951be32e4eab327e6952d448150fd10657f9e9466d5fdbe8032d1aeb49e96e5

See more details on using hashes here.

File details

Details for the file knockapi-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: knockapi-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1

File hashes

Hashes for knockapi-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a3ad519e8fcaf39f21d676b754e9b39d20a931aee494debcae47c6965ce9aeac
MD5 a5096991ce7d0126f6f450ce55f70fac
BLAKE2b-256 34d152d47abcc12a235a41424a8e477050efd407c01f60e6a863e1cd9eaaeab1

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