4 Star 8 Fork 5

Pear Admin / Pear Admin Fastapi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Pear Admin FastAPI

介绍

本项目是使用 fastapi_template 生成的.

本项目将使用 fastapi 和 pear admin next(基于layui-vue) 开发一个完善的管理系统

Poetry 包管理器

本项目使用 poetry. 这是一种现代依赖关系管理工具.

要运行项目, 请使用以下命令:

poetry install
poetry run python -m pear_admin_fastapi

这将在配置的主机上启动服务器.

您可以在 /api/docs 中找到 swagger 的文档.

您可以在这里阅读更多关于诗歌的信息:https://python-poetry.org/

Docker 容器部署

您可以使用以下命令使用 docker 启动项目:

docker-compose -f deploy/docker-compose.yml --project-directory . up --build

如果您想在 docker 中使用 autoreload 进行开发, 请将 -f deploy/docker-compose.dev.yml 添加到您的 docker 命令中.

例:

docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml --project-directory . up --build

此命令在端口 8000 上公开 Web 应用程序, 挂载当前目录并启用自动重新加载.

但是每次使用以下命令修改 poetry.lockpyproject.toml 时, 您都必须重新构建:

docker-compose -f deploy/docker-compose.yml --project-directory . build

项目结构

$ tree "pear_admin_fastapi"
pear_admin_fastapi
├── conftest.py  # Fixtures for all tests.
├── db  # module contains db configurations
│   ├── dao  # Data Access Objects. Contains different classes to interact with database.
│   └── models  # Package contains different models for ORMs.
├── __main__.py  # Startup script. Starts uvicorn.
├── services  # Package for different external services such as rabbit or redis etc.
├── settings.py  # Main configuration settings for project.
├── static  # Static content.
├── tests  # Tests for project.
└── web  # Package contains web server. Handlers, startup config.
    ├── api  # Package with all handlers.
    │   └── router.py  # Main router.
    ├── application.py  # FastAPI application configuration.
    └── lifetime.py  # Contains actions to perform on startup and shutdown.

项目配置

可以使用环境变量配置此应用程序.

您可以在根目录中创建 .env 文件并放置所有环境变量.

所有环境变量都应以 PEAR_ADMIN_FASTAPI_ 前缀开头.

例如, 如果您在 pear_admin_fastapi/settings.py 中看到一个名为 random_parameter 的变量, 您应该提供 PEAR_ADMIN_FASTAPI_RANDOM_PARAMETER变量来配置值. 可以通过修改 env_prefix 属性来更改此行为, 在 pear_admin_fastapi.settings.Settings.Config 中.

.env 文件的示例:

PEAR_ADMIN_FASTAPI_RELOAD="True"
PEAR_ADMIN_FASTAPI_PORT="8000"
PEAR_ADMIN_FASTAPI_ENVIRONMENT="dev"

您可以在此处阅读有关 BaseSettings 类的更多信息: https://pydantic-docs.helpmanual.io/usage/settings/

Pre-commit 项目规范

要安装预提交, 只需在 shell 中运行:

pre-commit install

预提交对于在发布代码之前检查代码非常有用. 它是使用 .pre-commit-config.yaml 文件配置的.

默认情况下, 它运行:

  • black (格式化您的代码);
  • mypy (验证类型);
  • iSort (对所有文件中的导入进行排序);
  • Flake8 (发现可能的错误);

您可以在此处阅读有关预提交的更多信息: https://pre-commit.com/

Migrations 数据库迁移

如果要迁移数据库, 应运行以下命令:

# To run all migrations until the migration with revision_id.
alembic upgrade "<revision_id>"

# To perform all pending migrations.
alembic upgrade "head"

还原迁移

如果要还原迁移, 则应运行:

# revert all migrations up to: revision_id.
alembic downgrade <revision_id>

# Revert everything.
alembic downgrade base

生成迁移

要生成迁移, 您应该运行:

# For automatic change detection.
alembic revision --autogenerate

# For empty file generation.
alembic revision
MIT License Copyright (c) 2023 Huo-WenBo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基 于 fastapi 的 快 速 开 发 框 架 展开 收起
Python 等 4 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/pear-admin/pear-admin-fastapi.git
git@gitee.com:pear-admin/pear-admin-fastapi.git
pear-admin
pear-admin-fastapi
Pear Admin Fastapi
main

搜索帮助