Skip to main content

Web starter build with autoboot and FastAPI

Project description

autoboot web starter

基于 autoboot 框架的插件机制扩展,集成了FastAPI框架,专注于web开发方向。

Version Python Downloads License

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开话题讨论,如果你有新的想法,创建新的featpref分支并提交PR。

License

MIT 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.7.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

autoboot_web-0.7.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file autoboot_web-0.7.0.tar.gz.

File metadata

  • Download URL: autoboot_web-0.7.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/40.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.65.0 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.6

File hashes

Hashes for autoboot_web-0.7.0.tar.gz
Algorithm Hash digest
SHA256 09a389d5f855ceeee6d4e29145592b3ae345ed608847fbdf095d437fc8dc06f9
MD5 c04a79b4de7ed8a5ff55520b4113b406
BLAKE2b-256 9edf3215721decc42873b16644a9cfb19573625c32ecc32f2989e0bf43af3721

See more details on using hashes here.

File details

Details for the file autoboot_web-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: autoboot_web-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/40.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.65.0 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.6

File hashes

Hashes for autoboot_web-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67b4b632fce50030866f32f6696e7fffb8b248146b342b2aa19ab117a5742d6c
MD5 3242e8d089d2b21aa30d68561a9db172
BLAKE2b-256 03cb66ad657c4618aadc15d7963dd9a9819f502c276b9561afab5056e50135c9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page