fastapi-basic 0.0.9__tar.gz → 0.0.11__tar.gz
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-0.0.9 → fastapi_basic-0.0.11}/PKG-INFO +8 -1
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/fastapi_basic/base_config.py +8 -1
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/fastapi_basic/base_factory.py +27 -1
- fastapi_basic-0.0.11/fastapi_basic/exception/__init__.py +0 -0
- fastapi_basic-0.0.11/fastapi_basic/exception/base_exception.py +13 -0
- fastapi_basic-0.0.11/fastapi_basic/ext/__init__.py +0 -0
- fastapi_basic-0.0.11/fastapi_basic/ext/aws/__init__.py +24 -0
- fastapi_basic-0.0.11/fastapi_basic/ext/aws/const.py +1 -0
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/fastapi_basic.egg-info/PKG-INFO +8 -1
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/fastapi_basic.egg-info/SOURCES.txt +6 -1
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/fastapi_basic.egg-info/requires.txt +7 -0
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/setup.py +1 -1
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/README.md +0 -0
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/fastapi_basic/__init__.py +0 -0
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/fastapi_basic/const.py +0 -0
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/fastapi_basic/utils.py +0 -0
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/fastapi_basic.egg-info/dependency_links.txt +0 -0
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/fastapi_basic.egg-info/top_level.txt +0 -0
- {fastapi_basic-0.0.9 → fastapi_basic-0.0.11}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi_basic
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.11
|
|
4
4
|
Summary: A short description of your module
|
|
5
5
|
Home-page: https://github.com/szx21023/fastapi-base
|
|
6
6
|
Author: szx21023
|
|
@@ -12,6 +12,8 @@ Requires-Python: >=3.6
|
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
Requires-Dist: annotated-types==0.7.0
|
|
14
14
|
Requires-Dist: anyio==4.9.0
|
|
15
|
+
Requires-Dist: boto3==1.37.36
|
|
16
|
+
Requires-Dist: botocore==1.37.36
|
|
15
17
|
Requires-Dist: certifi==2025.1.31
|
|
16
18
|
Requires-Dist: charset-normalizer==3.4.1
|
|
17
19
|
Requires-Dist: click==8.1.8
|
|
@@ -19,17 +21,22 @@ Requires-Dist: dotenv==0.9.9
|
|
|
19
21
|
Requires-Dist: fastapi==0.115.12
|
|
20
22
|
Requires-Dist: h11==0.14.0
|
|
21
23
|
Requires-Dist: idna==3.10
|
|
24
|
+
Requires-Dist: jmespath==1.0.1
|
|
22
25
|
Requires-Dist: pydantic==2.11.3
|
|
23
26
|
Requires-Dist: pydantic_core==2.33.1
|
|
27
|
+
Requires-Dist: python-dateutil==2.9.0.post0
|
|
24
28
|
Requires-Dist: python-dotenv==1.1.0
|
|
25
29
|
Requires-Dist: python-multipart==0.0.20
|
|
26
30
|
Requires-Dist: requests==2.32.3
|
|
31
|
+
Requires-Dist: s3transfer==0.11.5
|
|
32
|
+
Requires-Dist: six==1.17.0
|
|
27
33
|
Requires-Dist: sniffio==1.3.1
|
|
28
34
|
Requires-Dist: starlette==0.46.1
|
|
29
35
|
Requires-Dist: typing-inspection==0.4.0
|
|
30
36
|
Requires-Dist: typing_extensions==4.13.1
|
|
31
37
|
Requires-Dist: urllib3==2.3.0
|
|
32
38
|
Requires-Dist: uvicorn==0.34.0
|
|
39
|
+
Requires-Dist: watchtower==3.4.0
|
|
33
40
|
Dynamic: author
|
|
34
41
|
Dynamic: author-email
|
|
35
42
|
Dynamic: classifier
|
|
@@ -7,4 +7,11 @@ class BaseConfig(BaseSettings):
|
|
|
7
7
|
OPENAPI_URL: str|None = '/openapi.json'
|
|
8
8
|
|
|
9
9
|
# Logging config
|
|
10
|
-
LOGGER_NAME: str|None = 'uvicorn'
|
|
10
|
+
LOGGER_NAME: str|None = 'uvicorn'
|
|
11
|
+
|
|
12
|
+
# AWS
|
|
13
|
+
AWS_ACCESS_KEY_ID: str = ""
|
|
14
|
+
AWS_SECRET_KEY: str = ""
|
|
15
|
+
AWS_REGION: str = ""
|
|
16
|
+
AWS_PARAMETER_PATH_PREFIX: str = ""
|
|
17
|
+
AWS_LOGGROUP_NAME: str = ""
|
|
@@ -2,12 +2,16 @@ from abc import ABCMeta, abstractmethod
|
|
|
2
2
|
from functools import lru_cache
|
|
3
3
|
import os, dotenv
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import watchtower
|
|
6
|
+
from fastapi import FastAPI, HTTPException, Request
|
|
7
|
+
from fastapi.responses import JSONResponse
|
|
6
8
|
from fastapi.middleware.cors import CORSMiddleware
|
|
7
9
|
from starlette.concurrency import iterate_in_threadpool
|
|
8
10
|
import logging
|
|
9
11
|
|
|
10
12
|
from .const import LOG_DEFAULT_LOGGER_NAME, LOG_FMT
|
|
13
|
+
from .ext.aws import init_app as init_aws_app
|
|
14
|
+
from .exception.base_exception import InternalBaseException
|
|
11
15
|
from .utils import update_dict_with_cast
|
|
12
16
|
|
|
13
17
|
class BaseFactory(metaclass=ABCMeta):
|
|
@@ -35,6 +39,15 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
35
39
|
logger.addHandler(stream_handler)
|
|
36
40
|
return logger
|
|
37
41
|
|
|
42
|
+
def __setup_aws_cloud_log(self, app):
|
|
43
|
+
if app.state.aws_session and app.state.config.get("AWS_LOGGROUP_NAME"):
|
|
44
|
+
logs_client = app.state.aws_session.client("logs")
|
|
45
|
+
watchtower_handler = watchtower.CloudWatchLogHandler(
|
|
46
|
+
log_group_name=app.state.config.get("AWS_LOGGROUP_NAME"),
|
|
47
|
+
boto3_client=logs_client, create_log_group=True)
|
|
48
|
+
watchtower_handler.setFormatter(logging.Formatter(LOG_FMT))
|
|
49
|
+
app.logger.addHandler(watchtower_handler)
|
|
50
|
+
|
|
38
51
|
def create_app(self):
|
|
39
52
|
"""
|
|
40
53
|
Create an application instance.
|
|
@@ -52,6 +65,19 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
52
65
|
allow_headers=['*'],
|
|
53
66
|
)
|
|
54
67
|
self.__setup_main_logger(app, logger_name=app.state.config.get('LOGGER_NAME', LOG_DEFAULT_LOGGER_NAME), level=logging.DEBUG)
|
|
68
|
+
app.state.aws_session = init_aws_app(app)
|
|
69
|
+
self.__setup_aws_cloud_log(app)
|
|
70
|
+
|
|
71
|
+
@app.exception_handler(InternalBaseException)
|
|
72
|
+
async def http_exception_handler(request: Request, exc: InternalBaseException):
|
|
73
|
+
return JSONResponse(
|
|
74
|
+
status_code=exc.status_code,
|
|
75
|
+
content={
|
|
76
|
+
"code": exc.detail["code"],
|
|
77
|
+
"message": exc.detail["message"],
|
|
78
|
+
"data": exc.detail["data"]
|
|
79
|
+
}
|
|
80
|
+
)
|
|
55
81
|
|
|
56
82
|
@app.middleware("http")
|
|
57
83
|
async def handle_request_headers(request: Request, call_next):
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from fastapi import HTTPException
|
|
2
|
+
from fastapi import status
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class InternalBaseException(HTTPException):
|
|
6
|
+
def __init__(self, status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR, code: str = "internal_server_error",
|
|
7
|
+
message: str = "Internal server error", **kwargs):
|
|
8
|
+
detail = {
|
|
9
|
+
"code": code,
|
|
10
|
+
"message": message,
|
|
11
|
+
"data": kwargs,
|
|
12
|
+
}
|
|
13
|
+
super().__init__(status_code=status_code, detail=detail)
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
|
2
|
+
import boto3
|
|
3
|
+
|
|
4
|
+
from .const import AWS_CONF_KEY
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def init_app(app):
|
|
8
|
+
if not all([app.state.config.get(key) for key in AWS_CONF_KEY]):
|
|
9
|
+
# pylint: disable=no-member
|
|
10
|
+
app.logger.info("Lack AWS credential keys, ignore connect to AWS")
|
|
11
|
+
return None
|
|
12
|
+
|
|
13
|
+
aws_session = boto3.session.Session(
|
|
14
|
+
aws_access_key_id=app.state.config.AWS_ACCESS_KEY_ID,
|
|
15
|
+
aws_secret_access_key=app.state.config.AWS_SECRET_KEY,
|
|
16
|
+
region_name=app.state.config.AWS_REGION
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
# This should be logging when create Logging handlers,
|
|
20
|
+
# But we have too many CloudWatchLogHandler, only print once here.
|
|
21
|
+
if not getattr(app.state.config, "AWS_LOGGROUP_NAME"):
|
|
22
|
+
app.logger.info("Lack AWS configuration keys, ignore AWS CloudWatch log handlers")
|
|
23
|
+
|
|
24
|
+
return aws_session
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
AWS_CONF_KEY = ["AWS_ACCESS_KEY_ID", "AWS_SECRET_KEY", "AWS_REGION"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi_basic
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.11
|
|
4
4
|
Summary: A short description of your module
|
|
5
5
|
Home-page: https://github.com/szx21023/fastapi-base
|
|
6
6
|
Author: szx21023
|
|
@@ -12,6 +12,8 @@ Requires-Python: >=3.6
|
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
Requires-Dist: annotated-types==0.7.0
|
|
14
14
|
Requires-Dist: anyio==4.9.0
|
|
15
|
+
Requires-Dist: boto3==1.37.36
|
|
16
|
+
Requires-Dist: botocore==1.37.36
|
|
15
17
|
Requires-Dist: certifi==2025.1.31
|
|
16
18
|
Requires-Dist: charset-normalizer==3.4.1
|
|
17
19
|
Requires-Dist: click==8.1.8
|
|
@@ -19,17 +21,22 @@ Requires-Dist: dotenv==0.9.9
|
|
|
19
21
|
Requires-Dist: fastapi==0.115.12
|
|
20
22
|
Requires-Dist: h11==0.14.0
|
|
21
23
|
Requires-Dist: idna==3.10
|
|
24
|
+
Requires-Dist: jmespath==1.0.1
|
|
22
25
|
Requires-Dist: pydantic==2.11.3
|
|
23
26
|
Requires-Dist: pydantic_core==2.33.1
|
|
27
|
+
Requires-Dist: python-dateutil==2.9.0.post0
|
|
24
28
|
Requires-Dist: python-dotenv==1.1.0
|
|
25
29
|
Requires-Dist: python-multipart==0.0.20
|
|
26
30
|
Requires-Dist: requests==2.32.3
|
|
31
|
+
Requires-Dist: s3transfer==0.11.5
|
|
32
|
+
Requires-Dist: six==1.17.0
|
|
27
33
|
Requires-Dist: sniffio==1.3.1
|
|
28
34
|
Requires-Dist: starlette==0.46.1
|
|
29
35
|
Requires-Dist: typing-inspection==0.4.0
|
|
30
36
|
Requires-Dist: typing_extensions==4.13.1
|
|
31
37
|
Requires-Dist: urllib3==2.3.0
|
|
32
38
|
Requires-Dist: uvicorn==0.34.0
|
|
39
|
+
Requires-Dist: watchtower==3.4.0
|
|
33
40
|
Dynamic: author
|
|
34
41
|
Dynamic: author-email
|
|
35
42
|
Dynamic: classifier
|
|
@@ -9,4 +9,9 @@ fastapi_basic.egg-info/PKG-INFO
|
|
|
9
9
|
fastapi_basic.egg-info/SOURCES.txt
|
|
10
10
|
fastapi_basic.egg-info/dependency_links.txt
|
|
11
11
|
fastapi_basic.egg-info/requires.txt
|
|
12
|
-
fastapi_basic.egg-info/top_level.txt
|
|
12
|
+
fastapi_basic.egg-info/top_level.txt
|
|
13
|
+
fastapi_basic/exception/__init__.py
|
|
14
|
+
fastapi_basic/exception/base_exception.py
|
|
15
|
+
fastapi_basic/ext/__init__.py
|
|
16
|
+
fastapi_basic/ext/aws/__init__.py
|
|
17
|
+
fastapi_basic/ext/aws/const.py
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
annotated-types==0.7.0
|
|
2
2
|
anyio==4.9.0
|
|
3
|
+
boto3==1.37.36
|
|
4
|
+
botocore==1.37.36
|
|
3
5
|
certifi==2025.1.31
|
|
4
6
|
charset-normalizer==3.4.1
|
|
5
7
|
click==8.1.8
|
|
@@ -7,14 +9,19 @@ dotenv==0.9.9
|
|
|
7
9
|
fastapi==0.115.12
|
|
8
10
|
h11==0.14.0
|
|
9
11
|
idna==3.10
|
|
12
|
+
jmespath==1.0.1
|
|
10
13
|
pydantic==2.11.3
|
|
11
14
|
pydantic_core==2.33.1
|
|
15
|
+
python-dateutil==2.9.0.post0
|
|
12
16
|
python-dotenv==1.1.0
|
|
13
17
|
python-multipart==0.0.20
|
|
14
18
|
requests==2.32.3
|
|
19
|
+
s3transfer==0.11.5
|
|
20
|
+
six==1.17.0
|
|
15
21
|
sniffio==1.3.1
|
|
16
22
|
starlette==0.46.1
|
|
17
23
|
typing-inspection==0.4.0
|
|
18
24
|
typing_extensions==4.13.1
|
|
19
25
|
urllib3==2.3.0
|
|
20
26
|
uvicorn==0.34.0
|
|
27
|
+
watchtower==3.4.0
|
|
@@ -5,7 +5,7 @@ with open('requirements.txt', 'r') as f:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name='fastapi_basic', # 模組名稱
|
|
8
|
-
version='0.0.
|
|
8
|
+
version='0.0.11', # 版號版號
|
|
9
9
|
description='A short description of your module', # 模塊描述
|
|
10
10
|
long_description=open('README.md').read(), # 詳細描述,通常是 README 文件的内容
|
|
11
11
|
long_description_content_type='text/markdown', # markdown 格式
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|