FastAPI Structure

공식 문서기준
example file structure
├── app # "app" is a Python package │ ├── __init__.py # this file makes "app" a "Python package" │ ├── main.py # "main" module, e.g. import app.main │ ├── dependencies.py # "dependencies" module, e.g. import app.dependencies │ └── routers # "routers" is a "Python subpackage" │ │ ├── __init__.py # makes "routers" a "Python subpackage" │ │ ├── items.py # "items" submodule, e.g. import app.routers.items │ │ └── users.py # "users" submodule, e.g. import app.routers.users │ └── internal # "internal" is a "Python subpackage" │ ├── __init__.py # makes "internal" a "Python subpackage" │ └── admin.py # "admin" submodule, e.g. import app.internal.admin
Python
복사
factory pattern
fastapi-nano ├── app # primary application folder │ ├── apis # this houses all the API packages │ │ ├── api_a # api_a package │ │ │ ├── __init__.py # empty init file to make the api_a folder a package │ │ │ ├── mainmod.py # main module of api_a package │ │ │ └── submod.py # submodule of api_a package │ │ └── api_b # api_b package │ │ ├── __init__.py # empty init file to make the api_b folder a package │ │ ├── mainmod.py # main module of api_b package │ │ └── submod.py # submodule of api_b package │ ├── core # this is where the configs live │ │ ├── auth.py # authentication with OAuth2 │ │ ├── config.py # sample config file │ │ └── __init__.py # empty init file to make the config folder a package │ ├── __init__.py # empty init file to make the app folder a package │ ├── main.py # main file where the fastAPI() class is called │ ├── routes # this is where all the routes live │ │ └── views.py # file containing the endpoints of api_a and api_b │ └── tests # test package │ ├── __init__.py # empty init file to make the tests folder a package │ └── test_api.py # test files ├── docker-compose.yml # docker-compose file ├── Dockerfile # dockerfile ├── LICENSE # MIT license ├── Makefile # Makefile to apply Python linters ├── mypy.ini # type checking configs ├── requirements.txt # app dependencies └── requirements-dev.txt # development dependencies
Python
복사
├── app │ ├── __init__.py │ ├── api ----> NEW │ │ ├── __init__.py │ │ ├── api_v1 ----> NEW │ │ │ ├── __init__.py │ │ │ ├── api.py ----> NEW │ │ │ └── endpoints ----> NEW │ │ │ ├── __init__.py │ │ │ └── recipe.py ----> NEW │ │ └── deps.py │ ├── backend_pre_start.py │ ├── core ----> NEW │ │ ├── __init__.py │ │ └── config.py ----> │ ├── crud │ │ ├── __init__.py │ │ ├── base.py │ │ ├── crud_recipe.py │ │ └── crud_user.py │ ├── db │ │ ├── __init__.py │ │ ├── base.py │ │ ├── base_class.py │ │ ├── init_db.py │ │ └── session.py │ ├── initial_data.py │ ├── main.py ----> UPDATED │ ├── models │ │ ├── __init__.py │ │ ├── recipe.py │ │ └── user.py │ ├── schemas │ │ ├── __init__.py │ │ ├── recipe.py │ │ └── user.py │ └── templates │ └── index.html ├── poetry.lock ├── prestart.sh ├── pyproject.toml ├── README.md └── run.sh
Python
복사

Reference

fastapi-boilerplate
KimKiHyuk