API zur Entwicklung von Python -Kunden, um mit der Cheshire Cat zu interagieren.
Das Paket ermöglicht die Instanziierung eines WebSocket -Clients und bietet der API die Interaktion mit allen Endpunkten.
Ein Teil dieses Python -Pakets wird automatisch vom OpenAPI -Generatorprojekt generiert.
Eine tiefere Dokumentation zu den verfügbaren Endpunkten finden Sie im API -Redoc. Die offizielle Dokumentation von Cheshire Cat ist hier verfügbar.
Python 3.10
Sie können die API mit pip installieren:
pip install cheshire-cat-apiImportieren Sie dann das Paket:
import cheshire_cat_api as ccat Der CatClient verfügt über die folgenden Attribute, die leicht mit den zugehörigen APIs verknüpfen können:
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 ()Beide Klassen sind erhältlich mit:
from cheshire_cat_api import Config| Klasse | Name | Standard | Beschreibung |
|---|---|---|---|
| Konfiguration | base_url | "Lokalhost" | Basis -URL, bei der die Katze gehostet wird |
| Konfiguration | port | 1865 | Port für die Verbindung |
| Konfiguration | user_id | "Benutzer" | ID des Kunden |
| Konfiguration | auth_key | "" " | Authentifizierungsschlüssel für die HTTP -Endpunkte |
| Konfiguration | secure_connection | FALSCH | Wenn Sie sicheres Protokoll verwenden, |
Für eine fortgeschrittenere Verwendung können Sie direkt mit dem automatisch generierten Kunden interagieren. Für Dokumentation siehe hier