> For the complete documentation index, see [llms.txt](https://meetbill.gitbook.io/butterfly-user-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://meetbill.gitbook.io/butterfly-user-doc/readme.md).

# Introduction

{% hint style="info" %}
完美，不是在没有什么需要增加，而是在没有什么需要的时候去掉。
{% endhint %}

Python 轻量 web 框架 butterfly

```
    __          __  __            ______
   / /_  __  __/ /_/ /____  _____/ __/ /_  __
  / __ \/ / / / __/ __/ _ \/ ___/ /_/ / / / /
 / /_/ / /_/ / /_/ /_/  __/ /  / __/ / /_/ /
/_.___/\__,_/\__/\__/\___/_/  /_/ /_/\__, /
                                    /____/
```

Butterfly（轻量化 WSGI web 应用程序框架）如同蝴蝶一样，小而美，简单可依赖。目的是让入门变得简单快捷，能够扩展到复杂的应用程序。

> * 接入 --- 【接入】函数快速适配：普通 Python 函数可快速升级为 butterfly handler
> * 模型 --- 【模型】数据库支持：自带 ORM, 支持存储数据到 MySQL,Redis,LocalCache
> * 异步 --- 【百川】任务异步处理：任一 butterfly handler 皆可消费，异步处理 MQ 中消息
> * 定时 --- 【如期】任务定时调度：设置 butterfly handler 执行时间，定期执行 handler
> * 编排 --- 【星桥】任务依赖编排：设置 butterfly handler 依赖顺序，有序编排 handler

```
#################################################################################################<1 接入 >##
+common func----------------------------+    +butterfly handler-----------------------------------------+
|                                       |    |     ---------------(1) 增加装饰器标识 api 类型
|                                       |    |    /            ---(2) 增加 req 参数（Request 对象）
|                                       |    |   /           /
|                                       |    |@funcattr.api /
|def hello(str_info):                   |===>|def hello(req, str_info):
|    ...                                |    |    ...
|    return "OK", {"str_info": str_info}|    |    return "OK", {"str_info": str_info}
|                                       |    |    ----------------------------------
|                                       |    |    (3) 返回 stat, [data_dict 可选 ], [handler_list 可选 ]
+---------------------------------------+    +------------------+-----------------------------+---------+
################################################################|#############################|##<2 模型 >##
                                                                |                             |
                                        +----------+------------V--------------------+        |
                                        |  Media   |             Usage               |        |
                                        +----------+---------------------------------+        |
                                        |  MySQL   | ORM,Native method               |        |
                                        +----------+---------------------------------+        |
                                        |  Redis   | ORM,Native method,Baidu RAL     |        |
                                        +----------+---------------------------------+        |
                                        |Localcache| set/get ...                     |        |
                                        +----------+---------------------------------+        |
##############################################################################################|##<3 异步 >##
                  +Redis(message queue)-----------------------------------------+             |
                  | +msg------------------------+                               |             |
                  | |'{"str_info":"helloworld"}'|                               |             |
                  | +-+-------------------------+                               |             |
                  |   |       +queue-----------------------------+              |             |
                  |   +------>|         /demo_api/hello          |<---------+   |             |
                  |    lpush  +----------------------------------+   rpop   |   |             |
                  |                               +-------------------------+-+ |             |
                  |                               |'{"str_info":"helloworld"}'| |<------------+
                  |                               +---------------------------+ |
                  +-^-------------------^---------------------------------------+
####################|###################|########################################################<4 定时 >##
                                        |
        +-----------+----------+        |
        |         ruqi         |        |
        +----------------------+        |
########################################|########################################################<5 编排 >##
                                        |
                            +taskflow---+---------------------------+
                            |                    +Task------------+ |
                            |                +---|/{app}/{handler}| |
                            |                |   +----------------+ |
                            | +Job-------+   |   +Task------------+ |
                            | |          +---+---|/{app}/{handler}| |
                            | +----------+   |   +----------------+ |
                            |                |   +Task------------+ |
                            |                +---|/{app}/{handler}| |
                            |                    +----------------+ |
                            |               xingqiao                |
                            +---------------------------------------+
```
