Ever wanted a friend on campus? Well, now you can catch one!
- (Optional step) Set up a virtual environment using
python3 -m venv .venv. If using VSCode, accept using the new Python interpreter or otherwise ctrl+P and then>Python: Select Interpreterand choose the one located at.\.venv. - Install the dependencies using
pip install -r requirements.txt. - Additionally install `pip install "fastapi[standard]" separately. This is not included in a production build.
- Run the application using
fastapi dev src/main.py. - Any new changes after using something like ctrl+S will reload and re-run the project automatically.
- Easily test any endpoints at http://127.0.0.1:8000/docs
- Use
_log.debug,_log.info,_log.warning,_log.errorandlog.exceptionfor permanent logging (can useprintfor quick debugging). Especially check out how to uselog.exceptionin try except catches. - If you are importing something for the sake of type hinting ONLY, import it under
if TYPE_CHECKINGfromfrom typing import TYPE_CHECKING. - Install
pip install ruffand runruff formatto format all files. Can optionally also install the VSCode Ruff linter.
(Create an empty new line after each group of imports)
- Import
from __future__ import annotationswhere applicable (should also then havefrom typing import TYPE_CHECKINGimported too) first (used when you face cyclic import errors when you are just trying to type hint). - Import all third-party and built-in libraries that are
import foo. - Import all third-party and built-in libraries that are
from foo import bar. - Import all project-specific libraries under
/src.import foofirst, and thenfrom foo import barbut no need for empty new line in between. - Lastly import anything for only type hinting purposes under
if TYPE_CHECKING:.