fastapi_scheduler


Namefastapi_scheduler JSON
Version 0.0.4 PyPI version JSON
download
home_pageNone
SummaryFastAPI-Scheduler is a simple scheduled task management FastAPI extension based on APScheduler.
upload_time2022-05-14 05:57:32
maintainerNone
docs_urlNone
authorNone
requires_python>=3.6.1
licenseNone
keywords fastapi-amis-admin fastapi-apscheduler fastapi-scheduler apscheduler
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h2 align="center">
  FastAPI-Scheduler
</h2>

## 项目介绍

`FastAPI-Scheduler`是一个基于`APScheduler`的简单定时任务管理`FastAPI`拓展库.

## 安装

```bash
pip install fastapi-scheduler
```

## 简单示例

**main.py**:

```python
from fastapi import FastAPI
from fastapi_amis_admin.amis_admin.settings import Settings
from fastapi_amis_admin.amis_admin.site import AdminSite
from datetime import date
from fastapi_scheduler import SchedulerAdmin

# 创建`FastAPI`应用
app = FastAPI()

# 创建`AdminSite`实例
site = AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///admisadmin.db'))

# 创建定时任务调度器`SchedulerAdmin`实例
scheduler = SchedulerAdmin.bind(site)


# 添加定时任务,参考官方文档: https://apscheduler.readthedocs.io/en/master/
# use when you want to run the job at fixed intervals of time
@scheduler.scheduled_job('interval', seconds=60)
def interval_task_test():
    print('interval task is run...')


# use when you want to run the job periodically at certain time(s) of day
@scheduler.scheduled_job('cron', hour=3, minute=30)
def cron_task_test():
    print('cron task is run...')


# use when you want to run the job just once at a certain point of time
@scheduler.scheduled_job('date', run_date=date(2022, 11, 11))
def date_task_test():
    print('date task is run...')


# 挂载后台管理系统
site.mount_app(app)


@app.on_event("startup")
async def startup():
    # 启动定时任务调度器
    scheduler.start()


if __name__ == '__main__':
    import uvicorn

    uvicorn.run(app, debug=True)
```
## 界面预览

- Open `http://127.0.0.1:8000/admin/` in your browser:

![SchedulerAdmin](https://s2.loli.net/2022/05/10/QEtCLsWi1389BKH.png)

## 依赖项目

- [FastAPI-Amis-Admin](https://docs.amis.work/)

- [APScheduler](https://apscheduler.readthedocs.io/en/master/)

## 许可协议

该项目遵循 Apache2.0 许可协议。

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fastapi_scheduler",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6.1",
    "maintainer_email": "Atomi <1456417373@qq.com>",
    "keywords": "fastapi-amis-admin,fastapi-APScheduler,fastapi-scheduler,APScheduler",
    "author": null,
    "author_email": "Atomi <1456417373@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/00/0a/96142ea38711f0541db525b87e1779cf03ca1ad75516e7308bceee173da8/fastapi_scheduler-0.0.4.tar.gz",
    "platform": null,
    "description": "<h2 align=\"center\">\n  FastAPI-Scheduler\n</h2>\n\n## \u9879\u76ee\u4ecb\u7ecd\n\n`FastAPI-Scheduler`\u662f\u4e00\u4e2a\u57fa\u4e8e`APScheduler`\u7684\u7b80\u5355\u5b9a\u65f6\u4efb\u52a1\u7ba1\u7406`FastAPI`\u62d3\u5c55\u5e93.\n\n## \u5b89\u88c5\n\n```bash\npip install fastapi-scheduler\n```\n\n## \u7b80\u5355\u793a\u4f8b\n\n**main.py**:\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_amis_admin.amis_admin.settings import Settings\nfrom fastapi_amis_admin.amis_admin.site import AdminSite\nfrom datetime import date\nfrom fastapi_scheduler import SchedulerAdmin\n\n# \u521b\u5efa`FastAPI`\u5e94\u7528\napp = FastAPI()\n\n# \u521b\u5efa`AdminSite`\u5b9e\u4f8b\nsite = AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///admisadmin.db'))\n\n# \u521b\u5efa\u5b9a\u65f6\u4efb\u52a1\u8c03\u5ea6\u5668`SchedulerAdmin`\u5b9e\u4f8b\nscheduler = SchedulerAdmin.bind(site)\n\n\n# \u6dfb\u52a0\u5b9a\u65f6\u4efb\u52a1,\u53c2\u8003\u5b98\u65b9\u6587\u6863: https://apscheduler.readthedocs.io/en/master/\n# use when you want to run the job at fixed intervals of time\n@scheduler.scheduled_job('interval', seconds=60)\ndef interval_task_test():\n    print('interval task is run...')\n\n\n# use when you want to run the job periodically at certain time(s) of day\n@scheduler.scheduled_job('cron', hour=3, minute=30)\ndef cron_task_test():\n    print('cron task is run...')\n\n\n# use when you want to run the job just once at a certain point of time\n@scheduler.scheduled_job('date', run_date=date(2022, 11, 11))\ndef date_task_test():\n    print('date task is run...')\n\n\n# \u6302\u8f7d\u540e\u53f0\u7ba1\u7406\u7cfb\u7edf\nsite.mount_app(app)\n\n\n@app.on_event(\"startup\")\nasync def startup():\n    # \u542f\u52a8\u5b9a\u65f6\u4efb\u52a1\u8c03\u5ea6\u5668\n    scheduler.start()\n\n\nif __name__ == '__main__':\n    import uvicorn\n\n    uvicorn.run(app, debug=True)\n```\n## \u754c\u9762\u9884\u89c8\n\n- Open `http://127.0.0.1:8000/admin/` in your browser:\n\n![SchedulerAdmin](https://s2.loli.net/2022/05/10/QEtCLsWi1389BKH.png)\n\n## \u4f9d\u8d56\u9879\u76ee\n\n- [FastAPI-Amis-Admin](https://docs.amis.work/)\n\n- [APScheduler](https://apscheduler.readthedocs.io/en/master/)\n\n## \u8bb8\u53ef\u534f\u8bae\n\n\u8be5\u9879\u76ee\u9075\u5faa Apache2.0 \u8bb8\u53ef\u534f\u8bae\u3002\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "FastAPI-Scheduler is a simple scheduled task management FastAPI extension based on APScheduler.",
    "version": "0.0.4",
    "split_keywords": [
        "fastapi-amis-admin",
        "fastapi-apscheduler",
        "fastapi-scheduler",
        "apscheduler"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "md5": "12ca3a793c5fd9053962d7e7ff06c5ba",
                "sha256": "a8b12e8205719e851c491fb8a773f58b1064a569220040522722400887e30385"
            },
            "downloads": -1,
            "filename": "fastapi_scheduler-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "12ca3a793c5fd9053962d7e7ff06c5ba",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.1",
            "size": 5446,
            "upload_time": "2022-05-14T05:57:30",
            "upload_time_iso_8601": "2022-05-14T05:57:30.015977Z",
            "url": "https://files.pythonhosted.org/packages/f0/16/eab3f4d6c829fa18029d39c3396c77b4fcbcbe82a7a17aed283b12e9a675/fastapi_scheduler-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "md5": "e29863af13dc67242acf838ff66ba602",
                "sha256": "51208cc9cfcb19d38e7272a083f3431e1f6d10f587f9c5eb0940c90c1fde9713"
            },
            "downloads": -1,
            "filename": "fastapi_scheduler-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "e29863af13dc67242acf838ff66ba602",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.1",
            "size": 6334,
            "upload_time": "2022-05-14T05:57:32",
            "upload_time_iso_8601": "2022-05-14T05:57:32.350069Z",
            "url": "https://files.pythonhosted.org/packages/00/0a/96142ea38711f0541db525b87e1779cf03ca1ad75516e7308bceee173da8/fastapi_scheduler-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-05-14 05:57:32",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "fastapi_scheduler"
}
        
Elapsed time: 0.34129s