autoboot-web


Nameautoboot-web JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://github.com/yizzuide/autoboot_web
SummaryWeb starter build with autoboot and FastAPI
upload_time2024-05-11 20:05:49
maintainerNone
docs_urlNone
authoryizzuide
requires_python>=3.8
licenseMIT
keywords autoboot web fastapi
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # autoboot web starter
基于 [autoboot](https://github.com/yizzuide/autoboot) 框架的插件机制扩展,集成了`FastAPI`框架,专注于web开发方向。
<p>
  <a href="https://pypi.org/project/autoboot-web">
      <img src="https://img.shields.io/pypi/v/autoboot-web?color=%2334D058&label=pypi%20package" alt="Version">
  </a>
  <a href="https://pypi.org/project/autoboot-web">
        <img src="https://img.shields.io/pypi/pyversions/autoboot-web.svg?color=%2334D058" alt="Python">
  </a>
  <a href="https://pepy.tech/project/autoboot-web">
      <img src="https://static.pepy.tech/personalized-badge/autoboot-web?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads" alt="Downloads">
  </a>
  <a href="https://github.com/yizzuide/autoboot-web/blob/main/LICENSE">
      <img src="https://img.shields.io/github/license/yizzuide/autoboot-web" alt="License">
  </a>
</p>

## Quick Start

### Install
```sh
pip install autoboot-web
```

### Usage
#### 配置

* 启动配置文件`.env`
```ini
# 环境名称(默认值:dev,框架根据这个配置项来加载当前的环境配置)
ENV_NAME=dev

APPLICATION_NAME=web-runner
```

* 环境配置文件`.env.dev`
```ini
APPLICATION_NAME=web-runner-dev
```

* 主配置文件`autoboot.yaml`
```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`
```py
from .controller import IndexController

__all__=["IndexController"]
```

* 在该目录创建`index.py`
```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`
```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 的代码
# ...
```

#### 启动服务器
```bash
uvicorn example.main:app --host 127.0.0.1 --port 8000 --env-file .env
```

## Contributors
有问题可以在issues开话题讨论,如果你有新的想法,创建新的`feat`或`pref`分支并提交PR。

## License
[MIT License](https://github.com/yizzuide/autoboot/blob/main/LICENSE.txt)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/yizzuide/autoboot_web",
    "name": "autoboot-web",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "autoboot, web, FastAPI",
    "author": "yizzuide",
    "author_email": "fu837014586@163.com",
    "download_url": "https://files.pythonhosted.org/packages/42/54/3d167b923a1f870ff7111045c348f4d6405f350a7c701eb56607967dcd96/autoboot_web-0.6.0.tar.gz",
    "platform": null,
    "description": "# autoboot web starter\n\u57fa\u4e8e [autoboot](https://github.com/yizzuide/autoboot) \u6846\u67b6\u7684\u63d2\u4ef6\u673a\u5236\u6269\u5c55\uff0c\u96c6\u6210\u4e86`FastAPI`\u6846\u67b6\uff0c\u4e13\u6ce8\u4e8eweb\u5f00\u53d1\u65b9\u5411\u3002\n<p>\n  <a href=\"https://pypi.org/project/autoboot-web\">\n      <img src=\"https://img.shields.io/pypi/v/autoboot-web?color=%2334D058&label=pypi%20package\" alt=\"Version\">\n  </a>\n  <a href=\"https://pypi.org/project/autoboot-web\">\n        <img src=\"https://img.shields.io/pypi/pyversions/autoboot-web.svg?color=%2334D058\" alt=\"Python\">\n  </a>\n  <a href=\"https://pepy.tech/project/autoboot-web\">\n      <img src=\"https://static.pepy.tech/personalized-badge/autoboot-web?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads\" alt=\"Downloads\">\n  </a>\n  <a href=\"https://github.com/yizzuide/autoboot-web/blob/main/LICENSE\">\n      <img src=\"https://img.shields.io/github/license/yizzuide/autoboot-web\" alt=\"License\">\n  </a>\n</p>\n\n## Quick Start\n\n### Install\n```sh\npip install autoboot-web\n```\n\n### Usage\n#### \u914d\u7f6e\n\n* \u542f\u52a8\u914d\u7f6e\u6587\u4ef6`.env`\n```ini\n# \u73af\u5883\u540d\u79f0\uff08\u9ed8\u8ba4\u503c\uff1adev\uff0c\u6846\u67b6\u6839\u636e\u8fd9\u4e2a\u914d\u7f6e\u9879\u6765\u52a0\u8f7d\u5f53\u524d\u7684\u73af\u5883\u914d\u7f6e\uff09\nENV_NAME=dev\n\nAPPLICATION_NAME=web-runner\n```\n\n* \u73af\u5883\u914d\u7f6e\u6587\u4ef6`.env.dev`\n```ini\nAPPLICATION_NAME=web-runner-dev\n```\n\n* \u4e3b\u914d\u7f6e\u6587\u4ef6`autoboot.yaml`\n```yaml\nautoboot:\n  application:\n    name: !env $APPLICATION_NAME\n    module: api\n\n  web:\n    http:\n      gzip:\n        enable: true\n        # \u5c0f\u4e8e1KB\u4e0d\u538b\u7f29\n        minimum_size: 1KB\n      session:\n        enable: true\n        cookie_name: \"session_id\"\n        max_age: 120m\n    security:\n      cors:\n        cross_origin: true\n\n    # \u626b\u63cf\u63a7\u5236\u5668\u5305\n    scan_controller_packages:\n      - controller\n```\n\n#### \u521b\u5efa\u76ee\u5f55`controller`\n\n* \u5728\u8be5\u76ee\u5f55\u4e0b\u521b\u5efa`__init__.py`\n```py\nfrom .controller import IndexController\n\n__all__=[\"IndexController\"]\n```\n\n* \u5728\u8be5\u76ee\u5f55\u521b\u5efa`index.py`\n```py\nfrom autoboot_web.mvc.annotation import Controller, Get\n\n\n@Controller(path=\"/\", tag=\"index\")\nclass IndexController:\n  \n  @Get(\"/\")\n  def index(self, name):\n    return f\"Hello: {name}\"\n```\n\n#### \u521b\u5efa\u5e76\u542f\u52a8\u5bb9\u5668\n* \u521b\u5efa`main.py`\n```py\nfrom autoboot import AutoBoot, AutoBootConfig\nfrom autoboot_web import WebRunner\n\ncontext = Autoboot(AutoBootConfig(config_dir=\".\"))\n# \u6ce8\u518c\u63d2\u4ef6\ncontext.apply(WebRunner())\n# \u66b4\u9732\u63d2\u4ef6\u7684Runner\u5230\u5168\u5c40\u53d8\u91cf\uff08FastAPI\u4f7f\u7528\u7684unicorn\u542f\u52a8\u65f6\u4f1a\u7528\u5230\uff09\napp = context.run(lambda: WebRunner.get_context())\n\n# \u5176\u5b83\u4f7f\u7528 FastAPI \u5b9e\u4f8b app \u7684\u4ee3\u7801\n# ...\n```\n\n#### \u542f\u52a8\u670d\u52a1\u5668\n```bash\nuvicorn example.main:app --host 127.0.0.1 --port 8000 --env-file .env\n```\n\n## Contributors\n\u6709\u95ee\u9898\u53ef\u4ee5\u5728issues\u5f00\u8bdd\u9898\u8ba8\u8bba\uff0c\u5982\u679c\u4f60\u6709\u65b0\u7684\u60f3\u6cd5\uff0c\u521b\u5efa\u65b0\u7684`feat`\u6216`pref`\u5206\u652f\u5e76\u63d0\u4ea4PR\u3002\n\n## License\n[MIT License](https://github.com/yizzuide/autoboot/blob/main/LICENSE.txt)\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Web starter build with autoboot and FastAPI",
    "version": "0.6.0",
    "project_urls": {
        "Homepage": "https://github.com/yizzuide/autoboot_web"
    },
    "split_keywords": [
        "autoboot",
        " web",
        " fastapi"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7642c54a63df8e7fb1eb37f7d3d3bd7fa33023317a554243d7e905e6164ea82c",
                "md5": "9ebe0138f53a456597987320c0d6bce3",
                "sha256": "e0d51748e1cd68fd38104499af078259bb92b719db2a3c61e3bcbd42763b42d7"
            },
            "downloads": -1,
            "filename": "autoboot_web-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9ebe0138f53a456597987320c0d6bce3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10855,
            "upload_time": "2024-05-11T20:05:48",
            "upload_time_iso_8601": "2024-05-11T20:05:48.429680Z",
            "url": "https://files.pythonhosted.org/packages/76/42/c54a63df8e7fb1eb37f7d3d3bd7fa33023317a554243d7e905e6164ea82c/autoboot_web-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "42543d167b923a1f870ff7111045c348f4d6405f350a7c701eb56607967dcd96",
                "md5": "fd9160456c92e8588f43e2a3bfaf1780",
                "sha256": "cf794bfc1caee755355ac256f67304ae24590ae1f2e244db49f79606deb2da4d"
            },
            "downloads": -1,
            "filename": "autoboot_web-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fd9160456c92e8588f43e2a3bfaf1780",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 11457,
            "upload_time": "2024-05-11T20:05:49",
            "upload_time_iso_8601": "2024-05-11T20:05:49.723312Z",
            "url": "https://files.pythonhosted.org/packages/42/54/3d167b923a1f870ff7111045c348f4d6405f350a7c701eb56607967dcd96/autoboot_web-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-11 20:05:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yizzuide",
    "github_project": "autoboot_web",
    "github_not_found": true,
    "lcname": "autoboot-web"
}
        
Elapsed time: 0.28510s