Skip to main content

Typed event handling for GitHub Webhooks

Project description

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):
    await event_handler.handle_event(request.json())

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.

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

gh-webhooks-0.4.0.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

gh_webhooks-0.4.0-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file gh-webhooks-0.4.0.tar.gz.

File metadata

  • Download URL: gh-webhooks-0.4.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

Hashes for gh-webhooks-0.4.0.tar.gz
Algorithm Hash digest
SHA256 dd7045370ad3905c1c21115b019ff15161c580aebcb8d98ada9b3f7aaf69f709
MD5 9009b4328232bc30d82aed695694bebf
BLAKE2b-256 9b8c833a4b39a3e29a334ac9ebb03033604c0957a3062f7da1b6adada16daab0

See more details on using hashes here.

File details

Details for the file gh_webhooks-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: gh_webhooks-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 28.0 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

Hashes for gh_webhooks-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6115dc1ca92b9a5724a7c8cde1f779fd48af7050ea34684d662522248a6f7ff2
MD5 9c35aabf0ba6a9e7dabaf33a551620c2
BLAKE2b-256 bee5ea18ef10e992c2c4ccc917fc0e45b2f9b4c0c7e05ee7c9706011c09cf89d

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