Skip to content

Commit 9d22cd5

Browse files
Kilo59ExpDev07
andauthored
Fast api conversion (#4)
* add FastAPI uvicorn * define app * create provisional models * define latest, location endpoints * update models * change model name to match pre-existing model * defaults * update versions and response models * divide sections * create middleware to attach the "data_source" https://www.starlette.io/requests/#other-state * validation exception handler * get location by id * WIP get_all_locations * add Totals * Mount v2 of the application * add FIXME for timelines * end of file newlines * move models to models.py * exclude unset * gunicorn with FastAPI * change version name * create Sources enum * expose v1 and v2 apis via mounted WSGI app * lock dependencies for linux machines * specify python 3.8 runtime for Heroku * add sources and make Timelines a boolean * add sources * update prefix * use separate v2 router Co-authored-by: ExpDev <[email protected]>
1 parent 3009428 commit 9d22cd5

File tree

8 files changed

+355
-83
lines changed

8 files changed

+355
-83
lines changed

Pipfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ pytest = "*"
99
pylint = "*"
1010

1111
[packages]
12+
fastapi = "*"
1213
flask = "*"
1314
python-dotenv = "*"
1415
requests = "*"
1516
gunicorn = "*"
1617
flask-cors = "*"
1718
cachetools = "*"
1819
python-dateutil = "*"
20+
uvicorn = "*"
1921

2022
[requires]
2123
python_version = "3.8"
24+
25+
[scripts]
26+
dev_app = "uvicorn app.main:APP --reload"
27+
app = "uvicorn app.main:APP"

Pipfile.lock

Lines changed: 125 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: gunicorn app:create_app\(\)
1+
web: gunicorn app.main:APP -k uvicorn.workers.UvicornWorker

app/__init__.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,4 @@
1-
from flask import Flask
2-
from flask_cors import CORS
3-
41
# See PEP396.
52
__version__ = '2.0'
63

7-
def create_app():
8-
"""
9-
Construct the core application.
10-
"""
11-
# Create flask app with CORS enabled.
12-
app = Flask(__name__)
13-
CORS(app)
14-
15-
# Set app config from settings.
16-
app.config.from_pyfile('config/settings.py');
17-
18-
with app.app_context():
19-
# Import routes.
20-
from . import routes
21-
22-
# Register api endpoints.
23-
app.register_blueprint(routes.api_v1)
24-
app.register_blueprint(routes.api_v2)
25-
26-
# Return created app.
27-
return app
4+
from .core import create_app

app/core.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from flask import Flask
2+
from flask_cors import CORS
3+
4+
def create_app():
5+
"""
6+
Construct the core application.
7+
"""
8+
# Create flask app with CORS enabled.
9+
app = Flask(__name__)
10+
CORS(app)
11+
12+
# Set app config from settings.
13+
app.config.from_pyfile('config/settings.py');
14+
15+
with app.app_context():
16+
# Import routes.
17+
from . import routes
18+
19+
# Register api endpoints.
20+
app.register_blueprint(routes.api_v1)
21+
app.register_blueprint(routes.api_v2)
22+
23+
# Return created app.
24+
return app

0 commit comments

Comments
 (0)