FastAPI Amis
FastAPI Amis 是一个基于 FastAPI 和 Amis 的 Python 框架,用于快速构建现代化的管理后台界面。
目前正在实验中请不要投入生产项目
功能特性
- 🚀 基于 FastAPI 的高性能 Web 框架
- 🎨 集成 Amis 低代码前端框架
- 📱 响应式设计,支持多端适配
- 🔧 灵活的组件化开发
- 📊 内置丰富的表单、表格、图表组件
- 🛠️ 支持自定义路由和视图
环境要求
- Python >= 3.10
- uv (Python 包管理器)
- FastAPI
- Uvicorn
安装
- 克隆项目:
git clone https://github.com/InfernalAzazel/fastapi-amis.git
cd fastapi-amis
- 安装 uv(如果尚未安装):
curl -LsSf https://astral.sh/uv/install.sh | sh
- 安装依赖:
uv sync
这将自动创建虚拟环境并安装所有依赖。
运行示例
项目提供了两个示例,展示不同的使用方式:
示例 1:完整管理后台 (simple_example.py)
cd example
uv run python simple_example.py
访问:http://localhost:4000
示例 2:简单多页面应用 (main.py)
cd example
uv run python main.py
访问:http://localhost:3000
使用 uvicorn 运行(可选)
cd example
uv run uvicorn simple_example:create_app --host 0.0.0.0 --port 4000 --reload
# 或
uv run uvicorn main:app --host 0.0.0.0 --port 3000 --reload
项目结构
fastapi-amis/
├── fastapi_amis/ # 核心框架代码
│ ├── amis/ # Amis 组件定义
│ │ ├── components.py # 组件类定义
│ │ ├── constants.py # 常量定义
│ │ ├── types.py # 类型定义
│ │ └── templates/ # Jinja2 模板
│ ├── core/ # 核心功能
│ │ ├── router.py # 路由管理
│ │ ├── site.py # 站点管理
│ │ └── views.py # 视图基类
│ └── extensions/ # 扩展功能
└── example/ # 示例代码
├── main.py # 多页面示例
└── simple_example.py # 简单示例
快速开始
- 导入必要的模块:
from fastapi import FastAPI
from fastapi_amis.core.router import AmisViewRouter
from fastapi_amis.core.site import AmisSite
from fastapi_amis.core.views import AmisView
from fastapi_amis.amis.components import Page
- 创建路由器和视图:
# 创建路由器
user_router = AmisViewRouter(name="users", type="page")
# 注册视图
@user_router.register
class UserListView(AmisView):
page_schema = "用户列表"
url = "/users"
page = Page(
title="用户列表",
body={"type": "crud", "api": "/api/users"}
)
- 创建应用并挂载站点:
app = FastAPI()
site = AmisSite(title="管理后台")
site.add_router(user_router)
site.mount_to_app(app)
开发说明
- 项目使用 Python 3.10+ 开发
- 使用 uv 作为包管理器和虚拟环境管理工具
- 遵循 FastAPI 最佳实践
- 支持异步编程
- 使用 Pydantic 进行数据验证
- 集成 Amis 前端框架
开发环境设置
- 确保已安装 uv:
curl -LsSf https://astral.sh/uv/install.sh | sh
- 安装开发依赖:
uv sync --dev
- 激活虚拟环境:
source .venv/bin/activate # Linux/Mac
# 或
.venv\Scripts\activate # Windows
参考和感谢
本项目受到了以下优秀项目的启发和影响:
特别感谢
感谢 amisadmin 团队开发的 FastAPI-Amis-Admin 项目,为我们提供了宝贵的架构参考和设计思路。
感谢百度 Amis 团队提供的优秀前端组件库,让后端开发者也能轻松构建现代化的管理界面。
贡献
欢迎提交 Issue 和 Pull Request 来改进这个项目。
Metadata
Release files for fastapi-amis 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_amis-0.0.1.tar.gz | 117.0 kB | Without provenance | Details for fastapi_amis-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_amis-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for fastapi_amis-0.0.1-py3-none-any.whl |
Total release size: 196.9 kB
Release files / fastapi_amis-0.0.1.tar.gz
| Download URL | fastapi_amis-0.0.1.tar.gz |
|---|---|
| Size | 117.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0217d600b9480f4925988b407e2bfa080ba8f734d686f5e43ec17b6b14d8f72
|
|
BLAKE2b-256 checksum How to use checksums |
a6aab445c93ea46af3125ce80902405ff3b3212601f23fd5d4435cbaf1be1b5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.22
|
Release files / fastapi_amis-0.0.1-py3-none-any.whl
| Download URL | fastapi_amis-0.0.1-py3-none-any.whl |
|---|---|
| Size | 79.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef6c01b3c483068d3fa759f51d611619c66f45e329b690b41eb69889cbd9340d
|
|
BLAKE2b-256 checksum How to use checksums |
16a7cbde2ddae0d1bbbb47c555268ef899993a63080a4d9ac2553f50395898af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.22
|
Security for fastapi-amis 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.