This repository offers boilerplate code for initiating a Dockerized FastAPI-PostgreSQL-SQLAlchemy-Alembic project. It includes a pre-commit framework configured with mypy and ruff to ensure consistent code formatting and strict typing. Whether you're building microservices or a larger application, this template streamlines your project setup, allowing you to focus on developing your FastAPI-based microservices with confidence
Use this template as a starting point to quickly set up a robust and scalable FastAPI project with PostgreSQL, taking advantage of powerful features like automatic API documentation generation, asynchronous capabilities, and containerization for easy deployment.
- FastAPI framework for building high-performance APIs
- PostgreSQL database integration with SQLAlchemy for efficient data management
- Alembic for seamless database schema migrations
- Pre-commit framework with MyPy and ruff for code formatting and strict typing checks
- CRUD base class fot instance with needed model
- Project config file fo ease update configurations
- Utils function in utils.py (client and consumer for RabbitMQ broker for example)
Get started with your FastAPI project in no time using this template repository!
Initial Setup
- Init project:
- create and activate a virtual env
- install initial dependencies
- install pre-commit config and run in all file to initial check Positioning in the project root run make the following make command:
make init
Local Development
To set up environment variables for local development, follow these steps:
- Create a
.env
file in the root directory of your project. - Add the necessary environment variables to the .env file in the format KEY=VALUE. Adjust the config.py file to insert these variables into the config class instance.
Example .env file:
DB_HOST=localhost
DB_PORT=5432
DB_USER=myuser
DB_PASSWORD=mypassword
Deployed
For deployment, you'll need to set up environment variables or secrets in your GitHub repository. Here's how to do it:
- Create the required environment variables or secrets in your GitHub repository.
- In the github-actions workflow file locate the env section.
- Insert the environment variables or secrets into the workflow step, providing the necessary values.
Example workflow step:
- name: Deploy
env:
DB_HOST: ${{ vars.DB_HOST }}
DB_PORT: ${{ vars.DB_PORT }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
run: |
# Add your deployment script here
Please ensure you update this README after implementing an instance of this template. Here are the recommended steps to follow:
In your README's "Introduction and/or Overview" section (or similar), include the following information:
The service is built is based on the [fastAPI MS Template](https://github.com/ferdinandbracho/bp_fastAPI-sqlalchemy-alembic-docker). For comprehensive technical details, instructions on how to run, deploy, and any other related considerations, please refer to the documentation provided in the [template repository](https://github.com/ferdinandbracho/bp_fastAPI-sqlalchemy-alembic-docker).
Towards the end of your README, just before the "Contributing" section (if applicable), add links to specific sections of the template repository for Indeed Information:
## Indeed Information
For detailed information on installation and prerequisites, please refer to the [template repository](https://github.com/ferdinandbracho/bp_fastAPI-sqlalchemy-alembic-docker).
Contributions are welcome! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Implement your changes.
- Write or update tests as necessary.
- Submit a pull request against the main branch.
Please ensure your code adheres to the project's coding standards and includes appropriate tests.