惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
H
Hacker News: Front Page
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cisco Blogs
P
Palo Alto Networks Blog
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
AWS News Blog
AWS News Blog
Spread Privacy
Spread Privacy
S
Schneier on Security
The Hacker News
The Hacker News
Cyberwarzone
Cyberwarzone
T
Tenable Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Tailwind CSS Blog
S
Secure Thoughts
N
Netflix TechBlog - Medium
T
The Exploit Database - CXSecurity.com
I
Intezer
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Help Net Security
Help Net Security
K
Kaspersky official blog
Google Online Security Blog
Google Online Security Blog
L
LangChain Blog
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
Hacker News: Ask HN
Hacker News: Ask HN
www.infosecurity-magazine.com
www.infosecurity-magazine.com
有赞技术团队
有赞技术团队
P
Privacy International News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Recent Announcements
Recent Announcements
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Register - Security
The Register - Security
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
Recorded Future
Recorded Future
The Last Watchdog
The Last Watchdog
G
Google Developers Blog
T
Threatpost
小众软件
小众软件
S
Securelist
Recent Commits to openclaw:main
Recent Commits to openclaw:main
O
OpenAI News

TrumanDu's Blog

AI Agent RAG学习笔记 杜架的记录与分享(020期) AI 大模型工作流开发 深入理解 MCP 大模型微调 摄影学习笔记 修图大师 - 限制 AI 修图能力的不是修图大师,而是你的想象力 杜架的记录与分享(019期) 杜架的记录与分享(018 期) 你还记得自己的座右铭吗? Discourse 调研笔记 我的前端技术栈 杜架的记录与分享(017期) 杜架的记录与分享(016期) 2024年终总结 2024 年度独立博客年终总结随机浏览网站 杜架的记录与分享(015期) 杜架的记录与分享(014期) 足以让我爆吹的 AI 编程利器-Cursor React 学习笔记总结
MyBoot - 类似 Spring Boot 的 Python 快速开发框架
TrumanDu · 2025-11-10 · via TrumanDu's Blog

MyBoot 是一个功能丰富的 Python Web 框架,提供类似 Spring Boot 的自动配置和快速开发功能。它集成了 Web API、定时任务、日志管理、配置管理等核心功能,让您能够快速构建现代化的 Python 应用程序。

✨ 主要特性

  • 🚀 快速启动: 类似 Spring Boot 的自动配置和快速启动
  • 🎯 约定优于配置: 遵循约定,减少配置工作,自动发现和注册组件
  • 🌐 Web API: 基于 FastAPI 的高性能 Web API 开发
  • 🌐 REST API 统一响应格式
  • 高性能服务器: 默认使用 Hypercorn 服务器,支持 HTTP/2 和多进程
  • 定时任务: 强大的任务调度系统,支持 Cron 表达式和间隔任务
  • 📝 日志管理: 基于 loguru 的强大日志系统,支持结构化日志和第三方库日志控制
  • ⚙️ 配置管理: 基于 Dynaconf 的强大配置系统,支持 YAML 配置、环境变量覆盖和远程配置
  • 🔧 中间件支持: 丰富的中间件生态,包括 CORS、限流、安全等
  • 📊 健康检查: 内置健康检查、就绪检查和存活检查
  • 🎯 依赖注入: 简单的依赖注入和组件管理
  • 🔄 优雅关闭: 支持优雅关闭和资源清理
  • 📚 自动文档: 自动生成 API 文档和交互式界面

⚡ 一分钟快速上手

安装命令:

1
pip install myboot

创建项目:

1
2
3
myboot init --name my-app --template api
cd my-app
python main.py

访问 http://localhost:8000,一个完整的 API 服务就跑起来了。


✨ 示例:Hello MyBoot

1
2
3
4
5
6
7
8
9
10
11
from myboot.core.application import create_app
from myboot.core.decorators import get

app = create_app(name="HelloApp")

@get("/")
def hello():
return {"message": "Hello, MyBoot!"}

if __name__ == "__main__":
app.run()

无需手动注册路由、配置日志或服务器。
MyBoot 会自动扫描、注册并运行一切组件。

统一响应格式

1
2
3
4
5
6
server:
response_format:
enabled: true # 是否启用自动格式化
exclude_paths: # 排除的路径(这些路径不会自动格式化)
- "/custom/path"
- "/another/path"

响应格式:

1
2
3
4
5
6
7
8
{
"success": true,
"code": 200,
"message": "操作成功",
"data": {
// 实际业务数据
}
}

🧠 自动依赖注入与服务发现

MyBoot 的依赖注入机制让组件之间解耦变得自然:

1
2
3
4
5
6
7
8
9
10
11
from myboot.core.decorators import service, get
from myboot.core.application import get_service

@service()
class UserService:
def get_user(self, user_id): return {"id": user_id, "name": f"用户{user_id}"}

@get("/users/{user_id}")
def get_user(user_id: int):
user_service = get_service('user_service')
return user_service.get_user(user_id)

无须繁琐配置,框架自动识别、注册并注入依赖。


🕒 定时任务与后台任务

1
2
3
4
5
from myboot.core.decorators import cron

@cron("0 */1 * * * *")
def hourly_job():
print("每小时执行一次任务")

还可轻松集成异步任务或后台处理逻辑,无需引入 Celery。


🧰 统一的配置与日志管理

1
2
3
4
5
6
7
8

app:
name: "MyBoot App"
server:
port: 8000
logging:
level: INFO
file: logs/app.log

配置自动加载,可被环境变量或远程文件覆盖。
内置 Loguru 日志系统,支持结构化与 JSON 输出。


📁 推荐项目结构

1
2
3
4
5
6
7
8
9
my-app/
├── main.py
├── app/
│ ├── api/ # 路由
│ ├── service/ # 服务层
│ ├── jobs/ # 定时任务
│ └── client/ # 外部客户端
├── conf/config.yaml
└── tests/

简洁、规范、开箱即用。


💬 结语

MyBoot 并不是又一个 Web 框架,而是让 Python 开发体验接近 Spring Boot 的一体化解决方案
它让你专注于业务逻辑,而不是重复配置。

📦 项目地址:github.com/TrumanDu/myboot
🧑‍💻 立即安装体验:

1
pip install myboot

让企业级 Python 开发变得更快、更优雅。 更多文档详见项目首页。🚀