Web starter build with autoboot and FastAPI
Project description
autoboot web starter
基于 autoboot 框架的插件机制扩展,集成了FastAPI
框架,专注于web开发方向。
Quick Start
Install
pip install autoboot-web
Usage
配置
- 启动配置文件
.env
# 环境名称(默认值:dev,框架根据这个配置项来加载当前的环境配置)
ENV_NAME=dev
APPLICATION_NAME=web-runner
- 环境配置文件
.env.dev
APPLICATION_NAME=web-runner-dev
- 主配置文件
autoboot.yaml
autoboot:
application:
name: !env $APPLICATION_NAME
module: api
web:
http:
gzip:
enable: true
# 小于1KB不压缩
minimum_size: 1KB
session:
enable: true
cookie_name: "session_id"
max_age: 120m
security:
cors:
cross_origin: true
# 扫描控制器包
scan_controller_packages:
- controller
创建目录controller
- 在该目录下创建
__init__.py
from .controller import IndexController
__all__=["IndexController"]
- 在该目录创建
index.py
from autoboot_web.mvc.annotation import Controller, Get
@Controller(path="/", tag="index")
class IndexController:
@Get("/")
def index(self, name):
return f"Hello: {name}"
创建并启动容器
- 创建
main.py
from autoboot import AutoBoot, AutoBootConfig
from autoboot_web import WebRunner
context = Autoboot(AutoBootConfig(config_dir="."))
# 注册插件
context.apply(WebRunner())
# 暴露插件的Runner到全局变量(FastAPI使用的unicorn启动时会用到)
app = context.run(lambda: WebRunner.get_context())
# 其它使用 FastAPI 实例 app 的代码
# ...
启动服务器
uvicorn example.main:app --host 127.0.0.1 --port 8000 --env-file .env
Contributors
有问题可以在issues开话题讨论,如果你有新的想法,创建新的feat
或pref
分支并提交PR。
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
autoboot_web-0.6.0.tar.gz
(11.5 kB
view hashes)
Built Distribution
Close
Hashes for autoboot_web-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0d51748e1cd68fd38104499af078259bb92b719db2a3c61e3bcbd42763b42d7 |
|
MD5 | 9ebe0138f53a456597987320c0d6bce3 |
|
BLAKE2b-256 | 7642c54a63df8e7fb1eb37f7d3d3bd7fa33023317a554243d7e905e6164ea82c |