yuanboot 0.1.5__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 yuanboot might be problematic. Click here for more details.
- yuanboot-0.1.5/.gitignore +15 -0
- yuanboot-0.1.5/LICENSE +22 -0
- yuanboot-0.1.5/PKG-INFO +257 -0
- yuanboot-0.1.5/README.md +191 -0
- yuanboot-0.1.5/docs/components.md +226 -0
- yuanboot-0.1.5/docs/framework.md +185 -0
- yuanboot-0.1.5/docs/releases.md +185 -0
- yuanboot-0.1.5/packaging/build_binary.py +51 -0
- yuanboot-0.1.5/packaging/build_packages.py +35 -0
- yuanboot-0.1.5/packaging/cli/README.md +47 -0
- yuanboot-0.1.5/packaging/cli/pyproject.toml.tpl +36 -0
- yuanboot-0.1.5/packaging/prepare_release.py +17 -0
- yuanboot-0.1.5/packaging/yuanbootctl-python.spec +29 -0
- yuanboot-0.1.5/pyproject.toml +75 -0
- yuanboot-0.1.5/src/yuanboot/__init__.py +34 -0
- yuanboot-0.1.5/src/yuanboot/__main__.py +3 -0
- yuanboot-0.1.5/src/yuanboot/_version.py +1 -0
- yuanboot-0.1.5/src/yuanboot/cli/__init__.py +260 -0
- yuanboot-0.1.5/src/yuanboot/cli/__main__.py +3 -0
- yuanboot-0.1.5/src/yuanboot/cli/entrypoint.py +9 -0
- yuanboot-0.1.5/src/yuanboot/cli/scaffolding.py +119 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/.dockerignore.tpl +7 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/.gitignore.tpl +8 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/Dockerfile.tpl +10 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/README.md.tpl +59 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/__PACKAGE__/__init__.py.tpl +0 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/config.yml.tpl +11 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/config_dev.yml.tpl +3 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/config_fat.yml.tpl +3 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/config_pro.yml.tpl +3 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/config_uat.yml.tpl +3 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/docker-compose.yml.tpl +9 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/pyproject.toml.tpl +26 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/spec/backend-module-development.md.tpl +118 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/spec/components.md.tpl +226 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/common/spec/yuanboot-python.md.tpl +212 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/console/__PACKAGE__/main.py.tpl +29 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/console/__PACKAGE__/worker.py.tpl +14 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/grpc/__PACKAGE__/main.py.tpl +25 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/grpc/config.yml.tpl +9 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/grpc/config_dev.yml.tpl +3 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/grpc/config_fat.yml.tpl +3 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/grpc/config_pro.yml.tpl +3 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/grpc/config_uat.yml.tpl +3 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/grpc/proto/greeter.proto.tpl +6 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/microservice/__PACKAGE__/startup.py.tpl +15 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/microservice/__PACKAGE__/worker.py.tpl +16 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/mvc/__PACKAGE__/controllers.py.tpl +41 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/mvc/__PACKAGE__/startup.py.tpl +19 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/mvc/__PACKAGE__/templates/index.html.tpl +9 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/simpleweb/__PACKAGE__/startup.py.tpl +15 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/web/__PACKAGE__/main.py.tpl +27 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/webapi/__PACKAGE__/endpoints.py.tpl +25 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/webapi/__PACKAGE__/services.py.tpl +9 -0
- yuanboot-0.1.5/src/yuanboot/cli/templates/webapi/__PACKAGE__/startup.py.tpl +13 -0
- yuanboot-0.1.5/src/yuanboot/components/__init__.py +1 -0
- yuanboot-0.1.5/src/yuanboot/components/apollo.py +68 -0
- yuanboot-0.1.5/src/yuanboot/components/configuration.py +38 -0
- yuanboot-0.1.5/src/yuanboot/components/discovery.py +431 -0
- yuanboot-0.1.5/src/yuanboot/components/email.py +71 -0
- yuanboot-0.1.5/src/yuanboot/components/httpclient.py +93 -0
- yuanboot-0.1.5/src/yuanboot/components/mysql.py +136 -0
- yuanboot-0.1.5/src/yuanboot/components/nacos.py +517 -0
- yuanboot-0.1.5/src/yuanboot/components/observer.py +69 -0
- yuanboot-0.1.5/src/yuanboot/components/redis.py +107 -0
- yuanboot-0.1.5/src/yuanboot/components/scheduler.py +122 -0
- yuanboot-0.1.5/src/yuanboot/components/xxljob.py +219 -0
- yuanboot-0.1.5/src/yuanboot/configuration.py +294 -0
- yuanboot-0.1.5/src/yuanboot/console/__init__.py +3 -0
- yuanboot-0.1.5/src/yuanboot/dependency_injection.py +178 -0
- yuanboot-0.1.5/src/yuanboot/environment.py +9 -0
- yuanboot-0.1.5/src/yuanboot/grpc.py +133 -0
- yuanboot-0.1.5/src/yuanboot/health.py +14 -0
- yuanboot-0.1.5/src/yuanboot/hosting.py +335 -0
- yuanboot-0.1.5/src/yuanboot/logging.py +158 -0
- yuanboot-0.1.5/src/yuanboot/py.typed +0 -0
- yuanboot-0.1.5/src/yuanboot/web/__init__.py +30 -0
- yuanboot-0.1.5/src/yuanboot/web/application.py +144 -0
- yuanboot-0.1.5/src/yuanboot/web/context.py +43 -0
- yuanboot-0.1.5/src/yuanboot/web/dependencies.py +27 -0
- yuanboot-0.1.5/src/yuanboot/web/endpoints.py +63 -0
- yuanboot-0.1.5/src/yuanboot/web/middleware.py +97 -0
- yuanboot-0.1.5/src/yuanboot/web/mvc.py +105 -0
- yuanboot-0.1.5/src/yuanboot/web/routing.py +11 -0
- yuanboot-0.1.5/src/yuanboot/web/security.py +47 -0
yuanboot-0.1.5/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 max zhang
|
|
4
|
+
Copyright (c) 2026 yuanboot contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
yuanboot-0.1.5/PKG-INFO
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: yuanboot
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: A dependency-injected Python microservice framework built on FastAPI
|
|
5
|
+
Project-URL: Homepage, https://github.com/liangboceo/yuanboot-python
|
|
6
|
+
Project-URL: Documentation, https://github.com/liangboceo/yuanboot-python/tree/master/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/liangboceo/yuanboot-python
|
|
8
|
+
Project-URL: Issues, https://github.com/liangboceo/yuanboot-python/issues
|
|
9
|
+
Project-URL: Releases, https://github.com/liangboceo/yuanboot-python/releases
|
|
10
|
+
Author: yuanboot contributors
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: dependency-injection,fastapi,microservice,nacos,yuanboot
|
|
14
|
+
Classifier: Framework :: FastAPI
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: fastapi<1,>=0.115
|
|
23
|
+
Requires-Dist: jinja2<4,>=3.1
|
|
24
|
+
Requires-Dist: prometheus-client<1,>=0.21
|
|
25
|
+
Requires-Dist: pydantic<3,>=2.9
|
|
26
|
+
Requires-Dist: pyyaml<7,>=6
|
|
27
|
+
Requires-Dist: uvicorn[standard]<1,>=0.30
|
|
28
|
+
Provides-Extra: all
|
|
29
|
+
Requires-Dist: croniter<7,>=3; extra == 'all'
|
|
30
|
+
Requires-Dist: grpcio-health-checking<2,>=1.66; extra == 'all'
|
|
31
|
+
Requires-Dist: grpcio<2,>=1.66; extra == 'all'
|
|
32
|
+
Requires-Dist: httpx<1,>=0.27; extra == 'all'
|
|
33
|
+
Requires-Dist: pyjwt<3,>=2.9; extra == 'all'
|
|
34
|
+
Requires-Dist: pymysql[rsa]<2,>=1.1; extra == 'all'
|
|
35
|
+
Requires-Dist: redis<8,>=5; extra == 'all'
|
|
36
|
+
Requires-Dist: sqlalchemy<3,>=2.0; extra == 'all'
|
|
37
|
+
Provides-Extra: apollo
|
|
38
|
+
Requires-Dist: httpx<1,>=0.27; extra == 'apollo'
|
|
39
|
+
Provides-Extra: binary
|
|
40
|
+
Requires-Dist: pyinstaller<7,>=6.16; extra == 'binary'
|
|
41
|
+
Provides-Extra: dev
|
|
42
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
43
|
+
Requires-Dist: ruff>=0.9; extra == 'dev'
|
|
44
|
+
Requires-Dist: twine<7,>=6; extra == 'dev'
|
|
45
|
+
Provides-Extra: discovery
|
|
46
|
+
Requires-Dist: httpx<1,>=0.27; extra == 'discovery'
|
|
47
|
+
Provides-Extra: grpc
|
|
48
|
+
Requires-Dist: grpcio-health-checking<2,>=1.66; extra == 'grpc'
|
|
49
|
+
Requires-Dist: grpcio<2,>=1.66; extra == 'grpc'
|
|
50
|
+
Provides-Extra: http
|
|
51
|
+
Requires-Dist: httpx<1,>=0.27; extra == 'http'
|
|
52
|
+
Provides-Extra: jwt
|
|
53
|
+
Requires-Dist: pyjwt<3,>=2.9; extra == 'jwt'
|
|
54
|
+
Provides-Extra: mysql
|
|
55
|
+
Requires-Dist: pymysql[rsa]<2,>=1.1; extra == 'mysql'
|
|
56
|
+
Requires-Dist: sqlalchemy<3,>=2.0; extra == 'mysql'
|
|
57
|
+
Provides-Extra: nacos
|
|
58
|
+
Requires-Dist: httpx<1,>=0.27; extra == 'nacos'
|
|
59
|
+
Provides-Extra: redis
|
|
60
|
+
Requires-Dist: redis<8,>=5; extra == 'redis'
|
|
61
|
+
Provides-Extra: scheduler
|
|
62
|
+
Requires-Dist: croniter<7,>=3; extra == 'scheduler'
|
|
63
|
+
Provides-Extra: xxljob
|
|
64
|
+
Requires-Dist: httpx<1,>=0.27; extra == 'xxljob'
|
|
65
|
+
Description-Content-Type: text/markdown
|
|
66
|
+
|
|
67
|
+
# yuanboot-python
|
|
68
|
+
|
|
69
|
+
简单、轻量、快速的 Python 微服务框架,基于 FastAPI、Uvicorn 和依赖注入构建,支持 Web API、MVC、gRPC 与后台服务。Python 3.11+。
|
|
70
|
+
|
|
71
|
+
[](https://github.com/liangboceo/yuanboot-python/actions/workflows/ci.yml)
|
|
72
|
+
[](https://github.com/liangboceo/yuanboot-python/releases)
|
|
73
|
+
[](https://www.python.org/)
|
|
74
|
+
[](LICENSE)
|
|
75
|
+
|
|
76
|
+
## 框架特色
|
|
77
|
+
|
|
78
|
+
- 路由分组、MVC 控制器、请求校验、OpenAPI 和 WebSocket。
|
|
79
|
+
- Singleton、Scoped、Transient 依赖注入与资源自动释放。
|
|
80
|
+
- 统一宿主、应用生命周期、后台服务和优雅退出。
|
|
81
|
+
- YAML / JSON、多环境配置、环境变量和远程配置热更新。
|
|
82
|
+
- MySQL、Redis、Nacos 配置中心、服务注册与发现。
|
|
83
|
+
- 结构化日志、请求追踪、健康检查、Prometheus 和 JWT。
|
|
84
|
+
- HTTP 客户端、定时任务、SMTP、gRPC 和 XXL-Job BEAN 执行器。
|
|
85
|
+
- `yuanbootctl-python` 提供六类项目模板、运行和构建命令。
|
|
86
|
+
|
|
87
|
+
## 下载命令行工具
|
|
88
|
+
|
|
89
|
+
从 [GitHub Releases](https://github.com/liangboceo/yuanboot-python/releases) 下载对应系统和架构的压缩包,解压后即可执行,无需预装 Python。
|
|
90
|
+
|
|
91
|
+
| 系统 | 架构 | 文件后缀 |
|
|
92
|
+
| --- | --- | --- |
|
|
93
|
+
| Linux | amd64 / arm64 | `_linux_amd64.tar.gz` / `_linux_arm64.tar.gz` |
|
|
94
|
+
| macOS | Intel / Apple Silicon | `_darwin_amd64.tar.gz` / `_darwin_arm64.tar.gz` |
|
|
95
|
+
| Windows | amd64 | `_windows_amd64.zip` |
|
|
96
|
+
|
|
97
|
+
例如 Linux amd64:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
VERSION=0.1.5
|
|
101
|
+
curl -fLO "https://github.com/liangboceo/yuanboot-python/releases/download/v${VERSION}/yuanbootctl-python_${VERSION}_linux_amd64.tar.gz"
|
|
102
|
+
tar -xzf "yuanbootctl-python_${VERSION}_linux_amd64.tar.gz"
|
|
103
|
+
chmod +x yuanbootctl-python
|
|
104
|
+
./yuanbootctl-python --version
|
|
105
|
+
./yuanbootctl-python new webapi -n demo
|
|
106
|
+
cd demo
|
|
107
|
+
../yuanbootctl-python run --profile dev
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
访问 [API 文档](http://127.0.0.1:8080/docs)。Windows 使用 `yuanbootctl-python.exe`。
|
|
111
|
+
Release 同时提供 `SHA256SUMS`、wheel 和源码包。
|
|
112
|
+
|
|
113
|
+
独立可执行文件包含 Python 运行时、框架和标准组件,可以直接创建、运行模板项目。
|
|
114
|
+
业务增加其他 Python 依赖后,可使用 `run --python /path/to/.venv/bin/python` 选择业务环境。
|
|
115
|
+
`build` 打包 Python 项目,需要业务环境安装 `build`,详见 [命令行与发布说明](docs/releases.md)。
|
|
116
|
+
|
|
117
|
+
## 安装框架
|
|
118
|
+
|
|
119
|
+
从公开 PyPI 安装框架或项目工具:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
python -m pip install 'yuanboot[all]==0.1.5'
|
|
123
|
+
# 也可通过工具包安装同版本框架和命令:
|
|
124
|
+
python -m pip install yuanbootctl-python==0.1.5
|
|
125
|
+
yuanbootctl-python --version
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
`yuanbootctl-python` 自动依赖同版本的 `yuanboot`,命令入口和模板资源统一由框架提供。
|
|
129
|
+
`yuanbootctl-python[all]` 会安装全部标准组件。PyPI 安装方式需要 Python 3.11+。
|
|
130
|
+
|
|
131
|
+
业务项目也可使用 Git tag 固定框架版本:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
python -m venv .venv
|
|
135
|
+
source .venv/bin/activate
|
|
136
|
+
python -m pip install 'yuanboot[all] @ git+https://github.com/liangboceo/yuanboot-python.git@v0.1.5'
|
|
137
|
+
yuanbootctl-python new mvc -n orders
|
|
138
|
+
cd orders
|
|
139
|
+
python -m pip install -e '.[dev,components]'
|
|
140
|
+
yuanbootctl-python run --reload
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
按需选择 `mysql`、`redis`、`nacos`、`grpc` 等 extras;`all` 安装全部标准组件。
|
|
144
|
+
框架和业务项目分别管理版本,业务项目提交自己的依赖锁文件。
|
|
145
|
+
生成的项目默认保持 Git tag 依赖;使用 PyPI 时可将依赖改为 `yuanboot==0.1.5`、
|
|
146
|
+
`yuanboot[all]==0.1.5`(gRPC 项目使用 `yuanboot[grpc]==0.1.5`)。
|
|
147
|
+
|
|
148
|
+
## 项目模板
|
|
149
|
+
|
|
150
|
+
| 模板 | 内容 |
|
|
151
|
+
| --- | --- |
|
|
152
|
+
| `simpleweb` | 最小 HTTP 应用与运维端点 |
|
|
153
|
+
| `webapi` | API 路由、服务注入和请求校验 |
|
|
154
|
+
| `mvc` | 控制器、服务层和 Jinja2 页面 |
|
|
155
|
+
| `microservice` | Web API、监控和后台服务 |
|
|
156
|
+
| `console` | 命令行宿主与后台任务 |
|
|
157
|
+
| `grpc` | gRPC 服务与健康检查 |
|
|
158
|
+
|
|
159
|
+
模板包含项目元数据、配置、Dockerfile、Compose、README 和 `spec` 开发文档。
|
|
160
|
+
每个新项目默认提供以下文档,可离线查阅:
|
|
161
|
+
|
|
162
|
+
```text
|
|
163
|
+
README.md
|
|
164
|
+
spec/
|
|
165
|
+
├── yuanboot-python.md # 框架使用说明
|
|
166
|
+
├── components.md # 核心组件配置与使用
|
|
167
|
+
└── backend-module-development.md # 后端模块开发规范
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
yuanbootctl-python new --list
|
|
172
|
+
yuanbootctl-python new mvc -n my-app
|
|
173
|
+
yuanbootctl-python new grpc -n rpc-demo
|
|
174
|
+
yuanbootctl-python run --profile fat --port 9000
|
|
175
|
+
yuanbootctl-python run --workers 2
|
|
176
|
+
yuanbootctl-python build
|
|
177
|
+
yuanbootctl-python version
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## 简单示例
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
from yuanboot.web import create_default_builder
|
|
184
|
+
from yuanboot.web.endpoints import use_actuator
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def endpoints(router):
|
|
188
|
+
use_actuator(router)
|
|
189
|
+
|
|
190
|
+
@router.get("/info")
|
|
191
|
+
def info():
|
|
192
|
+
return {"info": "ok"}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
host = create_default_builder(endpoints).build()
|
|
196
|
+
app = host.app
|
|
197
|
+
|
|
198
|
+
if __name__ == "__main__":
|
|
199
|
+
host.run()
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
默认监听 `0.0.0.0:8080`。可通过宿主构建器配置服务注册、中间件、路由和生命周期。
|
|
203
|
+
|
|
204
|
+
## 环境与配置
|
|
205
|
+
|
|
206
|
+
支持 `dev / fat / uat / pro`,默认 `dev`。通过 `--profile` 或 `YUANBOOT_PROFILE` 选择环境。
|
|
207
|
+
|
|
208
|
+
```text
|
|
209
|
+
config.yml
|
|
210
|
+
config_dev.yml
|
|
211
|
+
config_fat.yml
|
|
212
|
+
config_uat.yml
|
|
213
|
+
config_pro.yml
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
配置优先级:默认值 < 基础配置 < 环境配置 < 远程配置 < 环境变量 < 命令行。
|
|
217
|
+
MySQL、Redis 和 Nacos 等组件按配置启用;Nacos 注册 metadata 的 `yuanboot_env` 使用当前环境名。
|
|
218
|
+
|
|
219
|
+
```yaml
|
|
220
|
+
yuanboot:
|
|
221
|
+
application:
|
|
222
|
+
name: orders
|
|
223
|
+
server:
|
|
224
|
+
address: ":8080"
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
支持 `${ENV:default}` 插值和 Pydantic 模型绑定,敏感信息通过环境变量提供。
|
|
228
|
+
|
|
229
|
+
## 核心组件
|
|
230
|
+
|
|
231
|
+
| 能力 | 组件 |
|
|
232
|
+
| --- | --- |
|
|
233
|
+
| 数据与缓存 | MySQL / SQLAlchemy、Redis |
|
|
234
|
+
| 配置中心 | Nacos、Apollo |
|
|
235
|
+
| 注册与发现 | Nacos、Consul、Eureka、etcd、内存注册表 |
|
|
236
|
+
| 日志与监控 | 标准 logging、JSON 日志、Request ID、健康检查、Prometheus |
|
|
237
|
+
| 服务通信 | HTTP 客户端、gRPC |
|
|
238
|
+
| 后台任务 | HostedService、Scheduler、XXL-Job BEAN |
|
|
239
|
+
| 通知与事件 | SMTP、进程内 Observer |
|
|
240
|
+
|
|
241
|
+
组件配置和使用方法见 [组件文档](docs/components.md)。
|
|
242
|
+
|
|
243
|
+
## 发布
|
|
244
|
+
|
|
245
|
+
在 [Actions → Build Release](https://github.com/liangboceo/yuanboot-python/actions/workflows/Release.yml) 手动填写 `version`,选择 `prerelease`、`draft`。
|
|
246
|
+
构建通过后,自动同步版本、创建 Git tag 和 GitHub Release,上传各平台可执行文件、wheel、源码包和校验文件。
|
|
247
|
+
默认分支为 `master`,已发布 tag 保持不变。
|
|
248
|
+
|
|
249
|
+
## 文档
|
|
250
|
+
|
|
251
|
+
- [框架开发指南](docs/framework.md)
|
|
252
|
+
- [组件配置与使用](docs/components.md)
|
|
253
|
+
- [命令行、发布与依赖管理](docs/releases.md)
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
[MIT](LICENSE)
|
yuanboot-0.1.5/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# yuanboot-python
|
|
2
|
+
|
|
3
|
+
简单、轻量、快速的 Python 微服务框架,基于 FastAPI、Uvicorn 和依赖注入构建,支持 Web API、MVC、gRPC 与后台服务。Python 3.11+。
|
|
4
|
+
|
|
5
|
+
[](https://github.com/liangboceo/yuanboot-python/actions/workflows/ci.yml)
|
|
6
|
+
[](https://github.com/liangboceo/yuanboot-python/releases)
|
|
7
|
+
[](https://www.python.org/)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
## 框架特色
|
|
11
|
+
|
|
12
|
+
- 路由分组、MVC 控制器、请求校验、OpenAPI 和 WebSocket。
|
|
13
|
+
- Singleton、Scoped、Transient 依赖注入与资源自动释放。
|
|
14
|
+
- 统一宿主、应用生命周期、后台服务和优雅退出。
|
|
15
|
+
- YAML / JSON、多环境配置、环境变量和远程配置热更新。
|
|
16
|
+
- MySQL、Redis、Nacos 配置中心、服务注册与发现。
|
|
17
|
+
- 结构化日志、请求追踪、健康检查、Prometheus 和 JWT。
|
|
18
|
+
- HTTP 客户端、定时任务、SMTP、gRPC 和 XXL-Job BEAN 执行器。
|
|
19
|
+
- `yuanbootctl-python` 提供六类项目模板、运行和构建命令。
|
|
20
|
+
|
|
21
|
+
## 下载命令行工具
|
|
22
|
+
|
|
23
|
+
从 [GitHub Releases](https://github.com/liangboceo/yuanboot-python/releases) 下载对应系统和架构的压缩包,解压后即可执行,无需预装 Python。
|
|
24
|
+
|
|
25
|
+
| 系统 | 架构 | 文件后缀 |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| Linux | amd64 / arm64 | `_linux_amd64.tar.gz` / `_linux_arm64.tar.gz` |
|
|
28
|
+
| macOS | Intel / Apple Silicon | `_darwin_amd64.tar.gz` / `_darwin_arm64.tar.gz` |
|
|
29
|
+
| Windows | amd64 | `_windows_amd64.zip` |
|
|
30
|
+
|
|
31
|
+
例如 Linux amd64:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
VERSION=0.1.5
|
|
35
|
+
curl -fLO "https://github.com/liangboceo/yuanboot-python/releases/download/v${VERSION}/yuanbootctl-python_${VERSION}_linux_amd64.tar.gz"
|
|
36
|
+
tar -xzf "yuanbootctl-python_${VERSION}_linux_amd64.tar.gz"
|
|
37
|
+
chmod +x yuanbootctl-python
|
|
38
|
+
./yuanbootctl-python --version
|
|
39
|
+
./yuanbootctl-python new webapi -n demo
|
|
40
|
+
cd demo
|
|
41
|
+
../yuanbootctl-python run --profile dev
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
访问 [API 文档](http://127.0.0.1:8080/docs)。Windows 使用 `yuanbootctl-python.exe`。
|
|
45
|
+
Release 同时提供 `SHA256SUMS`、wheel 和源码包。
|
|
46
|
+
|
|
47
|
+
独立可执行文件包含 Python 运行时、框架和标准组件,可以直接创建、运行模板项目。
|
|
48
|
+
业务增加其他 Python 依赖后,可使用 `run --python /path/to/.venv/bin/python` 选择业务环境。
|
|
49
|
+
`build` 打包 Python 项目,需要业务环境安装 `build`,详见 [命令行与发布说明](docs/releases.md)。
|
|
50
|
+
|
|
51
|
+
## 安装框架
|
|
52
|
+
|
|
53
|
+
从公开 PyPI 安装框架或项目工具:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
python -m pip install 'yuanboot[all]==0.1.5'
|
|
57
|
+
# 也可通过工具包安装同版本框架和命令:
|
|
58
|
+
python -m pip install yuanbootctl-python==0.1.5
|
|
59
|
+
yuanbootctl-python --version
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`yuanbootctl-python` 自动依赖同版本的 `yuanboot`,命令入口和模板资源统一由框架提供。
|
|
63
|
+
`yuanbootctl-python[all]` 会安装全部标准组件。PyPI 安装方式需要 Python 3.11+。
|
|
64
|
+
|
|
65
|
+
业务项目也可使用 Git tag 固定框架版本:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
python -m venv .venv
|
|
69
|
+
source .venv/bin/activate
|
|
70
|
+
python -m pip install 'yuanboot[all] @ git+https://github.com/liangboceo/yuanboot-python.git@v0.1.5'
|
|
71
|
+
yuanbootctl-python new mvc -n orders
|
|
72
|
+
cd orders
|
|
73
|
+
python -m pip install -e '.[dev,components]'
|
|
74
|
+
yuanbootctl-python run --reload
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
按需选择 `mysql`、`redis`、`nacos`、`grpc` 等 extras;`all` 安装全部标准组件。
|
|
78
|
+
框架和业务项目分别管理版本,业务项目提交自己的依赖锁文件。
|
|
79
|
+
生成的项目默认保持 Git tag 依赖;使用 PyPI 时可将依赖改为 `yuanboot==0.1.5`、
|
|
80
|
+
`yuanboot[all]==0.1.5`(gRPC 项目使用 `yuanboot[grpc]==0.1.5`)。
|
|
81
|
+
|
|
82
|
+
## 项目模板
|
|
83
|
+
|
|
84
|
+
| 模板 | 内容 |
|
|
85
|
+
| --- | --- |
|
|
86
|
+
| `simpleweb` | 最小 HTTP 应用与运维端点 |
|
|
87
|
+
| `webapi` | API 路由、服务注入和请求校验 |
|
|
88
|
+
| `mvc` | 控制器、服务层和 Jinja2 页面 |
|
|
89
|
+
| `microservice` | Web API、监控和后台服务 |
|
|
90
|
+
| `console` | 命令行宿主与后台任务 |
|
|
91
|
+
| `grpc` | gRPC 服务与健康检查 |
|
|
92
|
+
|
|
93
|
+
模板包含项目元数据、配置、Dockerfile、Compose、README 和 `spec` 开发文档。
|
|
94
|
+
每个新项目默认提供以下文档,可离线查阅:
|
|
95
|
+
|
|
96
|
+
```text
|
|
97
|
+
README.md
|
|
98
|
+
spec/
|
|
99
|
+
├── yuanboot-python.md # 框架使用说明
|
|
100
|
+
├── components.md # 核心组件配置与使用
|
|
101
|
+
└── backend-module-development.md # 后端模块开发规范
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
yuanbootctl-python new --list
|
|
106
|
+
yuanbootctl-python new mvc -n my-app
|
|
107
|
+
yuanbootctl-python new grpc -n rpc-demo
|
|
108
|
+
yuanbootctl-python run --profile fat --port 9000
|
|
109
|
+
yuanbootctl-python run --workers 2
|
|
110
|
+
yuanbootctl-python build
|
|
111
|
+
yuanbootctl-python version
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## 简单示例
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from yuanboot.web import create_default_builder
|
|
118
|
+
from yuanboot.web.endpoints import use_actuator
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def endpoints(router):
|
|
122
|
+
use_actuator(router)
|
|
123
|
+
|
|
124
|
+
@router.get("/info")
|
|
125
|
+
def info():
|
|
126
|
+
return {"info": "ok"}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
host = create_default_builder(endpoints).build()
|
|
130
|
+
app = host.app
|
|
131
|
+
|
|
132
|
+
if __name__ == "__main__":
|
|
133
|
+
host.run()
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
默认监听 `0.0.0.0:8080`。可通过宿主构建器配置服务注册、中间件、路由和生命周期。
|
|
137
|
+
|
|
138
|
+
## 环境与配置
|
|
139
|
+
|
|
140
|
+
支持 `dev / fat / uat / pro`,默认 `dev`。通过 `--profile` 或 `YUANBOOT_PROFILE` 选择环境。
|
|
141
|
+
|
|
142
|
+
```text
|
|
143
|
+
config.yml
|
|
144
|
+
config_dev.yml
|
|
145
|
+
config_fat.yml
|
|
146
|
+
config_uat.yml
|
|
147
|
+
config_pro.yml
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
配置优先级:默认值 < 基础配置 < 环境配置 < 远程配置 < 环境变量 < 命令行。
|
|
151
|
+
MySQL、Redis 和 Nacos 等组件按配置启用;Nacos 注册 metadata 的 `yuanboot_env` 使用当前环境名。
|
|
152
|
+
|
|
153
|
+
```yaml
|
|
154
|
+
yuanboot:
|
|
155
|
+
application:
|
|
156
|
+
name: orders
|
|
157
|
+
server:
|
|
158
|
+
address: ":8080"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
支持 `${ENV:default}` 插值和 Pydantic 模型绑定,敏感信息通过环境变量提供。
|
|
162
|
+
|
|
163
|
+
## 核心组件
|
|
164
|
+
|
|
165
|
+
| 能力 | 组件 |
|
|
166
|
+
| --- | --- |
|
|
167
|
+
| 数据与缓存 | MySQL / SQLAlchemy、Redis |
|
|
168
|
+
| 配置中心 | Nacos、Apollo |
|
|
169
|
+
| 注册与发现 | Nacos、Consul、Eureka、etcd、内存注册表 |
|
|
170
|
+
| 日志与监控 | 标准 logging、JSON 日志、Request ID、健康检查、Prometheus |
|
|
171
|
+
| 服务通信 | HTTP 客户端、gRPC |
|
|
172
|
+
| 后台任务 | HostedService、Scheduler、XXL-Job BEAN |
|
|
173
|
+
| 通知与事件 | SMTP、进程内 Observer |
|
|
174
|
+
|
|
175
|
+
组件配置和使用方法见 [组件文档](docs/components.md)。
|
|
176
|
+
|
|
177
|
+
## 发布
|
|
178
|
+
|
|
179
|
+
在 [Actions → Build Release](https://github.com/liangboceo/yuanboot-python/actions/workflows/Release.yml) 手动填写 `version`,选择 `prerelease`、`draft`。
|
|
180
|
+
构建通过后,自动同步版本、创建 Git tag 和 GitHub Release,上传各平台可执行文件、wheel、源码包和校验文件。
|
|
181
|
+
默认分支为 `master`,已发布 tag 保持不变。
|
|
182
|
+
|
|
183
|
+
## 文档
|
|
184
|
+
|
|
185
|
+
- [框架开发指南](docs/framework.md)
|
|
186
|
+
- [组件配置与使用](docs/components.md)
|
|
187
|
+
- [命令行、发布与依赖管理](docs/releases.md)
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
[MIT](LICENSE)
|