faster-app 0.1.0__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.
- faster_app-0.1.0/LICENSE +21 -0
- faster_app-0.1.0/PKG-INFO +285 -0
- faster_app-0.1.0/README.md +260 -0
- faster_app-0.1.0/faster_api/__init__.py +58 -0
- faster_app-0.1.0/faster_api/base.py +129 -0
- faster_app-0.1.0/faster_api/commands/__init__.py +14 -0
- faster_app-0.1.0/faster_api/commands/base.py +85 -0
- faster_app-0.1.0/faster_api/commands/builtins/__init__.py +3 -0
- faster_app-0.1.0/faster_api/commands/builtins/db.py +137 -0
- faster_app-0.1.0/faster_api/commands/builtins/fastapi.py +87 -0
- faster_app-0.1.0/faster_api/commands/discover.py +24 -0
- faster_app-0.1.0/faster_api/db.py +32 -0
- faster_app-0.1.0/faster_api/models/__init__.py +21 -0
- faster_app-0.1.0/faster_api/models/base.py +106 -0
- faster_app-0.1.0/faster_api/models/discover.py +53 -0
- faster_app-0.1.0/faster_api/routes/__init__.py +13 -0
- faster_app-0.1.0/faster_api/routes/base.py +12 -0
- faster_app-0.1.0/faster_api/routes/builtins/__init__.py +3 -0
- faster_app-0.1.0/faster_api/routes/builtins/defaults.py +12 -0
- faster_app-0.1.0/faster_api/routes/builtins/swagger.py +15 -0
- faster_app-0.1.0/faster_api/routes/discover.py +52 -0
- faster_app-0.1.0/faster_api/settings/__init__.py +10 -0
- faster_app-0.1.0/faster_api/settings/builtins/settings.py +64 -0
- faster_app-0.1.0/faster_api/settings/discover.py +79 -0
- faster_app-0.1.0/faster_api/statics/swagger-ui-bundle.min.js +11 -0
- faster_app-0.1.0/faster_api/statics/swagger-ui.min.css +1 -0
- faster_app-0.1.0/faster_app.egg-info/PKG-INFO +285 -0
- faster_app-0.1.0/faster_app.egg-info/SOURCES.txt +31 -0
- faster_app-0.1.0/faster_app.egg-info/dependency_links.txt +1 -0
- faster_app-0.1.0/faster_app.egg-info/requires.txt +8 -0
- faster_app-0.1.0/faster_app.egg-info/top_level.txt +1 -0
- faster_app-0.1.0/pyproject.toml +43 -0
- faster_app-0.1.0/setup.cfg +4 -0
faster_app-0.1.0/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Cloud Truss Team
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,285 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: faster-app
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: 一个轻量级的 Python Web 框架,提供自动发现、模型基类、命令行工具等功能
|
5
|
+
Author-email: peizhenfei <peizhenfei@hotmail.com>
|
6
|
+
Maintainer-email: peizhenfei <peizhenfei@hotmail.com>
|
7
|
+
License-Expression: MIT
|
8
|
+
Project-URL: Homepage, https://github.com/mautops/faster-app
|
9
|
+
Project-URL: Documentation, https://github.com/mautops/faster-app#readme
|
10
|
+
Project-URL: Repository, https://github.com/mautops/faster-app.git
|
11
|
+
Project-URL: Bug Tracker, https://github.com/mautops/faster-app/issues
|
12
|
+
Keywords: web,framework,fastapi,tortoise,orm,cli
|
13
|
+
Requires-Python: >=3.11
|
14
|
+
Description-Content-Type: text/markdown
|
15
|
+
License-File: LICENSE
|
16
|
+
Requires-Dist: aerich>=0.9.1
|
17
|
+
Requires-Dist: fastapi>=0.116.1
|
18
|
+
Requires-Dist: fire>=0.7.1
|
19
|
+
Requires-Dist: pydantic>=2.11.7
|
20
|
+
Requires-Dist: pydantic-settings>=2.10.1
|
21
|
+
Requires-Dist: rich>=14.1.0
|
22
|
+
Requires-Dist: tortoise-orm>=0.25.1
|
23
|
+
Requires-Dist: uvicorn>=0.35.0
|
24
|
+
Dynamic: license-file
|
25
|
+
|
26
|
+
# Faster API
|
27
|
+
|
28
|
+
[](https://www.python.org/downloads/)
|
29
|
+
[](https://fastapi.tiangolo.com/)
|
30
|
+
[](https://tortoise.github.io/)
|
31
|
+
[](https://opensource.org/licenses/MIT)
|
32
|
+
|
33
|
+
一个轻量级、高性能的 Python Web 框架,基于 FastAPI 和 Tortoise ORM 构建,提供自动发现、模型基类、命令行工具等企业级功能。
|
34
|
+
|
35
|
+
## ✨ 核心特性
|
36
|
+
|
37
|
+
- 🔍 **智能自动发现**: 自动扫描和加载模块、模型、路由和命令
|
38
|
+
- 🗄️ **丰富模型基类**: 基于 Tortoise ORM 的企业级模型基类
|
39
|
+
- 🛠️ **强大命令行工具**: 基于 Fire 的异步命令行工具框架
|
40
|
+
- 🌐 **统一路由管理**: FastAPI 路由的标准化返回格式
|
41
|
+
- 📦 **即插即用**: 模块化设计,开箱即用
|
42
|
+
- ⚡ **高性能**: 异步架构,支持高并发
|
43
|
+
- 🔧 **开发友好**: 内置数据库迁移、开发服务器等工具
|
44
|
+
|
45
|
+
## 🚀 快速安装
|
46
|
+
|
47
|
+
```bash
|
48
|
+
pip install faster-app
|
49
|
+
```
|
50
|
+
|
51
|
+
# 📖 快速开始
|
52
|
+
|
53
|
+
## 1. 项目结构
|
54
|
+
|
55
|
+
```
|
56
|
+
your-project/
|
57
|
+
├── apps/ # 应用目录
|
58
|
+
│ ├── auth/
|
59
|
+
│ │ ├── models.py # 模型定义
|
60
|
+
│ │ ├── routes.py # 路由定义
|
61
|
+
│ │ └── commands.py # 命令定义
|
62
|
+
│ └── user/
|
63
|
+
│ ├── models.py
|
64
|
+
│ ├── routes.py
|
65
|
+
│ └── commands.py
|
66
|
+
├── config/
|
67
|
+
└──── settings.py # 配置文件
|
68
|
+
└── main.py # 入口文件
|
69
|
+
```
|
70
|
+
|
71
|
+
### 2. 模型定义
|
72
|
+
|
73
|
+
```python
|
74
|
+
# models.py
|
75
|
+
from faster_api.models import UUIDModel, DateTimeModel, StatusModel
|
76
|
+
from tortoise import fields
|
77
|
+
|
78
|
+
class User(UUIDModel, DateTimeModel, StatusModel):
|
79
|
+
"""用户模型"""
|
80
|
+
name = fields.CharField(max_length=50, description="用户名")
|
81
|
+
email = fields.CharField(max_length=100, unique=True, description="邮箱")
|
82
|
+
|
83
|
+
class Meta:
|
84
|
+
table = "users"
|
85
|
+
table_description = "用户表"
|
86
|
+
```
|
87
|
+
|
88
|
+
### 3. 路由定义
|
89
|
+
|
90
|
+
```python
|
91
|
+
# routes.py
|
92
|
+
from fastapi import APIRouter
|
93
|
+
from faster_api.routes import ApiResponse
|
94
|
+
|
95
|
+
router = APIRouter(prefix="/api/v1/users", tags=["用户管理"])
|
96
|
+
|
97
|
+
@router.get("/", response_model=ApiResponse)
|
98
|
+
async def get_users():
|
99
|
+
"""获取用户列表"""
|
100
|
+
users = await User.all()
|
101
|
+
return ApiResponse(
|
102
|
+
message="获取用户列表成功",
|
103
|
+
data={"users": users, "total": len(users)}
|
104
|
+
)
|
105
|
+
|
106
|
+
@router.post("/", response_model=ApiResponse)
|
107
|
+
async def create_user(name: str, email: str):
|
108
|
+
"""创建用户"""
|
109
|
+
user = await User.create(name=name, email=email)
|
110
|
+
return ApiResponse(
|
111
|
+
message="用户创建成功",
|
112
|
+
data={"user": user}
|
113
|
+
)
|
114
|
+
```
|
115
|
+
|
116
|
+
### 4. 命令定义
|
117
|
+
|
118
|
+
```python
|
119
|
+
# commands.py
|
120
|
+
from faster_api.commands import CommandBase
|
121
|
+
|
122
|
+
class UserCommand(CommandBase):
|
123
|
+
"""用户管理命令"""
|
124
|
+
|
125
|
+
async def create_user(self, name: str, email: str):
|
126
|
+
"""创建用户"""
|
127
|
+
user = await User.create(name=name, email=email)
|
128
|
+
print(f"✅ 用户创建成功: {user.name} ({user.email})")
|
129
|
+
|
130
|
+
async def list_users(self):
|
131
|
+
"""列出所有用户"""
|
132
|
+
users = await User.all()
|
133
|
+
print(f"📋 共找到 {len(users)} 个用户:")
|
134
|
+
for user in users:
|
135
|
+
print(f" - {user.name} ({user.email})")
|
136
|
+
```
|
137
|
+
|
138
|
+
### 5. 启动应用
|
139
|
+
|
140
|
+
```python
|
141
|
+
# main.py
|
142
|
+
import fire
|
143
|
+
from faster_api.commands.discover import CommandDiscover
|
144
|
+
|
145
|
+
if __name__ == "__main__":
|
146
|
+
# 自动发现并注册所有命令
|
147
|
+
command_instances = CommandDiscover().discover()
|
148
|
+
commands = {}
|
149
|
+
for instance in command_instances:
|
150
|
+
command_name = instance.get_command_name()
|
151
|
+
commands[command_name] = instance
|
152
|
+
|
153
|
+
fire.Fire(commands)
|
154
|
+
```
|
155
|
+
|
156
|
+
# 🛠️ 内置工具
|
157
|
+
|
158
|
+
### 1. 数据库管理
|
159
|
+
|
160
|
+
```bash
|
161
|
+
# 初始化数据库
|
162
|
+
python main.py db init_db
|
163
|
+
|
164
|
+
# 生成迁移文件
|
165
|
+
python main.py db migrate
|
166
|
+
|
167
|
+
# 执行迁移
|
168
|
+
python main.py db upgrade
|
169
|
+
|
170
|
+
# 回滚迁移
|
171
|
+
python main.py db downgrade
|
172
|
+
|
173
|
+
# 查看迁移历史
|
174
|
+
python main.py db history
|
175
|
+
|
176
|
+
# 清理开发环境
|
177
|
+
python main.py db dev_clean
|
178
|
+
```
|
179
|
+
|
180
|
+
### 2. 开发服务器
|
181
|
+
|
182
|
+
```bash
|
183
|
+
# 启动开发服务器
|
184
|
+
python main.py fastapi start
|
185
|
+
|
186
|
+
# 指定主机和端口
|
187
|
+
python main.py fastapi start --host=0.0.0.0 --port=8080
|
188
|
+
```
|
189
|
+
|
190
|
+
# ⚙️ 配置管理
|
191
|
+
|
192
|
+
> 默认配置,可以通过
|
193
|
+
|
194
|
+
```python
|
195
|
+
from pydantic_settings import BaseSettings
|
196
|
+
|
197
|
+
class Settings(BaseSettings):
|
198
|
+
# 基础配置
|
199
|
+
PROJECT_NAME: str = ""
|
200
|
+
VERSION: str = "1.0.0"
|
201
|
+
DEBUG: bool = True
|
202
|
+
|
203
|
+
# 服务器配置
|
204
|
+
HOST: str = "127.0.0.1"
|
205
|
+
PORT: int = 8000
|
206
|
+
|
207
|
+
# API 配置
|
208
|
+
API_V1_STR: str = "/api/v1"
|
209
|
+
|
210
|
+
# JWT 配置
|
211
|
+
SECRET_KEY: str = "your-secret-key"
|
212
|
+
ALGORITHM: str = "HS256"
|
213
|
+
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
|
214
|
+
|
215
|
+
# 数据库配置
|
216
|
+
DB_ENGINE: str = "tortoise.backends.asyncpg"
|
217
|
+
DB_HOST: str = "localhost"
|
218
|
+
DB_PORT: int = 5432
|
219
|
+
DB_USER: str = "postgres"
|
220
|
+
DB_PASSWORD: str = "password"
|
221
|
+
DB_DATABASE: str = "mydb"
|
222
|
+
|
223
|
+
# 实例化配置
|
224
|
+
configs = Settings()
|
225
|
+
```
|
226
|
+
|
227
|
+
### 环境变量支持
|
228
|
+
|
229
|
+
创建 `.env` 文件:
|
230
|
+
|
231
|
+
```env
|
232
|
+
PROJECT_NAME=My API Project
|
233
|
+
DEBUG=true
|
234
|
+
DB_HOST=localhost
|
235
|
+
DB_PORT=5432
|
236
|
+
DB_USER=postgres
|
237
|
+
DB_PASSWORD=password
|
238
|
+
DB_DATABASE=mydb
|
239
|
+
SECRET_KEY=your-secret-key-here
|
240
|
+
```
|
241
|
+
|
242
|
+
## 🤝 贡献指南
|
243
|
+
|
244
|
+
我们欢迎所有形式的贡献!
|
245
|
+
|
246
|
+
### 如何贡献
|
247
|
+
|
248
|
+
1. Fork 本仓库
|
249
|
+
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
|
250
|
+
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
|
251
|
+
4. 推送到分支 (`git push origin feature/AmazingFeature`)
|
252
|
+
5. 开启 Pull Request
|
253
|
+
|
254
|
+
### 报告问题
|
255
|
+
|
256
|
+
如果您发现了 bug 或有功能建议,请在 [Issues](https://github.com/your-org/faster-app/issues) 中提交。
|
257
|
+
|
258
|
+
## 📄 许可证
|
259
|
+
|
260
|
+
本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。
|
261
|
+
|
262
|
+
## 🙏 致谢
|
263
|
+
|
264
|
+
- [FastAPI](https://fastapi.tiangolo.com/) - 现代、快速的 Web 框架
|
265
|
+
- [Tortoise ORM](https://tortoise.github.io/) - 异步 ORM 框架
|
266
|
+
- [Fire](https://github.com/google/python-fire) - 命令行接口生成器
|
267
|
+
- [Pydantic](https://pydantic-docs.helpmanual.io/) - 数据验证库
|
268
|
+
- [Rich](https://rich.readthedocs.io/) - 终端美化库
|
269
|
+
|
270
|
+
## 📈 更新日志
|
271
|
+
|
272
|
+
### v0.1.0 (2024-01-01)
|
273
|
+
|
274
|
+
- 🎉 初始版本发布
|
275
|
+
- ✅ 提供基础的自动发现功能
|
276
|
+
- ✅ 提供模型、命令、路由基类
|
277
|
+
- ✅ 提供数据库连接管理
|
278
|
+
- ✅ 内置数据库迁移工具
|
279
|
+
- ✅ 内置 FastAPI 开发服务器
|
280
|
+
|
281
|
+
---
|
282
|
+
|
283
|
+
**作者**: peizhenfei (peizhenfei@hotmail.com)
|
284
|
+
|
285
|
+
**项目主页**: [https://github.com/mautops/faster-app.git](https://github.com/mautops/faster-app.git)
|
@@ -0,0 +1,260 @@
|
|
1
|
+
# Faster API
|
2
|
+
|
3
|
+
[](https://www.python.org/downloads/)
|
4
|
+
[](https://fastapi.tiangolo.com/)
|
5
|
+
[](https://tortoise.github.io/)
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
7
|
+
|
8
|
+
一个轻量级、高性能的 Python Web 框架,基于 FastAPI 和 Tortoise ORM 构建,提供自动发现、模型基类、命令行工具等企业级功能。
|
9
|
+
|
10
|
+
## ✨ 核心特性
|
11
|
+
|
12
|
+
- 🔍 **智能自动发现**: 自动扫描和加载模块、模型、路由和命令
|
13
|
+
- 🗄️ **丰富模型基类**: 基于 Tortoise ORM 的企业级模型基类
|
14
|
+
- 🛠️ **强大命令行工具**: 基于 Fire 的异步命令行工具框架
|
15
|
+
- 🌐 **统一路由管理**: FastAPI 路由的标准化返回格式
|
16
|
+
- 📦 **即插即用**: 模块化设计,开箱即用
|
17
|
+
- ⚡ **高性能**: 异步架构,支持高并发
|
18
|
+
- 🔧 **开发友好**: 内置数据库迁移、开发服务器等工具
|
19
|
+
|
20
|
+
## 🚀 快速安装
|
21
|
+
|
22
|
+
```bash
|
23
|
+
pip install faster-app
|
24
|
+
```
|
25
|
+
|
26
|
+
# 📖 快速开始
|
27
|
+
|
28
|
+
## 1. 项目结构
|
29
|
+
|
30
|
+
```
|
31
|
+
your-project/
|
32
|
+
├── apps/ # 应用目录
|
33
|
+
│ ├── auth/
|
34
|
+
│ │ ├── models.py # 模型定义
|
35
|
+
│ │ ├── routes.py # 路由定义
|
36
|
+
│ │ └── commands.py # 命令定义
|
37
|
+
│ └── user/
|
38
|
+
│ ├── models.py
|
39
|
+
│ ├── routes.py
|
40
|
+
│ └── commands.py
|
41
|
+
├── config/
|
42
|
+
└──── settings.py # 配置文件
|
43
|
+
└── main.py # 入口文件
|
44
|
+
```
|
45
|
+
|
46
|
+
### 2. 模型定义
|
47
|
+
|
48
|
+
```python
|
49
|
+
# models.py
|
50
|
+
from faster_api.models import UUIDModel, DateTimeModel, StatusModel
|
51
|
+
from tortoise import fields
|
52
|
+
|
53
|
+
class User(UUIDModel, DateTimeModel, StatusModel):
|
54
|
+
"""用户模型"""
|
55
|
+
name = fields.CharField(max_length=50, description="用户名")
|
56
|
+
email = fields.CharField(max_length=100, unique=True, description="邮箱")
|
57
|
+
|
58
|
+
class Meta:
|
59
|
+
table = "users"
|
60
|
+
table_description = "用户表"
|
61
|
+
```
|
62
|
+
|
63
|
+
### 3. 路由定义
|
64
|
+
|
65
|
+
```python
|
66
|
+
# routes.py
|
67
|
+
from fastapi import APIRouter
|
68
|
+
from faster_api.routes import ApiResponse
|
69
|
+
|
70
|
+
router = APIRouter(prefix="/api/v1/users", tags=["用户管理"])
|
71
|
+
|
72
|
+
@router.get("/", response_model=ApiResponse)
|
73
|
+
async def get_users():
|
74
|
+
"""获取用户列表"""
|
75
|
+
users = await User.all()
|
76
|
+
return ApiResponse(
|
77
|
+
message="获取用户列表成功",
|
78
|
+
data={"users": users, "total": len(users)}
|
79
|
+
)
|
80
|
+
|
81
|
+
@router.post("/", response_model=ApiResponse)
|
82
|
+
async def create_user(name: str, email: str):
|
83
|
+
"""创建用户"""
|
84
|
+
user = await User.create(name=name, email=email)
|
85
|
+
return ApiResponse(
|
86
|
+
message="用户创建成功",
|
87
|
+
data={"user": user}
|
88
|
+
)
|
89
|
+
```
|
90
|
+
|
91
|
+
### 4. 命令定义
|
92
|
+
|
93
|
+
```python
|
94
|
+
# commands.py
|
95
|
+
from faster_api.commands import CommandBase
|
96
|
+
|
97
|
+
class UserCommand(CommandBase):
|
98
|
+
"""用户管理命令"""
|
99
|
+
|
100
|
+
async def create_user(self, name: str, email: str):
|
101
|
+
"""创建用户"""
|
102
|
+
user = await User.create(name=name, email=email)
|
103
|
+
print(f"✅ 用户创建成功: {user.name} ({user.email})")
|
104
|
+
|
105
|
+
async def list_users(self):
|
106
|
+
"""列出所有用户"""
|
107
|
+
users = await User.all()
|
108
|
+
print(f"📋 共找到 {len(users)} 个用户:")
|
109
|
+
for user in users:
|
110
|
+
print(f" - {user.name} ({user.email})")
|
111
|
+
```
|
112
|
+
|
113
|
+
### 5. 启动应用
|
114
|
+
|
115
|
+
```python
|
116
|
+
# main.py
|
117
|
+
import fire
|
118
|
+
from faster_api.commands.discover import CommandDiscover
|
119
|
+
|
120
|
+
if __name__ == "__main__":
|
121
|
+
# 自动发现并注册所有命令
|
122
|
+
command_instances = CommandDiscover().discover()
|
123
|
+
commands = {}
|
124
|
+
for instance in command_instances:
|
125
|
+
command_name = instance.get_command_name()
|
126
|
+
commands[command_name] = instance
|
127
|
+
|
128
|
+
fire.Fire(commands)
|
129
|
+
```
|
130
|
+
|
131
|
+
# 🛠️ 内置工具
|
132
|
+
|
133
|
+
### 1. 数据库管理
|
134
|
+
|
135
|
+
```bash
|
136
|
+
# 初始化数据库
|
137
|
+
python main.py db init_db
|
138
|
+
|
139
|
+
# 生成迁移文件
|
140
|
+
python main.py db migrate
|
141
|
+
|
142
|
+
# 执行迁移
|
143
|
+
python main.py db upgrade
|
144
|
+
|
145
|
+
# 回滚迁移
|
146
|
+
python main.py db downgrade
|
147
|
+
|
148
|
+
# 查看迁移历史
|
149
|
+
python main.py db history
|
150
|
+
|
151
|
+
# 清理开发环境
|
152
|
+
python main.py db dev_clean
|
153
|
+
```
|
154
|
+
|
155
|
+
### 2. 开发服务器
|
156
|
+
|
157
|
+
```bash
|
158
|
+
# 启动开发服务器
|
159
|
+
python main.py fastapi start
|
160
|
+
|
161
|
+
# 指定主机和端口
|
162
|
+
python main.py fastapi start --host=0.0.0.0 --port=8080
|
163
|
+
```
|
164
|
+
|
165
|
+
# ⚙️ 配置管理
|
166
|
+
|
167
|
+
> 默认配置,可以通过
|
168
|
+
|
169
|
+
```python
|
170
|
+
from pydantic_settings import BaseSettings
|
171
|
+
|
172
|
+
class Settings(BaseSettings):
|
173
|
+
# 基础配置
|
174
|
+
PROJECT_NAME: str = ""
|
175
|
+
VERSION: str = "1.0.0"
|
176
|
+
DEBUG: bool = True
|
177
|
+
|
178
|
+
# 服务器配置
|
179
|
+
HOST: str = "127.0.0.1"
|
180
|
+
PORT: int = 8000
|
181
|
+
|
182
|
+
# API 配置
|
183
|
+
API_V1_STR: str = "/api/v1"
|
184
|
+
|
185
|
+
# JWT 配置
|
186
|
+
SECRET_KEY: str = "your-secret-key"
|
187
|
+
ALGORITHM: str = "HS256"
|
188
|
+
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
|
189
|
+
|
190
|
+
# 数据库配置
|
191
|
+
DB_ENGINE: str = "tortoise.backends.asyncpg"
|
192
|
+
DB_HOST: str = "localhost"
|
193
|
+
DB_PORT: int = 5432
|
194
|
+
DB_USER: str = "postgres"
|
195
|
+
DB_PASSWORD: str = "password"
|
196
|
+
DB_DATABASE: str = "mydb"
|
197
|
+
|
198
|
+
# 实例化配置
|
199
|
+
configs = Settings()
|
200
|
+
```
|
201
|
+
|
202
|
+
### 环境变量支持
|
203
|
+
|
204
|
+
创建 `.env` 文件:
|
205
|
+
|
206
|
+
```env
|
207
|
+
PROJECT_NAME=My API Project
|
208
|
+
DEBUG=true
|
209
|
+
DB_HOST=localhost
|
210
|
+
DB_PORT=5432
|
211
|
+
DB_USER=postgres
|
212
|
+
DB_PASSWORD=password
|
213
|
+
DB_DATABASE=mydb
|
214
|
+
SECRET_KEY=your-secret-key-here
|
215
|
+
```
|
216
|
+
|
217
|
+
## 🤝 贡献指南
|
218
|
+
|
219
|
+
我们欢迎所有形式的贡献!
|
220
|
+
|
221
|
+
### 如何贡献
|
222
|
+
|
223
|
+
1. Fork 本仓库
|
224
|
+
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
|
225
|
+
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
|
226
|
+
4. 推送到分支 (`git push origin feature/AmazingFeature`)
|
227
|
+
5. 开启 Pull Request
|
228
|
+
|
229
|
+
### 报告问题
|
230
|
+
|
231
|
+
如果您发现了 bug 或有功能建议,请在 [Issues](https://github.com/your-org/faster-app/issues) 中提交。
|
232
|
+
|
233
|
+
## 📄 许可证
|
234
|
+
|
235
|
+
本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。
|
236
|
+
|
237
|
+
## 🙏 致谢
|
238
|
+
|
239
|
+
- [FastAPI](https://fastapi.tiangolo.com/) - 现代、快速的 Web 框架
|
240
|
+
- [Tortoise ORM](https://tortoise.github.io/) - 异步 ORM 框架
|
241
|
+
- [Fire](https://github.com/google/python-fire) - 命令行接口生成器
|
242
|
+
- [Pydantic](https://pydantic-docs.helpmanual.io/) - 数据验证库
|
243
|
+
- [Rich](https://rich.readthedocs.io/) - 终端美化库
|
244
|
+
|
245
|
+
## 📈 更新日志
|
246
|
+
|
247
|
+
### v0.1.0 (2024-01-01)
|
248
|
+
|
249
|
+
- 🎉 初始版本发布
|
250
|
+
- ✅ 提供基础的自动发现功能
|
251
|
+
- ✅ 提供模型、命令、路由基类
|
252
|
+
- ✅ 提供数据库连接管理
|
253
|
+
- ✅ 内置数据库迁移工具
|
254
|
+
- ✅ 内置 FastAPI 开发服务器
|
255
|
+
|
256
|
+
---
|
257
|
+
|
258
|
+
**作者**: peizhenfei (peizhenfei@hotmail.com)
|
259
|
+
|
260
|
+
**项目主页**: [https://github.com/mautops/faster-app.git](https://github.com/mautops/faster-app.git)
|
@@ -0,0 +1,58 @@
|
|
1
|
+
"""
|
2
|
+
Faster API - 一个轻量级的 Python Web 框架
|
3
|
+
|
4
|
+
提供了以下核心功能:
|
5
|
+
- 自动发现和加载模块 (DiscoverBase)
|
6
|
+
- 数据库模型基类 (UUIDModel, DateTimeModel, StatusModel, ScopeModel)
|
7
|
+
- 命令行工具基类 (CommandBase)
|
8
|
+
- 路由管理 (ApiResponse)
|
9
|
+
- 数据库连接管理 (tortoise_init)
|
10
|
+
"""
|
11
|
+
|
12
|
+
__version__ = "0.1.0"
|
13
|
+
__author__ = "peizhenfei"
|
14
|
+
__email__ = "peizhenfei@hotmail.com"
|
15
|
+
|
16
|
+
# 导出主要的类和函数
|
17
|
+
from faster_api.base import DiscoverBase
|
18
|
+
from faster_api.models.base import (
|
19
|
+
UUIDModel,
|
20
|
+
DateTimeModel,
|
21
|
+
StatusModel,
|
22
|
+
ScopeModel,
|
23
|
+
SyncTimeModel,
|
24
|
+
SyncCrontabModel,
|
25
|
+
)
|
26
|
+
from faster_api.commands.base import CommandBase, with_db_init
|
27
|
+
from faster_api.routes.base import ApiResponse
|
28
|
+
from faster_api.db import tortoise_init
|
29
|
+
|
30
|
+
# 导出发现器
|
31
|
+
from faster_api.models.discover import ModelDiscover
|
32
|
+
from faster_api.commands.discover import CommandDiscover
|
33
|
+
from faster_api.routes.discover import RoutesDiscover
|
34
|
+
|
35
|
+
# 导出配置
|
36
|
+
from faster_api.settings.builtins.settings import DefaultSettings
|
37
|
+
|
38
|
+
__all__ = [
|
39
|
+
# 基础类
|
40
|
+
"DiscoverBase",
|
41
|
+
"CommandBase",
|
42
|
+
"with_db_init",
|
43
|
+
"ApiResponse",
|
44
|
+
"tortoise_init",
|
45
|
+
# 模型基类
|
46
|
+
"UUIDModel",
|
47
|
+
"DateTimeModel",
|
48
|
+
"StatusModel",
|
49
|
+
"ScopeModel",
|
50
|
+
"SyncTimeModel",
|
51
|
+
"SyncCrontabModel",
|
52
|
+
# 发现器
|
53
|
+
"ModelDiscover",
|
54
|
+
"CommandDiscover",
|
55
|
+
"RoutesDiscover",
|
56
|
+
# 配置
|
57
|
+
"DefaultSettings",
|
58
|
+
]
|