Ko-fi Donation API enables access to donations, database, and users via FastAPI endpoints.
2.2K
An API to store and access Ko-fi donations
Ko-fi Donation API is a FastAPI-based system that allows users to store and access Ko-fi transactions. It provides a set of API endpoints for handling donations, exporting and importing the database, and admin-specific operations like managing users and transactions.
Python 3.12.6.FastAPI 0.115.0 by default.To install and set up the project locally, follow these steps:
Clone the repository:
git clone <https://github.com/yourusername/kofi-donation-api.git>
cd kofi-donation-api
Create a virtual environment and activate it:
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
Install dependencies:
cd app
pip install -r requirements.txt
Set up the environment variables:
DATA_RETENTION_DAYS: Default data retention period for users. Default is "30".
ADMIN_SECRET_KEY: Secret key for admin operations. Default is changethis. An alert will be raised if the secret key is set to the default value.
ENVIRONMENT: Provide the stage of the application. Possible values are local and production. Default is local and will not block if the secret key is set to the default value (in production it will block).
DATA_RETENTION_DAYS="10"
ADMIN_SECRET_KEY="your_admin_secret_key"
ENVIRONMENT="production"
The application uses Pydantic to manage environment variables. The configuration variables can be defined in the .env file or passed as environment variables. Key configuration options include:
PROJECT_NAME: The name of the project. Default is Ko-fi API.
DATA_RETENTION_DAYS: Default data retention period for users. Default is "30".
DATABASE_URL: The database connection URL (e.g., SQLite, PostgreSQL). Default is sqlite:///./KoFi.db.
ADMIN_SECRET_KEY: Secret key for admin operations. Default is changethis.
ENVIRONMENT: The environment in which the app is running (local, production). Default is local.
You can run the FastAPI application using Uvicorn:
cd app
fastapi run main.py
The API will be accessible at http://127.0.0.1:8000, and the documentation will be available at http://127.0.0.1:8000/docs or http://127.0.0.1:8000/redoc (Swagger UI/ReDoc).
POST /webhook: Receives a Ko-fi transaction via a webhook and stores the transaction.
You can find the different Ko-fi webhook events and more information about them here.
/users/{verification_token}: Create a new user./users/{verification_token}: Retrieve a user by their verification token./users/{verification_token}: Update user data, such as data_retention_days./users/{verification_token}: Delete a user and their associated transactions./db/transactions: Retrieve all Ko-fi transactions (admin-only)./db/users: Retrieve all Ko-fi users (admin-only)./db/export: Export the database (admin-only)./db/recover: Recover the database from a file (admin-only)./db/import: Import a database (admin-only).The project uses pytest for testing. To run the tests, first install the development dependencies:
cd app
pip install -r test/requirements-dev.txt
Then, run the tests:
coverage run -m pytest
This will execute all unit tests, including those for the FastAPI endpoints and database operations.
This project is licensed under the MIT License. See the LICENSE file for more details.
That's it! You're all set up to use the Ko-fi API.
Content type
Image
Digest
sha256:06029bc02…
Size
71.9 MB
Last updated
about 1 year ago
docker pull lordlumineer/kofi-api