python sonic client
1.0.0
用於聲音搜尋後端的 Python 客戶端。
pip install sonic-client
from sonic import IngestClient
with IngestClient ( "127.0.0.1" , 1491 , "password" ) as ingestcl :
print ( ingestcl . ping ())
print ( ingestcl . protocol )
print ( ingestcl . bufsize )
ingestcl . push ( "wiki" , "articles" , "article-1" , "for the love of god hell" )
ingestcl . push ( "wiki" , "articles" , "article-2" , "for the love of satan heaven" )
ingestcl . push ( "wiki" , "articles" , "article-3" , "for the love of lorde hello" )
ingestcl . push ( "wiki" , "articles" , "article-4" , "for the god of loaf helmet" )
from sonic import SearchClient
with SearchClient ( "127.0.0.1" , 1491 , "password" ) as querycl :
print ( querycl . ping ())
print ( querycl . query ( "wiki" , "articles" , "for" ))
print ( querycl . query ( "wiki" , "articles" , "love" ))
print ( querycl . suggest ( "wiki" , "articles" , "hell" ))
from sonic import ControlClient
with ControlClient ( "127.0.0.1" , 1491 , "password" ) as controlcl :
print ( controlcl . ping ())
controlcl . trigger ( "consolidate" )
API 文件可以在 docs/api 和 Browsable 中找到
asonic 使用 asyncio,而該客戶端沒有。它源自於需要在 gevent 上下文中使用 sonic