This repository contains an advanced generic template app using the Flask framework.
You can automatically generate marshmallow schemas by using the add_schema()
decorator on your models.
@add_schema(
meta=[
"exclude": ["password"]
],
custom_field=ma.String(...)
)
class User(BaseModel):
name: str = db.Column(db.String())
password: str = db.Column(db.String())
Similarily You can automatically generate views for you models by using the add_view()
decorator.
This will generate default REST endpoints to perform CRUD operations for the model.
Protect your views and endpoints by using the decorator auth.auth_required
and auth.roles_required(*roles)
.
It also features the following extensions:
- flask-smorest
- flask-praetorian
- SQLAlchemy
- SQLAlchemy-Mixins
- Marshmallow
- SocketIO
- APScheduler
This template is intended to be used with Visual Studio Code.
When opening the project, a new virtual environment will be created and the Flask server will be started.
The task can also be (re)started by using the shortcut Ctrl+Shift+B
.
The default config file path is config/config.yml
.
To add more configuration options simply extend src/config.py
.
Logging is done with python's default logging
library. Logs are outputted by default in the console and also to logs/app.log
.
The default database path is data/app.sqlite
.
Models are defined in src/models
and should inherit from the BaseModel
class in src/models/base_model.py
.
Tests can be defined in src/tests/
and are automatically discovered by the VS Code Test Explorer.
SocketIO events should be implemented in src/events
.
- Add template tests
- Add Github workflows