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(
  name="dinosaurs-loose",
  actor="dnedry",
  recipients=["jhammond", "agrant", "imalcolm", "esattler"],
  data={
    "type": "trex",
    "priority": 1
  }
)

Canceling notifies

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

client.cancel_notify(
  name="dinosaurs-loose",
  cancelation_key=alert.id,
  recipients=["jhammond", "agrant", "imalcolm", "esattler"],
)

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 clientside authentication here.

from 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.1.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

knockapi-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: knockapi-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 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.1.1.tar.gz
Algorithm Hash digest
SHA256 5ee1bd7814948505b67a9a48e5f017c19324d0b8239bd0f636c90c2a01a764bf
MD5 0956b10d3299e5c75d4d9e3e2594f99b
BLAKE2b-256 db81d262c3aa18e130a8c5b241f0a77136a732c0d86d5e519659eea1c79e9cd3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: knockapi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b5e08a6b1705a513d492362c01884f33fe97df173b9f87cd450fdd178e3e1e8
MD5 7388b601e35beebaa75f4f3752c068e8
BLAKE2b-256 bc180157b6de249eec3f97ac98e7cda9a27990c8a755bfdc92ceb5894f226fae

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