fastapi-basic 0.0.6__py3-none-any.whl → 0.0.8__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_config.py +4 -1
- fastapi_basic/base_factory.py +36 -5
- fastapi_basic/const.py +2 -0
- {fastapi_basic-0.0.6.dist-info → fastapi_basic-0.0.8.dist-info}/METADATA +3 -2
- fastapi_basic-0.0.8.dist-info/RECORD +9 -0
- {fastapi_basic-0.0.6.dist-info → fastapi_basic-0.0.8.dist-info}/WHEEL +1 -1
- fastapi_basic-0.0.6.dist-info/RECORD +0 -8
- {fastapi_basic-0.0.6.dist-info → fastapi_basic-0.0.8.dist-info}/top_level.txt +0 -0
fastapi_basic/base_config.py
CHANGED
fastapi_basic/base_factory.py
CHANGED
|
@@ -2,8 +2,11 @@ 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 starlette.concurrency import iterate_in_threadpool
|
|
7
|
+
import logging
|
|
6
8
|
|
|
9
|
+
from .const import LOG_DEFAULT_LOGGER_NAME, LOG_FMT
|
|
7
10
|
from .utils import update_dict_with_cast
|
|
8
11
|
|
|
9
12
|
class BaseFactory(metaclass=ABCMeta):
|
|
@@ -14,6 +17,23 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
14
17
|
Each factory should define what config it wants.
|
|
15
18
|
"""
|
|
16
19
|
|
|
20
|
+
def __load_local_config(self):
|
|
21
|
+
dotenv.load_dotenv(dotenv_path='.env', override=True)
|
|
22
|
+
update_dict_with_cast(self.get_app_config(), os.environ)
|
|
23
|
+
|
|
24
|
+
def __setup_main_logger(self, app, logger_name=LOG_DEFAULT_LOGGER_NAME, level=logging.DEBUG):
|
|
25
|
+
logger = self.__setup_logger(app, logger_name, level)
|
|
26
|
+
app.logger = logger
|
|
27
|
+
|
|
28
|
+
def __setup_logger(self, app, logger_name, level=logging.INFO):
|
|
29
|
+
logger = logging.getLogger(logger_name)
|
|
30
|
+
logger.setLevel(level)
|
|
31
|
+
|
|
32
|
+
stream_handler = logging.StreamHandler()
|
|
33
|
+
stream_handler.setFormatter(logging.Formatter(LOG_FMT))
|
|
34
|
+
logger.addHandler(stream_handler)
|
|
35
|
+
return logger
|
|
36
|
+
|
|
17
37
|
def create_app(self):
|
|
18
38
|
"""
|
|
19
39
|
Create an application instance.
|
|
@@ -22,8 +42,19 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
22
42
|
app_config = self.get_app_config()
|
|
23
43
|
app = FastAPI(docs_url=app_config.get('DOCS_URL'), redoc_url=app_config.get('REDOC_URL'), openapi_url=app_config.get('OPENAPI_URL'))
|
|
24
44
|
app.state.config = app_config
|
|
25
|
-
return app
|
|
26
45
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
46
|
+
self.__setup_main_logger(app, logger_name=app.state.config.get('LOGGER_NAME', LOG_DEFAULT_LOGGER_NAME), level=logging.DEBUG)
|
|
47
|
+
|
|
48
|
+
@app.middleware("http")
|
|
49
|
+
async def handle_request_headers(request: Request, call_next):
|
|
50
|
+
body = await request.body()
|
|
51
|
+
form = await request.form()
|
|
52
|
+
app.logger.info(f"request.url: {request.url}, method: {request.method}, headers: {request.headers}, body: {body}, form: {form}")
|
|
53
|
+
response = await call_next(request)
|
|
54
|
+
response_body = [section async for section in response.body_iterator]
|
|
55
|
+
response.body_iterator = iterate_in_threadpool(iter(response_body))
|
|
56
|
+
if response_body:
|
|
57
|
+
app.logger.info(f"response_body: {response_body[0].decode()}")
|
|
58
|
+
return response
|
|
59
|
+
|
|
60
|
+
return app
|
fastapi_basic/const.py
ADDED
|
@@ -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.8
|
|
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=3SFewCi2SKpvAZp5kjpGYz_hTxqS_WJa0ecEBicq9mc,2332
|
|
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.8.dist-info/METADATA,sha256=w9LeU9tlfQRfa2whpukhvTotXOZDDdtxC4A1r8nuxi4,1508
|
|
7
|
+
fastapi_basic-0.0.8.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
8
|
+
fastapi_basic-0.0.8.dist-info/top_level.txt,sha256=Q9PdwWxaB4dy135MQHiroRYOqArdUSaIeEkzYinN6W0,14
|
|
9
|
+
fastapi_basic-0.0.8.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
fastapi_basic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
fastapi_basic/base_config.py,sha256=UkW7g0oHkkNZQkX-jxZvY4FGCOt529lQw7sVYgM4vrw,213
|
|
3
|
-
fastapi_basic/base_factory.py,sha256=5Gfm7bKT-SoFeVsmb1OFgsCw2yBOXQxDjMFIRlHv8eA,878
|
|
4
|
-
fastapi_basic/utils.py,sha256=8ympyQIXsKkxLILTI_7ug85vmKWYKqX0mpADjgHekgU,306
|
|
5
|
-
fastapi_basic-0.0.6.dist-info/METADATA,sha256=okes-0U_5kvnpNjs5_GXvjLc-Aj-ycvD47ESlz1jIfk,1468
|
|
6
|
-
fastapi_basic-0.0.6.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
7
|
-
fastapi_basic-0.0.6.dist-info/top_level.txt,sha256=Q9PdwWxaB4dy135MQHiroRYOqArdUSaIeEkzYinN6W0,14
|
|
8
|
-
fastapi_basic-0.0.6.dist-info/RECORD,,
|
|
File without changes
|