This is my custom template project for a simple FastAPI application.
This template provides a basic setup for a FastAPI application.
- Python 3.12+
- FastAPI
- Uvicorn
- SQLAlchemy
- Poetry (optional)
- Pytest
- Clone the repository:
git clone https://github.com/jmcerrejon/another-fastapi-template.git
cd another-fastapi-template
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
- Install the dependencies:
pip install -r requirements.txt
- Copy .env.example to .env and modify the values:
cp .env.example .env
If you want to use the customizer script, run the following command:
./scripts/boilerplate-customizer.sh
If you want to start a new project once you have cloned the repository, remove the .git
directory and start a new git repository. But, maybe you want to get updates from this repository. You can add it as a remote upstream:
rm -rf .git
git init
# (Optional) Add the remote repository as upstream
git remote add upstream git@github.com:jmcerrejon/another-fastapi-template.git
When you want to get updates from this repository:
git pull upstream main
To start the server, run the following command:
uvicorn main:app --host 127.0.0.1 --port 8000 --reload
You have a containerized version of the app. To build the image, run:
docker build -t fastapi-template . && docker run -d -p 8000:8000 --name fastapi-container fastapi-template
To run the tests, run the following command:
PYTHONPATH=. pytest
To install and use Poetry in the project, follow these steps:
- Install Poetry:
pip install poetry
- Install the dependencies using Poetry:
poetry install
- To add a new dependency, use the following command:
poetry add <package_name>
- To run the project using Poetry, use the following command:
poetry run uvicorn main:app --host 127.0.0.1 --port 8000 --reload
- Add Database support (default: sqlite).
- Add .env support.
- Add SQLAlchemy support.
- Add Poetry.
- Testing.
- Add Dockerfile.
- Log system.
- Authentication.
- Modify scripts/boilerplate-customizer.sh to add more options.
This project is licensed under the MIT License - see the LICENSE file for details.
- Made with ❤️ and ☕️ by Jose Cerrejon.
- Inspired on posts by @aberrospic1 & @lou_adam.