poyonga
Version 0.6.0

Python Groogaクライアント。 HTTPおよびGQTPプロトコルへのPoyongaサポート。
ピップから:
PIPインストール - ポヨンガのアップグレード
$ groonga -n grn.db#Groogaデータベースファイルを作成します $ 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/' )Groogaは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はデフォルトで指定されています。
詳細:
例ディレクトリを参照してください
開発者の依存関係をインストールします:
$ pip install "。[dev]"
テストの実行:
$ pytest
ラン・リナー:
$ ruff。
Formatterを実行:
$ black - ディフ。