-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.py
42 lines (32 loc) · 1.18 KB
/
init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
This module initializes a Flask application with various extensions and configuration settings.
"""
# Import statements
from os import environ
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase
from flask_marshmallow import Marshmallow
from flask_bcrypt import Bcrypt
from flask_jwt_extended import JWTManager
# Create a base class for all SQLAlchemy models
class Base(DeclarativeBase):
"""
Base class for all SQLAlchemy models in the application.
"""
pass
# Initialize Flask application by creating an instance of Flask class
app = Flask(__name__)
# Set JWT_SECRET_KEY from environment variable JWT_KEY
app.config['JWT_SECRET_KEY'] = environ.get("JWT_KEY")
# Set the database URI from the environment variable
app.config["SQLALCHEMY_DATABASE_URI"] = environ.get("DB_URI")
# Initialize SQLAlchemy with the Flask application
db = SQLAlchemy(model_class=Base)
db.init_app(app)
# Creating an instance of Marshmallow class and passing in the flask app
ma = Marshmallow(app)
# Initialize Bcrypt extension for password hashing in Flask
bcrypt = Bcrypt(app)
# Initialize JWTManager with the Flask application
jwt = JWTManager(app)