Typed event handling for GitHub Webhooks
Project description
Typed event handling for GitHub Webhooks
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)
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 codepoe lint
- Lint codepoe test
- Run testspoe docs
- Build docspoe 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.
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
Built Distribution
File details
Details for the file gh-webhooks-0.5.0.tar.gz
.
File metadata
- Download URL: gh-webhooks-0.5.0.tar.gz
- Upload date:
- Size: 28.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.6 Linux/5.13.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcb4aa3f4b19bfa918cdfba9c06b0bf715aefc3ad4f85dfad5c7f6f1f1285b4c |
|
MD5 | 97aee668b6774718faba3d9fa830d746 |
|
BLAKE2b-256 | 9cc6be6492d894849ff65cea96e694b5ca5413fcd80a973893cea6a83add1e91 |
File details
Details for the file gh_webhooks-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: gh_webhooks-0.5.0-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.6 Linux/5.13.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 891c28589b868f3b118b72796ddb6b0c740fc9b47130bbe3064406fc4df71f71 |
|
MD5 | 54f0d84858c27073c29b5b94fc838513 |
|
BLAKE2b-256 | 5e7aa3655da3748a745b81e0c631ee8199d6e6f0ff462dad683713f9027ca7ea |