Featured
- Get link
- X
- Other Apps
๐ Ottasker Flask Template – The Ultimate Starter Kit for Flask Developers
๐ก What is Ottasker Flask Template?
The Ottasker Flask Template is a pre-built, production-ready starter kit for Python's Flask framework. It provides you with everything you need to kickstart your Flask project without reinventing the wheel.
✨ Key Features
Here’s why Ottasker Flask Template stands out:
-
Modular Structure: Built with Flask blueprints for better scalability.
-
Database Integration: MySQL-ready with easy configuration.
-
Logging System: Integrated logging for better debugging and monitoring.
-
Environment Configuration: Secure your credentials with
.envvariables. -
Reusable Components: Pre-configured routes, templates, and utilities.
-
Rapid Setup: Start coding your core logic in under 5 minutes.
๐ Quick Start Guide
-
Download
-
Install Dependencies
python setup.py -
Run the Application : python app.py
Your Flask project is now up and running! ๐
Why Choose Ottasker Flask Template?
-
Saves Development Time: No more setting up repetitive boilerplate code.
-
Encourages Best Practices: Standardized structure for professional projects.
-
Beginner-Friendly: Perfect for learning Flask and building real-world apps.
-
Scalable: Easily extendable as your project grows.
๐ Documentation
๐ setup.py – Project Initialization Script
This script is designed to automate the initial setup of your Python project. It ensures that all required dependencies are installed and that the necessary directory structure is created before running the application.
๐งฉ Purpose
✅ Install Required Packages
Automatically installs any missing dependencies usingpip.๐ Set Up Project Folders
Creates essential folders (e.g.,logs/,uploads/, etc.) to prevent runtime errors due to missing directories.
๐ Code Overview
from configs.checkingintro import check_and_install_requirements, setUpingFolders
if __name__ == '__main__':
check_and_install_requirements()
setUpingFolders()
๐ app.py – Main Entry Point of the Flask Application
The app.py file is the heart of your Flask application. It initializes the Flask app, configures logging, registers blueprints, and runs the server.
๐ What It Typically Contains
1. Importing Dependencies
from flask import Flask
from configs.logger import LogInstance
---
⚙️ setting.json – Centralized Configuration File
The setting.json file is a central configuration hub for your Flask application. It allows you to define and manage environment-specific and app-level settings in a structured and easily editable format.
๐ File Structure Overview
{
"file_location": "C:/",
"database": {
"db": "tut",
"host": "localhost",
"password": "12345",
"username": "root",
"port": "3306"
},
"appname": "flaskOS",
"mailpassword": "",
"secure": true,
"secret_key": "your_secret_key_here",
"cross_orgins": [
"http://127.0.0.1:5000"
]
}
๐ฆ Reading the JSON: utils/settingsreader.py
This script is responsible for loading configuration data from the setting.json file so it can be used throughout your app.
utils/settingsreader.py
import json
path = "./setting.json"
def propReader():
data = None
with open(path) as json_file:
data = json.load(json_file)
return data
✅ Usage Example
from utils.settingsreader import propReader
settings = propReader()
db_config = settings["database"]
file_path = settings["file_location"]
This makes your app:
✅ More flexible
๐ ️ Easier to configure per environment
๐ฆ Keeps code clean by avoiding hardcoded values
๐ Best Practice Tip
Never hardcode passwords or secret keys in source files. For production, use environment variables or encrypted secrets managers.Let me know if you'd like a versioned loader for dev/prod environments or validation for required keys.
๐งญ Blueprint Configuration in Flask
This file defines how Flask Blueprints are used to modularize and organize the routing structure of the application.
๐ File Overview : configs\routingconfig.py
# Blue Print for the routing configuration
from flask import Blueprint
from routers.routeexample import loginController
def init_Blueprint(app):
# Create a blueprint for the routing configuration
# Import the route example module and register it with the blueprint
app.register_blueprint(loginController, url_prefix="/usercontroller")
# Add more blueprints as needed
๐งฉ What is a Blueprint?
A Blueprint in Flask is a way to organize your application into modules. It helps split routes, models, views, etc., into separate files or packages, making large applications more maintainable and scalable.
๐ Function: init_Blueprint(app)
This function is called during app initialization (usually in app.py) to register all necessary route modules (blueprints) with the Flask app.
✅ Key Responsibilities:
Imports loginController from routers.routeexample
Registers it under the URL prefix /usercontroller
Prepares your app to add more modular route handlers in the future
๐งพ Common Response Model – model/commonresponsemodel.py
This file defines a standard response structure used across the Flask application to maintain consistency and clarity in all API responses.
๐ File Overview
from flask import jsonify
def createResponse(rescode, response):
return jsonify(response.createDictionarie, rescode)
๐น Purpose: The createResponse function takes a status code and a response object (instance of CommonRequestModel) and returns a Flask jsonify() response using the structured data from the object.
๐งฉ Class: CommonRequestModel
class CommonRequestModel:
def __init__(self, message, code, data, stcodes=None):
self.message = message
self.code = code
self.data = data
self.stcode = stcodes
๐น Parameters:
- message: A string describing the result of the API call.
- code: A custom code to classify the type of response (e.g., 1001 for success).
- data: The actual response payload.
๐น Purpose:
The createResponse function takes a status code and a response object (instance of CommonRequestModel) and returns a Flask jsonify() response using the structured data from the object.
✅ Example Usage
Constructing a response manually:
from model.commonresponsemodel import CommonRequestModel response_model = CommonRequestModel( message="Data fetched successfully", code=1001, data={"user": "John Doe"}, stcodes=200 ) return response_model.createDictionari_respo()- Using createResponse wrapper:
return createResponse(200, response_model)๐ก Benefits
✅ Consistent API responses for frontend integration
✅ Easy to debug and extend
✅ Centralized format handling
๐งพ LogInstance – Centralized Logging Utility for Flask
The LogInstance class provides a reusable logging utility that integrates with Flask and supports centralized logging configuration using Python's logging module.
๐ฏ Purpose
This class encapsulates the logic for:
- Loading logging configuration from
LOGGING_CONFIG - Attaching log handlers to the Flask app
- Providing simple methods for logging at different severity levels
๐ ️ Code Breakdown
import logging
import logging.config
from flask import Flask
from configs.checkingintro import LOGGING_CONFIG
๐ Class: LogInstance
init(self, app: Flask = None)
- Applies the logging configuration using dictConfig.
- Retrieves a named logger FlaskAppLogger.
- Optionally initializes with the Flask app instance.
init_app(self, app: Flask)
- Overrides Flask’s default logger with the one configured here.
- Ensures all logs go through the centralized logger.
Logging Methods
logger_info(message, file=None)Logs info-level messages. If file is provided, prepends it to the message.logger_error(message, file=None)Logs error-level messages.logger_warning(message, file=None)Logs warning-level messages.
Usage
in app.py
from flask import Flask
from configs.logger import LogInstance
app = Flask(__name__)
logger = LogInstance(app)
logger.logger_info("Server started successfully")
In other routine blueprint
from utils.logger import LogInstance
logg= LogInstance()
@loginController.route("/")
def index():
logg.logger_info(message="hello starter", file="logincontroller")
return "hello"
LOGGING_CONFIG
Typically loaded from configs/checkingintro.py:
LOGGING_CONFIG = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'detailed': {
'format': '[%(asctime)s] [%(levelname)s] %(name)s: %(message)s',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'detailed',
},
'file': {
'class': 'logging.FileHandler',
'formatter': 'detailed',
'filename': 'app.log',
},
},
'root': {
'handlers': ['console', 'file'],
'level': 'INFO',
},
}
✅ Benefits
- Centralized log control for all app modules.
- Easily extendable for more advanced handlers (email, rotating files, etc.).
- Clean separation of configuration and logic.
๐ Final Developer Note
Thank you for exploring and using the Ottasker Flask Template!
This project aims to give developers a head start by providing a well-structured Flask boilerplate with:
- ๐ฆ Modular Blueprint Configuration
- ๐งฉ Consistent Request & Response Models
- ๐ก️ JWT Integration
- ๐ CORS Management
- ๐ JSON-based Settings
- ๐ Robust Logging System
Whether you're building a simple prototype or scaling a full-fledged application, this template is designed to be flexible, extensible, and developer-friendly.
If you found this helpful and saved some hours of work, consider supporting the creator ๐๐
Happy coding! ๐
- Get link
- X
- Other Apps
Popular Posts
Stress Testing web application with JMeter HTTP(S) Test Script Recorder
- Get link
- X
- Other Apps

Comments
Post a Comment