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()
orGithubApp.installation_client()
, you need to installPyGithub>=1.58
.
Quickstart (Webhook)
- Create a new Smee channel on https://smee.io
- Install
smee-client
(e.g.yarn global add smee-client
) - Run
smee -u <SMEE_CHANNEL_URL> -P /event-handler -p 5000
- 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)
- Create a GitHub App, including a private key
- Set the
APP_ID
andPRIVATE_KEY_FILE
environment variables - 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
Release history Release notifications | RSS feed
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.2.tar.gz
(10.5 kB
view hashes)
Built Distribution
Close
Hashes for github_bot_api-0.5.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5141629304dff6f3a2dbe7bd9e2b32f90fb4c25a37bfc129b4d592773ba55e35 |
|
MD5 | c7b2d1f0a2ac884c11a7dc66feb3c0b1 |
|
BLAKE2b-256 | 542e43c136daee9bdfd6db2847657015d8a75cae0740f02b58265881b40a15eb |