bookmark_borderFastAPI Stripe Webhook Template

A FastAPI equivalent for verify-events-came-from-stripe.

import os

from http import HTTPStatus
from typing import Annotated

import stripe
from fastapi import Depends, FastAPI, Header, HTTPException, Request


app = FastAPI()


async def get_body(request: Request) -> bytes:
    return await request.body()


@app.post("/webhook", status_code=HTTPStatus.NO_CONTENT)
def post_report(
    stripe_signature: Annotated[str, Header(alias="stripe-signature")],
    body: bytes = Depends(get_body),
) -> None:
    endpoint_secret = os.environ["ENDPOINT_SECRET"]

    try:
        # signature validation
        event = stripe.Webhook.construct_event(body, stripe_signature, endpoint_secret)
    except ValueError as e:
        # Invalid payload
        raise HTTPException(status_code=HTTPStatus.BAD_REQUEST) from e
    except stripe.error.SignatureVerificationError as e:
        # Invalid signature
        raise HTTPException(status_code=HTTPStatus.UNPROCESSABLE_ENTITY) from e

    print(event)

    return

A possible catch, one that I ran into, is that I had FastAPI convert the request.body to a dictionary in the function parameters (so body: dict). Then I serialized it to a string for the validation step… and it failed because it was no longer identical to what came in.

bookmark_borderMinimizing the size of lambdas by avoiding having boto3 and its stubs in the deployment package

If you are having problems with AWS lambdas exceeding the 250MB limit, here is a tip that might help.

Continue reading “Minimizing the size of lambdas by avoiding having boto3 and its stubs in the deployment package”

bookmark_borderUsing Selenium to Roll Out Changes to Gihub Settings

Your company is rolling out a new policy and need you to change settings across many repositories? That sounds like a very repetitive task that can be easily automated. I just did it with Selenium. Here is the recipe.

Continue reading “Using Selenium to Roll Out Changes to Gihub Settings”

bookmark_borderA chrome extension to navigate Github files differently

Last week, I was somewhat complaining that Github’s file navigator was not to my taste. When moving across files and directory, you have to go back and forth a lot. If you quickly want to switch between 2 files not in the same directory, it’s painful. Of course, one could open another tab, but tabbing doesn’t cut it. I wanted something more like a files navigator that we can find in any OS.

Then I though, hey, surely I can simply manipulate the HTML to make it work the way I want. I started coding… 45 minutes later, I had a working prototype of JavaScript code that I could simply paste in the browser console and bang; a nice file tree navigator-like experience right in Github.

Continue reading “A chrome extension to navigate Github files differently”

bookmark_borderStarCluster 0.95

English version will follow.

La version 0.95 de StarCluster, à laquelle j’ai contribué à travers mon emploi chez Datacratic et mon implication sur le canal IRC, est sortie hier. Consultez la liste des changements pour plus d’informations.

StarCluster version 0.95, which I contributed to through my work at Datacratic and my implication via the IRC channel, was released yesterday. See the list of changes for more information.

bookmark_borderStarCluster 0.94

La version 0.94 de StarCluster est sortie tout récemment. Le 22 juillet dernier pour être exact.

Pour ceux qui voudraient être un peu plus «bleeding edge», je viens de compléter le merge de la plus récente version de la branche develop à l’intérieur de notre branche vanilla_improvements. À la fin du readme, vous trouverez les ajouts que j’ai faits à la version originale.


StarCluster version 0.94 was recently released. July 22nd to be exact.

For those who would like to use the bleeding edge version, I just completed merging the latest commit on branch develop into our vanilla_improvements branch. At the end of the readme, you will find the additions I made to the original version.