Skip to content

Commit

Permalink
docs: plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mic1on committed Nov 29, 2023
1 parent a904ef4 commit bbe408f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.pnpm-store/
6 changes: 3 additions & 3 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ export default withPwa(defineConfig({
sidebar: {
'/plugin': [
{
text: '扩展插件',
text: '扩展',
items: [
{
text: 'usepy-plugin-logger',
text: 'use-logger',
link: '/plugin/logger',
},
{
text: 'usepy-plugin-notify',
text: 'use-notify',
link: '/plugin/notify',
}
],
Expand Down
9 changes: 5 additions & 4 deletions docs/plugin/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# 插件
# 扩展

大部分基础较为常用的功能内置于`usepy`中,但是有一些功能并不是所有人都需要,所以我们将这些功能放在了插件中,这样可以保证`usepy`更加轻量化。

## 插件列表
## 扩展列表

- [usepy-plugin-logger](logger.md)
- [usepy-plugin-notify](notify.md)
- [use-rabbitmq](rabbitmq.md)
- [use-logger](logger.md)
- [use-notify](notify.md)
20 changes: 11 additions & 9 deletions docs/plugin/logger.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
title: usepy-plugin-logger
title: use-logger
outline: deep
---
# usepy-plugin-logger
# use-logger

::: code-group

```bash [pip]
pip install "usepy[logger]"
pip install use-logger
```
```bash [poetry]
poetry add "usepy[logger]"
poetry add use-logger
```
:::

Expand All @@ -25,7 +25,7 @@ poetry add "usepy[logger]"
## 使用

```python
from usepy import useLogger
from use_logger import useLogger

useLogger() # 使用默认配置
```
Expand All @@ -35,7 +35,7 @@ useLogger() # 使用默认配置
如果想要感受它带来的“魔法”,需要稍微配置一下。

```python
from usepy import useLogger
from use_logger import useLogger

useLogger(packages=["scrapy", "django", "usepy"])
```
Expand All @@ -50,7 +50,9 @@ useLogger(packages=["scrapy", "django", "usepy"])
`useLogger`内置一个`logstash_handler`统一化输出格式。

```python{6}
from usepy import useTimeIt, useLogger, logstash_handler
from usepy import useTimeIt
from use_logger import useLogger
from use_logger.handlers import logstash_handler
useLogger(
handlers=[
Expand Down Expand Up @@ -83,7 +85,7 @@ useTimeIt(lambda: logger.debug("start run test function"))()
```python
# app.py
from fastapi import FastAPI
from usepy import useLoggerInterceptUvicorn
from use_logger import useLoggerInterceptUvicorn

useLoggerInterceptUvicorn() # 在 app 实例化前调用即可

Expand Down Expand Up @@ -111,7 +113,7 @@ uvicorn.run(app="app:app", host="127.0.0.1")

```python
from loguru import logger
from usepy import useLogger
from use_logger import useLogger

useLogger()

Expand Down
12 changes: 6 additions & 6 deletions docs/plugin/notify.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
title: usepy-plugin-notify
title: use-notify
outline: deep
---

# usepy-plugin-logger
# use-notify

::: code-group

```bash [pip]
pip install "usepy[notify]"
pip install use-notify
```
```bash [poetry]
poetry add "usepy[notify]"
poetry add use-notify
```
:::

Expand All @@ -30,7 +30,7 @@ poetry add "usepy[notify]"
#### 使用

```python
from usepy import useNotify, useNotifyChannels
from use_notify import useNotify, useNotifyChannels

notify = useNotify()
notify.add(
Expand All @@ -50,7 +50,7 @@ notify.publish(title="消息标题", content="消息正文")
#### 自己开发消息通知

```python
from usepy.useNotifyChannels import BaseChannel
from use_notify.useNotifyChannels import BaseChannel


class Custom(BaseChannel):
Expand Down
41 changes: 41 additions & 0 deletions docs/plugin/rabbitmq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: use-rabbitmq
outline: deep
---

# use-rabbitmq

::: code-group

```bash [pip]
pip install use-rabbitmq
```
```bash [poetry]
poetry add use-rabbitmq
```
:::

一个永不断线的RabbitMQ连接管理


### example

```python
from use_rabbitmq import useRabbitMQ

rmq = useRabbitMQ()


@rmq.listener(queue_name="test")
def test_listener(message):
print(message.body)
message.ack() # ack message
```

if you use it with [usepy](https://github.com/use-py/usepy), you can use it like this:

```python
from usepy.plugin import useRabbitMQ

rmq = useRabbitMQ()
```

0 comments on commit bbe408f

Please sign in to comment.