-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
42 lines (36 loc) · 1.62 KB
/
app.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
42
from dotenv import dotenv_values
from flask import Flask
from flask_jwt_extended import JWTManager
from flask_restx import Api
from flask_sqlalchemy import SQLAlchemy
env = dotenv_values(".env")
class Config:
MYSQL_USERNAME = env["MYSQL_USERNAME"]
MYSQL_PASSWORD = env["MYSQL_PASSWORD"]
MYSQL_HOST = env["MYSQL_HOST"]
MYSQL_PORT = env["MYSQL_PORT"]
MYSQL_DB = env["MYSQL_DB"]
SQLALCHEMY_DATABASE_URL = f"mysql+mysqlconnector://{Config.MYSQL_USERNAME}:{Config.MYSQL_PASSWORD}@" \
f"{Config.MYSQL_HOST}:{Config.MYSQL_PORT}/{Config.MYSQL_DB}"
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URL
app.config['JWT_SECRET_KEY'] = 'your_secret_key'
description = (
'A simple Flask REST API App with JWT Authentication and SQLAlchemy ORM '
'integration with MySQL database backend and Swagger UI for API documentation and testing purposes. \n'
'Author: @MicBun (Michael Buntarman)\n'
'Repository: https://github.com/MicBun/flask-rest-api-jwt-auth-mysql\n'
'LinkedIn: https://www.linkedin.com/in/micbun'
)
rest_app = Api(app=app, version='1.0',
title='Flask REST API with Flask-RESTX, Flask-SQLAlchemy, JWT Auth, and MySQL',
description=description)
product_space = rest_app.namespace('Product', description="CRUD Product")
order_space = rest_app.namespace('Order', description="CRUD Order")
database_space = rest_app.namespace('Database', description="Database")
user_space = rest_app.namespace('Users', description="CRUD User")
db = SQLAlchemy(app)
jwt = JWTManager(app)
from router import *
if __name__ == '__main__':
app.run()