### Install Mofi using pip Source: https://github.com/jedddy/mofi/blob/master/README.md This command installs the Mofi library using pip, making it available for use in your Python projects. Ensure you have Python and pip installed. ```bash pip install mofi ``` -------------------------------- ### Mofi Basic Usage with Callbacks Source: https://github.com/jedddy/mofi/blob/master/README.md This Python code demonstrates the basic usage of the Mofi library to handle Ko-fi webhooks. It sets up a Mofi instance and defines asynchronous callback functions for 'donation', 'subscription', 'shop_order', and a general 'global' event type. The application is then run on a specified host and port. ```python from mofi import Mofi, Donation, GlobalType, Subscription, ShopOrder app = Mofi(token="token") @app.callback("donation") async def donation(data: Donation): print("Donation event.") @app.callback("subscription") async def subscription(data: Subscription): print("Subscription event") @app.callback("shop_order") async def shop_order(data: ShopOrder): print("Shop Order event") @app.callback("global") async def global_callback(data: GlobalType): print("Global event") # matches all event types app.run(host="127.0.0.1", port=8000) # use 0.0.0.0 and 80 on deployment ``` -------------------------------- ### Integrate Mofi with FastAPI Application Source: https://github.com/jedddy/mofi/blob/master/README.md This Python code shows how to integrate Mofi into an existing FastAPI application. It creates a FastAPI app, initializes Mofi, defines a callback for the 'global' event, and then includes the Mofi router into the main FastAPI application. A basic root endpoint is also included. ```python from fastapi import FastAPI from mofi import Mofi, GlobalType app = FastAPI() mofi_wh = Mofi(token="token") @mofi_wh.callback("global") async def global_type(data: GlobalType): print(data.from_name) app.include_router(mofi_wh.as_router()) # add mofi after defining callbacks @app.get("/") async def index(): return {"message": "Hello World"} ``` -------------------------------- ### Expose Local Server with ngrok Source: https://github.com/jedddy/mofi/blob/master/README.md This command uses ngrok to expose a local server running on port 8000 to the internet. This is useful for testing webhooks, as it provides a public URL that external services like Ko-fi can send requests to. ```bash ngrok http 8000 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.