Skip to content
tmaesaka edited this page May 23, 2011 · 3 revisions

python-kyototycoon

Introduction goes here.

Simple Example

Set / Get Example

from kyototycoon import KyotoTycoon

kt = KyotoTycoon()

kt.open()
kt.set('key', 'abc')
value = kt.get('key')
kt.close()

Connecting to a specific server

By default, python-kyototycoon connects to the localhost on port 1978 (default port of Kyoto Tycoon). Alternatively, you can choose to connect to a server of your choice when you open a new connection.

kt.open(HOSTNAME, PORT_NUMBER)

Additionally, you can choose to specify a timeout (in seconds).

kt.open(HOSTNAME, PORT_NUMBER, TIMEOUT)

Data Serialization and Interoperability

By default, python-kyototycoon serializes data using the Python picke module. This means that by default, data sent over the wire / stored on Kyoto Tycoon can (generally) only be processed by Python. In order to achieve data interoperability, you can choose to use the optional JSON serializer or override the seralizer yourself. This functionality is currently in progress.

Get, Set and Remove Records in Bulk

In some cases, you may know that the set of records that you’re interested is stored on a particular server/node. You may alternatively want to store a set of records on a particular node. For cases like this, you can choose to perform bulk operation and save on network round-trips and method call costs.

By default, all bulk operations in python-kyototycoon is enabled to perform operations atomically. You can choose to abandon atomicity by providing “atomic=false” as an argument to the methods but this is not recommended.

Getting Records in Bulk

key_list = ['apple', 'banana', 'cranberry', 'durian']
r_dict = kt.get_bulk(key_list)

Setting Records in Bulk

records = {
    'apple': 'apple pie',
    'banana': 'banana cake',
    'cranberry': 'cranberry juice',
    'durian': 'smells'
}
num_successful = kt.set_bulk(records)

Removing Records in Bulk

key_list = ['apple', 'banana', 'cranberry', 'durian']
num_deleted = kt.remove_bulk(key_list)