Skip to main content

Python Groonga Client

Project description

PyPI Version Build status

Python Groonga Client. poyonga support to HTTP and GQTP protocol.

Requrements

  • Python 3.6+

Installation

from pip:

pip install --upgrade poyonga

Usage

Setup Groonga Server

$ groonga -n grn.db     # create groonga database file
$ groonga -s grn.db     # start groonga server with GQTP

Basic Usage

>>> 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}
>>>

with eventlet

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()

Custom prefix path

If you use the Custom prefix path and Multi databases , specify prefix_path .

# default is '/d/'
g = Groonga(prefix_path='/db2/')

with Apache Arrow

Groonga supports Apache Arrow, use it with load and select commands.

use poyonga with Apache Arrow, you need pyarrow .

requrie pyarrow:

$ pip install pyarrow

and call with output_type="apache-arrow" option:

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",
)

load with 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")

more information:

example code

see examples directory

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

poyonga-0.5.0.tar.gz (9.6 kB view details)

Uploaded Source

File details

Details for the file poyonga-0.5.0.tar.gz.

File metadata

  • Download URL: poyonga-0.5.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.8

File hashes

Hashes for poyonga-0.5.0.tar.gz
Algorithm Hash digest
SHA256 44cbb989089170d7ff3d99a3d1e59834d3c4466f5c521ea69f010a61509110b3
MD5 ac29874b1d10a10e42ff3912929684b3
BLAKE2b-256 729f0478b93acadbab03745ce354b9c5b9e6c17fd6557fcf6f60062ddd65ac84

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page