Introduction¶
This is the introduction section. How to create a project and an explanation of the application structure.
Create a new project¶
Application structure¶
We followed the project layout from the FastAPI documentation here https://fastapi.tiangolo.com/tutorial/bigger-applications/ with a few additions like changing the routers folder to controllers.
$ tree your-project -I __pycache__
your-project
├── app
│ ├── commands
│ │ ├── __init__.py
│ │ └── user.py
│ ├── controllers
│ │ ├── dummy
│ │ │ ├── __init__.py
│ │ │ └── serializers.py
│ │ └── __init__.py
│ ├── __init__.py
│ ├── main.py
│ ├── models.py
│ ├── plugins
│ │ └── __init__.py
│ └── settings
│ ├── development.py
│ ├── __init__.py
│ ├── local.py
│ └── production.py
├── docker-compose.yml
├── Dockerfile
├── entrypoint.sh
├── Pipfile
└── README.md
app: Location of your applicationapp/commands: A place to add your commands. Want to jump?app/controllers: Location of REST APIs. Want to jump?app/main.py: FastAPI Appapp/models.py: A place to create (Model with SQLModel) or (Document with MongoEngine)app/plugins: A place to make your own plugins. Want to jump?app/settings: Your app configuration listdocker-compose.yml,Dockerfile,entrypoint.sh: A file for bundling your app into a docker container.Pipfile: We usepipenvas the package manager.README.md: Short description to run your app
Now run your app:
To run the app you can use the command fastack runserver or use uvicorn directly.
Warning
Don't use fastack runserver in a production environment!
Application settings¶
By default the app settings will use the local settings stored in app/settings/local.py.
How do we use other settings? e.g. in a production environment.
To select the app settings for a specific environment, you can add the APP_ENV environment with a filename value that is in the app/settings directory. For example:
It will use the settings from app/settings/production.py. That's it :)