Skip to content

Events over webhooks example app #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/event-webhooks-local-flask.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Events Over Webhooks Local Flask App Tests

# Taken from https://github.com/actions/starter-workflows/blob/main/ci/python-app.yml

on:
push:
branches: [ main ]
pull_request:
types: [opened, edited, synchronize]

permissions:
contents: read

jobs:
test:

runs-on: ubuntu-20.04
name: Quality Checks + Tests
defaults:
run:
working-directory: ./examples/event-webhooks-local-flask

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install requirements
run: pip install -r requirements.txt
- name: Install dev requirements
run: pip install -r dev_requirements.txt
- name: Lint
run: ruff check .
- name: Mypy
run: mypy .
- name: Run Tests
run: pytest tests/unit
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,23 @@ in a local development environment running [Flask](https://flask.palletsprojects
* User Feedback via [App Status](https://docs.benchling.com/docs/introduction-to-app-status)
* Data Mapping via [App Config](https://docs.benchling.com/docs/app-configuration)
* Receiving and verifying [Webhooks](https://docs.benchling.com/docs/getting-started-with-webhooks)
* Creating [molecule custom entities](https://benchling.com/api/reference#/Molecules/createMolecule)
* Creating [molecule custom entities](https://benchling.com/api/reference#/Molecules/createMolecule)

## event-webhooks-local-flask

Demonstrates creating a custom UI in Benchling allowing users to search for
molecules from [PubChem](https://pubchem.ncbi.nlm.nih.gov/) and sync them into Benchling.

Uses [localtunnel](https://localtunnel.me/) and [Docker](https://www.docker.com/) to receive webhooks
in a local development environment running [Flask](https://flask.palletsprojects.com/) with the
[Benchling SDK](https://docs.benchling.com/docs/getting-started-with-the-sdk). Syncs data from Benchling
to [PostgreSQL](https://www.postgresql.org/), an external database.

![image info](./examples/event-webhooks-local-flask/docs/demo-full.gif)

**Code Includes:**
* Benchling App Authentication via [Client Credentials](https://docs.benchling.com/docs/getting-started-benchling-apps#getting-credentials)
* App Activity Feedback via [App Status](https://docs.benchling.com/docs/introduction-to-app-status)
* Data Mapping via [App Config](https://docs.benchling.com/docs/app-configuration)
* Receiving and verifying [Webhooks](https://docs.benchling.com/docs/getting-started-with-webhooks)
* Filtering a `v2.entity.registered` Event from Benchling delivered by webhook
17 changes: 17 additions & 0 deletions examples/event-webhooks-local-flask/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.11

# Add non-root user for security
ARG USERNAME=nonroot
RUN groupadd --gid 1000 $USERNAME && useradd --uid 1000 --gid 1000 -m $USERNAME
## Make sure to reflect new user in PATH
ENV PATH="/home/${USERNAME}/.local/bin:${PATH}"
USER $USERNAME

# Install pre-requirements
RUN pip install pip~=23.3.2 setuptools~=69.0.3

COPY requirements.txt ./
RUN pip install -r requirements.txt

COPY dev_requirements.txt ./
RUN pip install -r dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"runArgs": [
"--network=host"
],
"remoteUser": "nonroot",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.mypy-type-checker",
"charliermarsh.ruff"
],
"settings": {
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.editor.defaultFormatter": "charliermarsh.ruff",
"python.linting.mypy": true,
"python.linting.enabled": true,
"explorer.excludeGitIgnore": true,
"python.analysis.packageIndexDepths": [
{"name": "benchling_sdk", "depth": 8, "includeAllSymbols": true}
]
}
}
}
}
12 changes: 12 additions & 0 deletions examples/event-webhooks-local-flask/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.idea
.vscode
**/.venv/
**/*.egg-info
**/__pycache__
**/.env
.DS_Store
**/.client_secret
**/.database_password
**/.pytest_cache
.mypy_cache
.ruff_cache
10 changes: 10 additions & 0 deletions examples/event-webhooks-local-flask/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.11

# Install pre-requirements
RUN pip install pip~=23.3.2 setuptools~=69.0.3

COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY ./local_app /src/local_app
WORKDIR /src/local_app
CMD ["flask", "run", "--host", "0.0.0.0"]
5 changes: 5 additions & 0 deletions examples/event-webhooks-local-flask/Dockerfile.localtunnel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:21-alpine
RUN npm install -g [email protected]

# Note: This might not work with some networks. For instance, random airplane WiFi
CMD lt --port 5000 --local-host benchling-app --print-requests
Loading
Loading