Project Lead : | Chris Blevins
Thanks to Sebastián Ramírez @tiangolo we have the wonderful FastAPI package for developing applications and APIs. Anyone looking at this repository is most likely familiar with the project. If not I highly recommend Reading the Docs.
While learning and using FastAPI I have often needed/wanted lightweight project scaffolding. The project generators and scaffolding projects in the FastAPI ecosystem have been either too deterministic and too big or not deterministic enough for me.
This is how I set up a new FastAPI project. I hope this is helpful.
Package | Note |
---|---|
Python 3.6+ | This project uses Python 3.9 but should work on Python 3.6+. |
pip | I use Pip for pacakage management and pin versions. I don't think anything more complex than that is necessary. Adjust for your flow. |
virtualenv | Again I am not trying to get fancy. py -m pip install virtualenv |
FastAPI | I usally install all related packages in my venv. pip install fastapi[all] |
Docker | (Optional) I use it to startup DBs instead of installing directly. Will make your life easier. There are also images for bundled FastAPI environmets on Docker Hub. |
ODMantic | (Optional) ORM for MongoDB with great model and document support. |
TortoiseORM | (Optional) ASYNC ORM that works well with FastAPI and Postgres/MySQL |
dnsPython | (Optional) Used for querrying remote DBs etc. |
-
Install Python if not already installed
-
Clone this repository:
git clone https://github.com/blevinscm/fastapi-scaffold-base.git
-
Install virtualenv
py -m pip install --user virtualenv
-
CD into project directory
cd dir
-
Create virtual environment
py -m venv env
-
Activate virtual environment
source .\env\bin\activate
-
Install pip dependencies (This will install all FastAPI Modules. If you do not want [all] plese adjust the req file.)
pip install -r requirements.txt
-
(Optional) If you want to use Mongo then edit fastapi-scaffold-base\app\config\config.py to add Mongo URI.
-
(Optional) Pull latest Mongo image and create mongo container for dev purposes
docker pull mongo:latest docker run --rm --net=host mongo
-
Set execute permissions on either startup.ps1 or startup.sh
-
Run the start-FastAPI for your system
-
Go to https://localhost:8000 to see a basic HTML page with sections for content. You can edit the Jinja placeholders to add content as you see fit in fastapi-scaffold-base\templates\indeix.html. This is a responsive template based on CSS Grid without using Javacript. Add any static assets to static.
-
Go to https://localhost:8000/docs to see your FastAPI documentation and explore the sample docs.
-
Close your FastAPI terminal and your Mongo Terminal.
-
To get out of venv
deactivate
--TODO--
- Add unit tests and Integrate Pytest
- Add implicit support for Relational data
- Add plug and play content through API calls