poyonga
Version 0.6.0

Python Groonga客戶。 Poyonga支持HTTP和GQTP協議。
來自PIP:
PIP安裝 - 升級Poyonga
$ groonga -n grn.db#創建groonga數據庫文件 $ groonga -s grn.db#使用GQTP啟動groonga服務器
> >> from poyonga import Groonga
> >> g = Groonga ()
> >> g . protocol
'http'
> >> ret = g . call ( "status" )
> >> ret
< poyonga . result . GroongaResult object at 0x8505ccc >
> >> ret . status
0
> >> ret . body
{ u'uptime' : 427 , u'max_command_version' : 2 , u'n_queries' : 3 ,
u'cache_hit_rate' : 66.6666666666667 , u'version' : u'1.2.8' , u
'alloc_count' : 156 , u'command_version' : 1 , u'starttime' : 132
8286909 , u'default_command_version' : 1 }
> >> from poyonga import Groonga
import eventlet
eventlet . monkey_patch ()
def fetch ( cmd , ** kwargs ):
g = Groonga ()
ret = g . call ( cmd , ** kwargs )
print ret . status
print ret . body
print "*" * 40
cmds = [( "status" , {}),
( "log_level" , { "level" : "warning" }),
( "table_list" , {})
( "select" , { "table" : "Site" })]
pool = eventlet . GreenPool ()
for cmd , kwargs in cmds :
pool . spawn_n ( fetch , cmd , ** kwargs )
pool . waitall ()如果使用自定義前綴路徑和多數據庫,請指定prefix_path。
# default is '/d/'
g = Groonga ( prefix_path = '/db2/' )Groonga支持Apache Arrow,將其與load和select命令一起使用。
使用Poyonga與Apache Arrow,您需要Pyarrow。
Requrie Pyarrow:
$ pip安裝pyarrow
並使用output_type="apache-arrow"選項:
from poyonga import Groonga
g = Groonga ()
g . call (
"select" ,
table = "Users" ,
match_columns = "name,location_str,description" ,
query = "東京" ,
output_type = "apache-arrow" ,
output_columns = "_key,name" ,
)筆記
output_type還可以指定poyonga.const.outputtype.apache_arrow。如果未指定,則默認情況下指定poyonga.const.outputtype.json。
加載input_type="apache-arrow" :
import pyarrow as pa
from poyonga import Groonga
# use Apache Arrow IPC Streaming Format
data = [ pa . array ([ "groonga.org" ])]
batch = pa . record_batch ( data , names = [ "_key" ])
sink = pa . BufferOutputStream ()
with pa . ipc . new_stream ( sink , batch . schema ) as writer :
writer . write_batch ( batch )
buf = sink . getvalue ()
values = buf . to_pybytes ()
g = Groonga ()
g . call ( "load" , table = "Site" , values = values , input_type = "apache-arrow" )筆記
input_type還可以指定poyonga.const.inputtype.apache_arrow。如果未指定,則默認情況下指定poyonga.const.inputtype.json。
更多信息:
請參閱示例目錄
安裝DEV依賴項:
$ pip安裝“。[dev]”
運行測試:
$ pytest
運行linter:
$ ruff。
運行格式:
$黑色-Diff。