A flask app with the following features and concepts implemented,
- User sign up using full name and email
- Email randomly generated password on sign up
- Sign in the user using randomly generated password
- Token based authentication for the RESTful APIs
- Filtering, Pagination and Sorting for RESTful APIs
- Flask, SQLAlchemy, Marshmallow based RESTful CRUD APIs
- Data validation on POST/PUT RESTful APIs
- Users session management with Redis
- Redis connection pool configuariton and handling
- SQLAlchemy connection pool configuariton and handling
- Flask based app project folders and files structure
The app is using following tools and technologies,
Tools & Technologies | Description |
---|---|
Flask | A micro web framework based on Python. |
MySQL | An open-source relational database. |
SQLAlchemy | An open-source object-relational mapper for python. |
Marshmallow | A python library for data validation, serialization and deserialization. |
Redis | An open source in-memory data structure store. |
Docker | An open source containerization platform. |
flask-sample-app/ # Project foler
app/
middlewares/ # It contains decorator files.
__init__.py
middleware_files.py
blueprints/ # It contains restful api endpoints files.
__init__.py
blueprints_files.py
schemas/ # It contains schemas files for data validation, serialization and desrialization.
__init__.py
schemas_files.py
models/ # It contains ORM models files.
__init__.py
models_files.py
utils/ # It contains common utils funcs files.
__init__.py
utils_files.py
core/ # It contains core settings files for App or database.
__init__.py
core_files.py
main.py # It's the main app file.
.env
requirements.txt
docker-compose.yml
The RESTful APIs postman collection for the sample project is available as well as the documentation.
The RESTful API endpoints are as follows,
- Temporary API endpoint,
- [GET] / : hello world!
- RESTful API endpoints for database status,
- [GET] /db_status : show database status
- RESTful API endpoints for signup/signin/signout,
- [POST] accounts/signup : signup user
- [POST] accounts/signin : signin user
- [GET] accounts/signout : signout user
- RESTful API endpoints for users session management,
- [GET] accounts/sessions : user sessions count including current
- [DELETE] accounts/sessions : delete user sessions except current
- RESTful API endpoints for vehicle categories,
- [GET] categories/ : list categories
- [POST] categories/ : create category
- [GET] categories/<category_id> : view category
- [PUT] categories/<category_id> : update category
- [DELETE] categories/<category_id> : delete category
- RESTful API endpoints for vehicles,
- [GET] vehicles/ : list vehicles
- [POST] vehicles/ : create vehicle
- [GET] vehicles/<vehicle_id> : view vehicle
- [PUT] vehicles/<vehicle_id> : update vehicle
- [DELETE] vehicles/<vehicle_id> : delete vehicle
virtualenv venv
source venv/bin/activate
pip install flask sqlalchemy marshmallow PyMySQL[rsa] pyjwt[crypto] python-dotenv flask-cors redis
#or
pip install -r requirements.txt
docker compose up -d
# Set flask variables.
HOST = '0.0.0.0'
PORT = 5000
# Set database variables.
DB_HOST = 'DB_HOST'
DB_NAME = 'DB_NAME'
DB_PORT = 'DB_PORT'
DB_USERNAME = 'DB_USERNAME'
DB_PASSWORD = 'DB_PASSWORD'
# Set mail server variables.
MAIL_SERVER = 'MAIL_SERVER'
MAIL_PORT = 'MAIL_PORT'
EMAIL_ADDRESS = 'EMAIL_ADDRESS'
EMAIL_PASSWORD = 'EMAIL_PASSWORD'
# Set RSA512 encryption keys.
RSA_PRIVATE_KEY = 'RSA_PRIVATE_KEY'
RSA_PUBLIC_KEY = 'RSA_PUBLIC_KEY'
export FLASK_ENV=development
python app/main.py