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.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

knockapi-0.2.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: knockapi-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 02efcbff6b68f8f85f06a4fd99570b182f99fce4c05939a66b628785b0e7c794
MD5 c05b8261ddc7c52685fa05a4e491d9d9
BLAKE2b-256 e8ce979d3f2ddc895f0976c48a04e80b2234ebf98e22d592c5020e8fe598927b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: knockapi-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6bc8ed1ce64a4060bf152a3777c82821868076fc3ce38265c438527078f88eef
MD5 2c9ca72fe3144303b059d11ad486e97f
BLAKE2b-256 2893a5e7bd1e6131b8240d92ae725bb02964021a242293d5024fbed874e93c84

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