> 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                |
                            +---------------------------------------+
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://meetbill.gitbook.io/butterfly-user-doc/readme.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
