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 | 錯誤的 | 如果要使用安全協議 |
對於更高級的用法,您可以直接與自動生成的客戶端進行互動。有關文檔,請參見此處