database-smartools 0.0.1__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.
Files changed (32) hide show
  1. database_smartools-0.0.1/LICENSE +13 -0
  2. database_smartools-0.0.1/PKG-INFO +80 -0
  3. database_smartools-0.0.1/README.md +26 -0
  4. database_smartools-0.0.1/database_smartools/__init__.py +18 -0
  5. database_smartools-0.0.1/database_smartools/api/__init__.py +18 -0
  6. database_smartools-0.0.1/database_smartools/api/etl.py +160 -0
  7. database_smartools-0.0.1/database_smartools/database/__init__.py +18 -0
  8. database_smartools-0.0.1/database_smartools/database/dameng_extend.py +65 -0
  9. database_smartools-0.0.1/database_smartools/database/db_handler.py +676 -0
  10. database_smartools-0.0.1/database_smartools/database/mysql_extend.py +396 -0
  11. database_smartools-0.0.1/database_smartools/database/oceanbase_extend.py +55 -0
  12. database_smartools-0.0.1/database_smartools/database/oracle_extend.py +27 -0
  13. database_smartools-0.0.1/database_smartools/database/postgre_extend.py +396 -0
  14. database_smartools-0.0.1/database_smartools/main.py +86 -0
  15. database_smartools-0.0.1/database_smartools/module/__init__.py +18 -0
  16. database_smartools-0.0.1/database_smartools/module/function.py +115 -0
  17. database_smartools-0.0.1/database_smartools/utils/__init__.py +18 -0
  18. database_smartools-0.0.1/database_smartools/utils/config.py +56 -0
  19. database_smartools-0.0.1/database_smartools/utils/debug.py +59 -0
  20. database_smartools-0.0.1/database_smartools/utils/file.py +42 -0
  21. database_smartools-0.0.1/database_smartools/utils/http.py +74 -0
  22. database_smartools-0.0.1/database_smartools/utils/logger.py +237 -0
  23. database_smartools-0.0.1/database_smartools/utils/output.py +31 -0
  24. database_smartools-0.0.1/database_smartools/utils/texter.py +186 -0
  25. database_smartools-0.0.1/database_smartools/utils/timer.py +52 -0
  26. database_smartools-0.0.1/database_smartools.egg-info/PKG-INFO +80 -0
  27. database_smartools-0.0.1/database_smartools.egg-info/SOURCES.txt +30 -0
  28. database_smartools-0.0.1/database_smartools.egg-info/dependency_links.txt +1 -0
  29. database_smartools-0.0.1/database_smartools.egg-info/requires.txt +35 -0
  30. database_smartools-0.0.1/database_smartools.egg-info/top_level.txt +1 -0
  31. database_smartools-0.0.1/setup.cfg +4 -0
  32. database_smartools-0.0.1/setup.py +64 -0
@@ -0,0 +1,13 @@
1
+ Copyright:2025-2035, 深圳市赢和信息技术有限公司. All rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.4
2
+ Name: database-smartools
3
+ Version: 0.0.1
4
+ Summary: 数据库操作工具包
5
+ Home-page:
6
+ Author: joelz
7
+ Author-email: zhongbj_26210@163.com
8
+ Requires-Python: >=3.11
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: altgraph==0.17.4
12
+ Requires-Dist: annotated-types==0.7.0
13
+ Requires-Dist: anyio==4.9.0
14
+ Requires-Dist: click==8.1.8
15
+ Requires-Dist: colorama==0.4.6
16
+ Requires-Dist: oracledb==3.0.0
17
+ Requires-Dist: DBUtils==3.0.0
18
+ Requires-Dist: dmPython==2.5.8
19
+ Requires-Dist: fastapi==0.115.12
20
+ Requires-Dist: greenlet==3.2.1
21
+ Requires-Dist: h11==0.16.0
22
+ Requires-Dist: idna==3.10
23
+ Requires-Dist: mysql-connector-python==8.4.0
24
+ Requires-Dist: numpy==2.0.0
25
+ Requires-Dist: packaging==25.0
26
+ Requires-Dist: pandas==2.2.3
27
+ Requires-Dist: pefile==2023.2.7
28
+ Requires-Dist: psycopg2-binary==2.9.8
29
+ Requires-Dist: pydantic==2.11.3
30
+ Requires-Dist: pydantic_core==2.33.1
31
+ Requires-Dist: pyinstaller==6.14.0
32
+ Requires-Dist: pyinstaller-hooks-contrib==2025.4
33
+ Requires-Dist: python-dateutil==2.9.0.post0
34
+ Requires-Dist: pytz==2025.2
35
+ Requires-Dist: pywin32-ctypes==0.2.3
36
+ Requires-Dist: six==1.17.0
37
+ Requires-Dist: sniffio==1.3.1
38
+ Requires-Dist: SQLAlchemy==2.0.40
39
+ Requires-Dist: starlette==0.46.2
40
+ Requires-Dist: typing-inspection==0.4.0
41
+ Requires-Dist: typing_extensions==4.13.2
42
+ Requires-Dist: tzdata==2025.2
43
+ Requires-Dist: uvicorn==0.34.2
44
+ Requires-Dist: JayDeBeApi==1.2.3
45
+ Requires-Dist: jpype1>=1.5.2
46
+ Dynamic: author
47
+ Dynamic: author-email
48
+ Dynamic: description
49
+ Dynamic: description-content-type
50
+ Dynamic: license-file
51
+ Dynamic: requires-dist
52
+ Dynamic: requires-python
53
+ Dynamic: summary
54
+
55
+ # python-main
56
+
57
+ #### 介绍
58
+ python web服务,api - module - model - db
59
+
60
+ /logRefresh:是日志配置初始化接口(开发调试用的)
61
+ /configRefresh:是配置文件初始化接口,修改了项目下的conf.ini后可以调用这个接口刷新
62
+ /etl/functionCall:调用etl脚本主入口
63
+ /etl/dbpool/refresh:修改数据库链接后,用于刷新数据库连接池
64
+ /etl/lo
65
+
66
+ #### 软件架构
67
+ 软件架构说明
68
+ 目录结构参照项目目录下的Readme.txt
69
+
70
+
71
+ #### 安装教程
72
+ 进入到项目主目录下
73
+ 1. 安装Python 3.10.16
74
+ 2. pip install -r requirement.txt
75
+
76
+
77
+ #### 使用说明
78
+ 1. 运行服务器,python main.py [可选参数:dev/pro,分别为开发环境和产品环境,默认dev],对应配置信息在conf.ini中
79
+ 2. 控制台会输出对应的Swagger UI界面,可在该页面上调试api
80
+ ![输入图片说明](statics/imagesimage.png)
@@ -0,0 +1,26 @@
1
+ # python-main
2
+
3
+ #### 介绍
4
+ python web服务,api - module - model - db
5
+
6
+ /logRefresh:是日志配置初始化接口(开发调试用的)
7
+ /configRefresh:是配置文件初始化接口,修改了项目下的conf.ini后可以调用这个接口刷新
8
+ /etl/functionCall:调用etl脚本主入口
9
+ /etl/dbpool/refresh:修改数据库链接后,用于刷新数据库连接池
10
+ /etl/lo
11
+
12
+ #### 软件架构
13
+ 软件架构说明
14
+ 目录结构参照项目目录下的Readme.txt
15
+
16
+
17
+ #### 安装教程
18
+ 进入到项目主目录下
19
+ 1. 安装Python 3.10.16
20
+ 2. pip install -r requirement.txt
21
+
22
+
23
+ #### 使用说明
24
+ 1. 运行服务器,python main.py [可选参数:dev/pro,分别为开发环境和产品环境,默认dev],对应配置信息在conf.ini中
25
+ 2. 控制台会输出对应的Swagger UI界面,可在该页面上调试api
26
+ ![输入图片说明](statics/imagesimage.png)
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ @项目名称 : yhfin-data-agent
4
+ @文件名称 : __init__.py.py
5
+ @创建人 : zhongbinjie
6
+ @创建时间 : 2025/9/9 17:02
7
+ @文件说明 :
8
+ @企业名称 : 深圳市赢和信息技术有限公司
9
+ @Copyright:2025-2035, 深圳市赢和信息技术有限公司. All rights Reserved.
10
+ """
11
+
12
+
13
+ def test():
14
+ print()
15
+
16
+
17
+ if __name__ == '__main__':
18
+ None
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ @项目名称 : yhfin-data-agent
4
+ @文件名称 : __init__.py.py
5
+ @创建人 : zhongbinjie
6
+ @创建时间 : 2025/9/9 17:02
7
+ @文件说明 :
8
+ @企业名称 : 深圳市赢和信息技术有限公司
9
+ @Copyright:2025-2035, 深圳市赢和信息技术有限公司. All rights Reserved.
10
+ """
11
+
12
+
13
+ def test():
14
+ print()
15
+
16
+
17
+ if __name__ == '__main__':
18
+ None
@@ -0,0 +1,160 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ @项目名称 : python-main
4
+ @文件名称 : etl.py
5
+ @创建人 : zhongbinjie
6
+ @创建时间 : 2025/6/7 19:06
7
+ @文件说明 :
8
+ @企业名称 : 深圳市赢和信息技术有限公司
9
+ @Copyright:2025-2035, 深圳市赢和信息技术有限公司. All rights Reserved.
10
+ """
11
+
12
+ from fastapi import APIRouter
13
+ from utils import logger, http
14
+ import json
15
+ from module import function as func
16
+ from database import db_handler as dh
17
+
18
+ router = APIRouter()
19
+
20
+ #mcp function call格式
21
+ """
22
+ 模板样例:
23
+ [
24
+ {
25
+ "id": "call_xxxx", #必填项
26
+ "type": "function", #必填项
27
+ "function": {
28
+ "name": "", #必填项
29
+ "description": "", #必填项,简要描述
30
+ "script_path": "", #选填项
31
+ "input_schema": { #选填项,可以没有参数列表
32
+ "title": "xxxxx_arguments", #如果有参数列表,则必填项
33
+ "type": "object", #如果有参数列表,则必填项
34
+ "properties": {
35
+ "arg1": {"type" : '', "value" : ''}, #如果有参数列表,则必填项,结构保持一致
36
+ "arg2": {"type" : '', "value" : ''}
37
+ },
38
+ "required": [
39
+ "arg1" #required为选填项,指properties里有的参数为必选参数,值不能为空
40
+ ]
41
+ }
42
+ }
43
+ }
44
+ ]
45
+ 实际样例:
46
+ [
47
+ {
48
+ "id": "wf_pytest",
49
+ "type": "function",
50
+ "function": {
51
+ "name": "py_test2",
52
+ "description": "Function for testing purposes",
53
+ "script_path": "",
54
+ "input_schema": {
55
+ "title": "pytest_arguments",
56
+ "type": "object",
57
+ "properties": {
58
+ "db_key" : {
59
+ "type": "string",
60
+ "value": "123"
61
+ },
62
+ "p_beg_date": {
63
+ "type": "string",
64
+ "value": "20180101"
65
+ },
66
+ "p_end_date": {
67
+ "type": "string",
68
+ "value": "20180131"
69
+ },
70
+ "p_cal_code": {
71
+ "type": "string",
72
+ "value": "400007"
73
+ }
74
+ },
75
+ "required": [
76
+ "db_key",
77
+ "p_beg_date",
78
+ "p_end_date"
79
+ ]
80
+ }
81
+ }
82
+ }
83
+ ]
84
+ """
85
+ @router.get("/functionCall")
86
+ def function_call(function_str: str):
87
+ return_list = []
88
+ #支持工作流:任务1>>任务2串联方式
89
+ try:
90
+ function_map = json.loads(function_str)
91
+ for function in function_map:
92
+ workflow_id = function['id']
93
+ sub_functions = function['function']['name'].split('>>')
94
+ properties = function['function']['input_schema']['properties']
95
+ requires = function['function']['input_schema']['required']
96
+ script_path = None
97
+ if 'script_path' in function['function'].keys():
98
+ script_path = function['function']['script_path']
99
+ args = {}
100
+ for key, param in properties.items():
101
+ if key in requires and (not param['value'] or param['value'] == ""):
102
+ message = f"缺少必要参数:{key}"
103
+ logger.error(message)
104
+ return http.ResponseUtil.error(message=message)
105
+ args[key] = param['value']
106
+
107
+ for sub in sub_functions:
108
+ rtn_map = func.execute_function(sub, args, script_path)
109
+ exec_time = rtn_map['time']
110
+ if not rtn_map['status']:
111
+ return_list.append(http.ResponseUtil.error(message=rtn_map['message'], workflow_id=workflow_id, function=sub, exec_time=exec_time))
112
+ else:
113
+ data = rtn_map['data']
114
+ return_list.append(http.ResponseUtil.success(data=data, workflow_id=workflow_id, function=sub, exec_time=exec_time))
115
+
116
+ except json.JSONDecodeError:
117
+ message = f"json格式异常,请检查参数:{function_str}"
118
+ logger.error(message)
119
+ return_list.append(http.ResponseUtil.error(message=message))
120
+ return http.ResponseUtil.error(message=message)
121
+
122
+ return return_list
123
+
124
+ @router.get("/dbpool/refresh")
125
+ def refresh_dbpool(db_key: str):
126
+ if db_key:
127
+ if db_key not in dh.POOL_MAP.keys():
128
+ return http.ResponseUtil.error(message=f'刷新失败,数据池中没有{db_key}对应的连接')
129
+ else:
130
+ pool, message = dh.get_pool_by_key(db_key, refresh=True)
131
+ if not pool:
132
+ return http.ResponseUtil.error(message=message)
133
+
134
+ return http.ResponseUtil.success(message=f"数据库连接池刷新成功,db_key: {db_key}")
135
+
136
+ @router.get("/logs")
137
+ def grap_log(id: str = None):
138
+ message_id = id
139
+ log_file = logger.LOG_NAME
140
+ logs = []
141
+ with open(log_file, "r", encoding="utf-8") as file:
142
+ for line in file:
143
+ try:
144
+ log = json.loads(line.strip())
145
+ if log['id'] == message_id and message_id is not None:
146
+ logs.append(log)
147
+ if not message_id:
148
+ logs.append(log)
149
+
150
+ except json.JSONDecodeError:
151
+ None
152
+ logger.info(f"抓取日志信息成功,message_id:{id}")
153
+ return http.ResponseUtil.success(data={'logs' : logs})
154
+
155
+ def test():
156
+ print()
157
+
158
+
159
+ if __name__ == '__main__':
160
+ None
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ @项目名称 : yhfin-data-agent
4
+ @文件名称 : __init__.py.py
5
+ @创建人 : zhongbinjie
6
+ @创建时间 : 2025/9/9 17:02
7
+ @文件说明 :
8
+ @企业名称 : 深圳市赢和信息技术有限公司
9
+ @Copyright:2025-2035, 深圳市赢和信息技术有限公司. All rights Reserved.
10
+ """
11
+
12
+
13
+ def test():
14
+ print()
15
+
16
+
17
+ if __name__ == '__main__':
18
+ None
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ @项目名称 : python-main
4
+ @文件名称 : oracle_extend.py
5
+ @创建人 : zhongbinjie
6
+ @创建时间 : 2025/7/2 16:14
7
+ @文件说明 :
8
+ @企业名称 : 深圳市赢和信息技术有限公司
9
+ @Copyright:2025-2035, 深圳市赢和信息技术有限公司. All rights Reserved.
10
+ """
11
+ import dmPython
12
+ from datetime import date, datetime, timedelta
13
+ from decimal import Decimal
14
+
15
+
16
+ def formatter(result):
17
+ data = []
18
+ for row in result["data"]:
19
+ item_map = {}
20
+ for index, item in enumerate(row):
21
+ column_type = result["desc"][index][1]
22
+ if item is not None:
23
+ if column_type == dmPython.BOOLEAN:
24
+ # 将达梦 BOOLEAN 类型转换为 Python bool 类型
25
+ item = bool(item)
26
+ elif column_type == dmPython.BINARY:
27
+ # 将达梦 BINARY 类型转换为 Python bytes 类型
28
+ item = bytes(item)
29
+ elif column_type == dmPython.DATE:
30
+ # 将达梦 DATE 类型转换为 Python datetime.date 类型
31
+ item = datetime(item.year, item.month, item.day)
32
+ elif column_type == dmPython.TIMESTAMP:
33
+ # 将达梦 TIMESTAMP 类型转换为 Python datetime.datetime 类型
34
+ item = datetime(
35
+ item.year,
36
+ item.month,
37
+ item.day,
38
+ item.hour,
39
+ item.minute,
40
+ item.second,
41
+ item.microsecond,
42
+ )
43
+ elif column_type == dmPython.INTERVAL:
44
+ # 将达梦 INTERVAL 类型转换为 Python datetime.timedelta 类型
45
+ item = timedelta(
46
+ days=item.days,
47
+ seconds=item.seconds,
48
+ microseconds=item.microseconds,
49
+ )
50
+ elif column_type == dmPython.DECIMAL:
51
+ # 将达梦 DECIMAL 类型转换为 Python decimal.Decimal 类型
52
+ item = float(item)
53
+ elif column_type == dmPython.REAL:
54
+ # 将达梦 REAL 类型转换为 Python float 类型
55
+ item = float(item)
56
+ elif column_type == dmPython.BIGINT:
57
+ # 将达梦 BIGINT 类型转换为 Python int 类型
58
+ item = int(item)
59
+ elif column_type == dmPython.STRING:
60
+ # 将达梦 STRING 类型转换为 Python str 类型
61
+ item = str(item)
62
+
63
+ item_map[result["desc"][index][0].lower()] = item
64
+ data.append(item_map)
65
+ return data