fastapi-basic 0.0.7__py3-none-any.whl → 0.0.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fastapi-basic might be problematic. Click here for more details.
- fastapi_basic/base_factory.py +35 -14
- {fastapi_basic-0.0.7.dist-info → fastapi_basic-0.0.9.dist-info}/METADATA +3 -2
- fastapi_basic-0.0.9.dist-info/RECORD +9 -0
- {fastapi_basic-0.0.7.dist-info → fastapi_basic-0.0.9.dist-info}/WHEEL +1 -1
- fastapi_basic-0.0.7.dist-info/RECORD +0 -9
- {fastapi_basic-0.0.7.dist-info → fastapi_basic-0.0.9.dist-info}/top_level.txt +0 -0
fastapi_basic/base_factory.py
CHANGED
|
@@ -2,7 +2,9 @@ from abc import ABCMeta, abstractmethod
|
|
|
2
2
|
from functools import lru_cache
|
|
3
3
|
import os, dotenv
|
|
4
4
|
|
|
5
|
-
from fastapi import FastAPI
|
|
5
|
+
from fastapi import FastAPI, Request
|
|
6
|
+
from fastapi.middleware.cors import CORSMiddleware
|
|
7
|
+
from starlette.concurrency import iterate_in_threadpool
|
|
6
8
|
import logging
|
|
7
9
|
|
|
8
10
|
from .const import LOG_DEFAULT_LOGGER_NAME, LOG_FMT
|
|
@@ -16,19 +18,6 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
16
18
|
Each factory should define what config it wants.
|
|
17
19
|
"""
|
|
18
20
|
|
|
19
|
-
def create_app(self):
|
|
20
|
-
"""
|
|
21
|
-
Create an application instance.
|
|
22
|
-
"""
|
|
23
|
-
self.__load_local_config()
|
|
24
|
-
app_config = self.get_app_config()
|
|
25
|
-
app = FastAPI(docs_url=app_config.get('DOCS_URL'), redoc_url=app_config.get('REDOC_URL'), openapi_url=app_config.get('OPENAPI_URL'))
|
|
26
|
-
app.state.config = app_config
|
|
27
|
-
|
|
28
|
-
self.__setup_main_logger(app, logger_name=app.state.config.get('LOGGER_NAME', LOG_DEFAULT_LOGGER_NAME), level=logging.DEBUG)
|
|
29
|
-
|
|
30
|
-
return app
|
|
31
|
-
|
|
32
21
|
def __load_local_config(self):
|
|
33
22
|
dotenv.load_dotenv(dotenv_path='.env', override=True)
|
|
34
23
|
update_dict_with_cast(self.get_app_config(), os.environ)
|
|
@@ -45,3 +34,35 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
45
34
|
stream_handler.setFormatter(logging.Formatter(LOG_FMT))
|
|
46
35
|
logger.addHandler(stream_handler)
|
|
47
36
|
return logger
|
|
37
|
+
|
|
38
|
+
def create_app(self):
|
|
39
|
+
"""
|
|
40
|
+
Create an application instance.
|
|
41
|
+
"""
|
|
42
|
+
self.__load_local_config()
|
|
43
|
+
app_config = self.get_app_config()
|
|
44
|
+
app = FastAPI(docs_url=app_config.get('DOCS_URL'), redoc_url=app_config.get('REDOC_URL'), openapi_url=app_config.get('OPENAPI_URL'))
|
|
45
|
+
app.state.config = app_config
|
|
46
|
+
|
|
47
|
+
app.add_middleware(
|
|
48
|
+
CORSMiddleware,
|
|
49
|
+
allow_origins=['*'],
|
|
50
|
+
allow_credentials=True,
|
|
51
|
+
allow_methods=['*'],
|
|
52
|
+
allow_headers=['*'],
|
|
53
|
+
)
|
|
54
|
+
self.__setup_main_logger(app, logger_name=app.state.config.get('LOGGER_NAME', LOG_DEFAULT_LOGGER_NAME), level=logging.DEBUG)
|
|
55
|
+
|
|
56
|
+
@app.middleware("http")
|
|
57
|
+
async def handle_request_headers(request: Request, call_next):
|
|
58
|
+
body = await request.body()
|
|
59
|
+
form = await request.form()
|
|
60
|
+
app.logger.info(f"request.url: {request.url}, method: {request.method}, headers: {request.headers}, body: {body}, form: {form}")
|
|
61
|
+
response = await call_next(request)
|
|
62
|
+
response_body = [section async for section in response.body_iterator]
|
|
63
|
+
response.body_iterator = iterate_in_threadpool(iter(response_body))
|
|
64
|
+
if response_body:
|
|
65
|
+
app.logger.info(f"response_body: {response_body[0].decode()}")
|
|
66
|
+
return response
|
|
67
|
+
|
|
68
|
+
return app
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi_basic
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.9
|
|
4
4
|
Summary: A short description of your module
|
|
5
5
|
Home-page: https://github.com/szx21023/fastapi-base
|
|
6
6
|
Author: szx21023
|
|
@@ -22,6 +22,7 @@ Requires-Dist: idna==3.10
|
|
|
22
22
|
Requires-Dist: pydantic==2.11.3
|
|
23
23
|
Requires-Dist: pydantic_core==2.33.1
|
|
24
24
|
Requires-Dist: python-dotenv==1.1.0
|
|
25
|
+
Requires-Dist: python-multipart==0.0.20
|
|
25
26
|
Requires-Dist: requests==2.32.3
|
|
26
27
|
Requires-Dist: sniffio==1.3.1
|
|
27
28
|
Requires-Dist: starlette==0.46.1
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
fastapi_basic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
fastapi_basic/base_config.py,sha256=_AMa1BDpCw0e00BUYKzOGVBjHrbAR5WfIWwlRS_Dmug,273
|
|
3
|
+
fastapi_basic/base_factory.py,sha256=nBBLX2ymqLoKTHnJTl9pw9JsJiB6LX4auhLSvU3x_bw,2584
|
|
4
|
+
fastapi_basic/const.py,sha256=UA7-Eefu_dbWpbFn09Ei_BPb903SExnCgVbnm8_3ALE,99
|
|
5
|
+
fastapi_basic/utils.py,sha256=8ympyQIXsKkxLILTI_7ug85vmKWYKqX0mpADjgHekgU,306
|
|
6
|
+
fastapi_basic-0.0.9.dist-info/METADATA,sha256=3iluGrKgnnrC3p6HMuXZGaxm3ZrB8lGgCWc8EGwrr2s,1508
|
|
7
|
+
fastapi_basic-0.0.9.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
8
|
+
fastapi_basic-0.0.9.dist-info/top_level.txt,sha256=Q9PdwWxaB4dy135MQHiroRYOqArdUSaIeEkzYinN6W0,14
|
|
9
|
+
fastapi_basic-0.0.9.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
fastapi_basic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
fastapi_basic/base_config.py,sha256=_AMa1BDpCw0e00BUYKzOGVBjHrbAR5WfIWwlRS_Dmug,273
|
|
3
|
-
fastapi_basic/base_factory.py,sha256=0gawoXixPHFgluJZ0MQ51dgK2MkzGd5b9yqBBQ7W6p0,1595
|
|
4
|
-
fastapi_basic/const.py,sha256=UA7-Eefu_dbWpbFn09Ei_BPb903SExnCgVbnm8_3ALE,99
|
|
5
|
-
fastapi_basic/utils.py,sha256=8ympyQIXsKkxLILTI_7ug85vmKWYKqX0mpADjgHekgU,306
|
|
6
|
-
fastapi_basic-0.0.7.dist-info/METADATA,sha256=1WOrwj0c-fZyxV0UpRgRnwMHqjEFlNUjRODelTli1No,1468
|
|
7
|
-
fastapi_basic-0.0.7.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
8
|
-
fastapi_basic-0.0.7.dist-info/top_level.txt,sha256=Q9PdwWxaB4dy135MQHiroRYOqArdUSaIeEkzYinN6W0,14
|
|
9
|
-
fastapi_basic-0.0.7.dist-info/RECORD,,
|
|
File without changes
|