api client py
1.4.8
Pythonクライアントを開発するAPIは、Cheshire Catと対話します。
このパッケージにより、WebSocketクライアントをインスタンス化することができ、APIがすべてのエンドポイントと対話するように提供します。
このPythonパッケージの一部は、Openapiジェネレータープロジェクトによって自動的に生成されます。
利用可能なエンドポイントに関するより深いドキュメントについては、API Redocを参照してください。公式のチェシャー猫のドキュメンテーションはこちらから入手できます。
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 | 「localhost」 | 猫がホストされているベースURL |
| config | port | 1865年 | 接続用のポート |
| config | user_id | "ユーザー" | クライアントのID |
| config | auth_key | "" | HTTPエンドポイントの認証キー |
| config | secure_connection | 間違い | セキュアプロトコルを使用する場合 |
より高度な使用のために、自動生成されたクライアントと直接対話できます。ドキュメントについては、こちらをご覧ください