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.
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_IDandPRIVATE_KEY_FILEenvironment 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.4.0.tar.gz
(10.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file github-bot-api-0.4.0.tar.gz.
File metadata
- Download URL: github-bot-api-0.4.0.tar.gz
- Upload date:
- Size: 10.9 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.61.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5623a87b32046b3f033b5ca2d09e2175fd0f43ae642f5eca0aea1ba64b91194
|
|
| MD5 |
8673a60228b3265f8d253f15cdbff4d3
|
|
| BLAKE2b-256 |
bb3994f3cb618d10768c35adbcafdd87f2617e0ed4c4a17a7e20a4cabe05e7d8
|
File details
Details for the file github_bot_api-0.4.0-py3-none-any.whl.
File metadata
- Download URL: github_bot_api-0.4.0-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.61.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e95f7f6aa7c37fec71d7db036f4fee74210ac03350bae1d99c2ff5aa0411ec8d
|
|
| MD5 |
9c0fa19f77fce7ed052043790ac39d1d
|
|
| BLAKE2b-256 |
adc66555c9f40b61065c4ac9c0f2c95be4fc5d26704edd96d50c653db79e0068
|