Skip to main content

API for creating GitHub bots and webhooks in Python.

Project description

github-bot-api

API for creating GitHub bots and webhooks in Python.

Note: If you want to make use of GithubApp.app_client() or GithubApp.installation_client(), you need to install PyGithub.

Quickstart (Webhook)

  1. Create a new Smee channel on https://smee.io
  2. Install smee-client (e.g. yarn global add smee-client)
  3. Run smee -u <SMEE_CHANNEL_URL> -P /event-handler -p 5000
  4. Create a Python script with the below contents and run it
from github_bot_api import Event, Webhook
from github_bot_api.flask import create_flask_app

def on_any_event(event: Event) -> bool:
  print(event)
  return True

webhook = Webhook(secret=None)
webhook.listen('*', on_any_event)

import os; os.environ['FLASK_ENV'] = 'development'
flask_app = create_flask_app(__name__, webhook)
flask_app.run()

Quickstart (Application)

  1. Create a GitHub App, including a private key
  2. Set the APP_ID and PRIVATE_KEY_FILE environment variables
  3. Run the following Python script
import os
from github_bot_api import GithubApp

with open(os.environ['PRIVATE_KEY_FILE']) as fp:
  private_key = fp.read()

app = GithubApp(
  user_agent='my-bot/0.0.0',
  app_id=int(os.environ['APP_ID']),
  private_key=private_key)

print(app.app_client().get_app().owner)

Combined Example

# ...

app = GithubApp(...)
webhook = Webhook()

@webhook.listen('pull_request')
def on_pull_request(event: Event) -> bool:
  client = app.installation_client(event.payload['installation']['id'])
  repo = client.get_repo(event['repository']['full_name'])
  pr = repo.get_pull(event['pull_request']['number'])
  pr.create_issue_comment('Hello from my own bot!')
  return True

# ...

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

github-bot-api-0.5.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

github_bot_api-0.5.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file github-bot-api-0.5.1.tar.gz.

File metadata

  • Download URL: github-bot-api-0.5.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

File hashes

Hashes for github-bot-api-0.5.1.tar.gz
Algorithm Hash digest
SHA256 11ab82b8cf6485a1ffb086a53626fec29e0dbce994ff38aba49fab302c7f19c5
MD5 69f2294240cc7badf782145ef20ccd20
BLAKE2b-256 f90364f522c0257cfcc42b04a5df038e9dd3dfe6f1c43b4eebb230ed8d2be662

See more details on using hashes here.

File details

Details for the file github_bot_api-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: github_bot_api-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

File hashes

Hashes for github_bot_api-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df405e604195d65147a6d1d3c79240b56940f8a894a40986f34aa122539000eb
MD5 54915f69d930491e4d51647408d32840
BLAKE2b-256 ffcc991e9e2b5b0d86a3b15aa618d008d40ae70264e115a45f830934f23c3fe0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page