api client py
1.4.8
API เพื่อพัฒนาลูกค้า Python เพื่อโต้ตอบกับแมว Cheshire
แพ็คเกจช่วยให้ไคลเอนต์ WebSocket อินสแตนซ์อินสแตนซ์และให้ API โต้ตอบกับจุดสิ้นสุดทั้งหมด
ส่วนหนึ่งของแพ็คเกจ Python นี้ถูกสร้างขึ้นโดยอัตโนมัติโดยโครงการ OpenAPI Generator
สำหรับเอกสารที่ลึกซึ้งยิ่งขึ้นเกี่ยวกับจุดสิ้นสุดที่มีอยู่โปรดดูที่ API redoc เอกสารอย่างเป็นทางการของ Cheshire Cat มีอยู่ที่นี่
Python 3.10
คุณสามารถติดตั้ง API ด้วย pip :
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| ระดับ | ชื่อ | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| การกำหนดค่า | base_url | "localhost" | URL พื้นฐานที่เป็นเจ้าภาพแมว |
| การกำหนดค่า | port | พ.ศ. 2408 | พอร์ตสำหรับการเชื่อมต่อ |
| การกำหนดค่า | user_id | "ผู้ใช้" | id ของลูกค้า |
| การกำหนดค่า | auth_key | - | คีย์การรับรองความถูกต้องสำหรับจุดสิ้นสุด HTTP |
| การกำหนดค่า | secure_connection | เท็จ | หากใช้โปรโตคอลที่ปลอดภัย |
สำหรับการใช้งานขั้นสูงมากขึ้นคุณสามารถโต้ตอบกับไคลเอนต์ที่สร้างอัตโนมัติได้โดยตรง สำหรับเอกสารดูที่นี่