api client py
1.4.8
API开发Python客户以与柴郡猫互动。
该软件包允许实例化Websocket客户端,并提供API与所有端点进行交互。
该Python软件包的一部分是由OpenAPI Generator Project自动生成的。
有关可用端点的更深入文档,请参阅API重做。柴郡官方的猫文档可在此处找到。
Python 3.10
您可以使用pip安装API:
pip install cheshire-cat-api然后导入包:
import cheshire_cat_api as ccat CatClient具有以下属性,可以轻松地与相关的API接口:
import cheshire_cat_api as ccat
# A config is necessary to set up base parameters like
# URL, port, user_id, etc.
config = ccat . Config ( user_id = "my_user_42" )
# Connect to the API
cat_client = ccat . CatClient (
config = config
) # Now retrieve a list of the available plugins
plugins = cat_client . plugins . get_available_plugins () from cheshire_cat_api . models . body_upload_url import BodyUploadUrl
# Please note that interacting with the RabbitHole to upload
# a URL requires structuring the body like this
body_upload_url = BodyUploadUrl (
url = "https://cheshire-cat-ai.github.io/docs/conceptual/cheshire_cat/rabbit_hole/"
)
# then you can make the request as follows
response = cat_client . rabbit_hole . upload_url ( body_upload_url ) import time
import cheshire_cat_api as ccat
# A config is necessary to set up base parameters like
# URL, port, user_id, etc.
config = ccat . Config ( user_id = "my_user_42" )
cat_client = ccat . CatClient ( config = config )
# Connect to the WebSocket API
cat_client . connect_ws ()
while not cat_client . is_ws_connected :
# A better handling is strongly advised to avoid an infinite loop
time . sleep ( 1 )
# Send the message
cat_client . send ( message = "Hello Cat!" )
# Close connection
cat_client . close ()这两个类都可以提供:
from cheshire_cat_api import Config| 班级 | 姓名 | 默认 | 描述 |
|---|---|---|---|
| config | base_url | “ Local主机” | 猫的基本网址 |
| config | port | 1865年 | 连接的端口 |
| config | user_id | “用户” | 客户的ID |
| config | auth_key | “” | HTTP端点的身份验证密钥 |
| config | secure_connection | 错误的 | 如果要使用安全协议 |
对于更高级的用法,您可以直接与自动生成的客户端进行互动。有关文档,请参见此处