Skip to main content

Typed event handling for GitHub Webhooks

CI codecov PyPI

This library provides types for using GitHub Webhook events in Python, and a class for registering event handlers for each event type.

An example using FastAPI:

from fastapi import FastAPI, Request
from gh_webhooks import GhWebhookEventHandler
from gh_webhooks.types import BranchProtectionRuleCreated

app = FastAPI()
event_handler = GhWebhookEventHandler()

@event_handler.on(BranchProtectionRuleCreated)
async def handle_new_branch_protection_rule(event: BranchProtectionRuleCreated):
    print(event.repository.name)


@app.post("/payload")
async def handle_webhook_payload(request: Request):
    event = await request.json()
    await event_handler.handle_event(event)

You can also see a basic example project here.

Multiple handlers can be registered to the same event type, and they'll run concurrently.

The types are auto-generated using datamodel-code-generator. A GitHub action maintains these types automatically.

Integration tests are also auto-generated from the example events in the GitHub Webhook events spec docs.

Developing

Install Poetry and poetry install the project

Useful Commands

Note: if Poetry is managing a virtual environment for you, you may need to use poetry run poe instead of poe

  • poe autoformat - Autoformat code
  • poe lint - Lint code
  • poe test - Run tests
  • poe docs - Build docs
  • poe codegen - Generate types

Release

Release a new version by manually running the release action on GitHub with a 'major', 'minor', or 'patch' version bump selected. This will create and push a new semver tag of the format v1.2.3, which in turn will trigger an action to automatically publish a new version to PyPI.

Optionally create a release from this new tag to let users know what changed.

Release files for gh-webhooks 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gh-webhooks 0.6.0
File Size Uploaded
gh-webhooks-0.6.0.tar.gz 29.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gh-webhooks 0.6.0
File Interpreter ABI Platform
gh_webhooks-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 57.9 kB

Release files / gh-webhooks-0.6.0.tar.gz

Download URL gh-webhooks-0.6.0.tar.gz
Size 29.0 kB
Tags Source
SHA-256 checksum
How to use checksums
188f7b8edcb5184270ab89aeadd5e7c3f5c43c209b051132d8146506f69aa6ef
BLAKE2b-256 checksum
How to use checksums
fa3e828cde0881390681eecd2a8053d6a021342ee72e5298b494119d4c4c226b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.0a2 CPython/3.9.6 Linux/5.13.0-1031-azure

Release files / gh_webhooks-0.6.0-py3-none-any.whl

Download URL gh_webhooks-0.6.0-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e115f5928badd877cb39d582e0c61d5468af279f71936a8c904957ffb8785fc8
BLAKE2b-256 checksum
How to use checksums
8596522b6891d0b0cf7c35f63d1b38eb5f3fbd31d25048dd1391bcc6ae00536f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.0a2 CPython/3.9.6 Linux/5.13.0-1031-azure

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page