Skip to content

This is my custom template project for a simple FastAPI application.

License

Notifications You must be signed in to change notification settings

jmcerrejon/another-fastapi-template

Repository files navigation

Another FastAPI Template

This is my custom template project for a simple FastAPI application.

Description

This template provides a basic setup for a FastAPI application.

Requirements

  • Python 3.12+
  • FastAPI
  • Uvicorn
  • SQLAlchemy
  • Poetry (optional)
  • Pytest

Installation

  1. Clone the repository:
git clone https://github.com/jmcerrejon/another-fastapi-template.git
cd another-fastapi-template
  1. Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows use `.venv\Scripts\activate`
  1. Install the dependencies:
pip install -r requirements.txt
  1. 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

Running

To start the server, run the following command:

uvicorn main:app --host 127.0.0.1 --port 8000 --reload

Docker

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

Testing

To run the tests, run the following command:

PYTHONPATH=. pytest

Using Poetry

To install and use Poetry in the project, follow these steps:

  1. Install Poetry:
pip install poetry
  1. Install the dependencies using Poetry:
poetry install
  1. To add a new dependency, use the following command:
poetry add <package_name>
  1. To run the project using Poetry, use the following command:
poetry run uvicorn main:app --host 127.0.0.1 --port 8000 --reload

TODO

  • 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.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

About

This is my custom template project for a simple FastAPI application.

Topics

Resources

License

Stars

Watchers

Forks