
ไคลเอนต์ Python Groonga Poyonga สนับสนุนโปรโตคอล HTTP และ GQTP
จาก PIP:
การติดตั้ง PIP -อัพเกรด Poyonga
$ groonga -n grn.db # สร้างไฟล์ฐานข้อมูล Groonga $ groonga -s grn.db # เริ่มเซิร์ฟเวอร์ Groonga ด้วย GQTP
> >> 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 ()หากคุณใช้พา ธ คำนำหน้าแบบกำหนดเองและฐานข้อมูลหลายตัวให้ระบุคำนำหน้า _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 Dependencies:
$ pip install ". [dev]"
เรียกใช้การทดสอบ:
$ pytest
เรียกใช้ linter:
$ ruff
เรียกใช้ Formatter:
$ Black -Diff