Knock Python API Library

1.24.1 · active · verified Mon Apr 13

The Knock Python library provides convenient access to the Knock REST API from any Python 3.9+ application. Knock is a notification infrastructure platform that helps developers build and manage notification workflows across multiple channels including email, push, SMS, Slack, and in-app feeds. The library offers both synchronous and asynchronous clients powered by `httpx` and includes type definitions for all request parameters and response fields. It is generated with Stainless and follows semantic versioning conventions.

Warnings

Install

Imports

Quickstart

Initializes the synchronous Knock client using an API key from an environment variable and triggers a sample workflow. Ensure the `KNOCK_API_KEY` environment variable is set and a workflow with the key `dinosaurs-loose` exists in your Knock dashboard.

import os
from knockapi import Knock

# Initialize the client with your API key from an environment variable
# KNOCK_API_KEY environment variable is used by default if not explicitly provided
client = Knock(api_key=os.environ.get('KNOCK_API_KEY', ''))

# Trigger a workflow (ensure 'dinosaurs-loose' workflow exists in Knock dashboard)
try:
    response = client.workflows.trigger(
        key="dinosaurs-loose",
        recipients=["dnedry"],
        data={
            "dinosaur": "triceratops"
        },
    )
    print(f"Workflow run ID: {response.workflow_run_id}")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →