Version 10.0.2
Python API
Data StructuresSource Location
lang/python/

Caution: the Architecture Guide is not updated in lockstep with the code base and is not necessarily correct or complete for any specific release.

WiredTiger includes a Python API, which is useful for scripting and experimentation.

The following simple example show some highlights of the API:

import os
from wiredtiger import wiredtiger_open
# Connect to the database and open a session
os.system('rm -rf WT_HOME')
os.makedirs('WT_HOME')
conn = wiredtiger_open('WT_HOME', 'create')
session = conn.open_session()
# Create a simple table
session.create('table:T', 'key_format=S,value_format=S')
# Open a cursor and insert a record
cursor = session.open_cursor('table:T', None)
cursor.set_key('key1')
cursor.set_value('value1')
cursor.insert()
# Iterate through the records
cursor.reset()
for key, value in cursor:
print('Got record: %s : %s' % (key, value))
conn.close()

The API is implemented using SWIG. SWIG imports the <wiredtiger.h> file, and from it creates the classes and C support files needed to allow Python to import the WiredTiger library.

Not every facility that is present in the C API is available in Python. In particular, setting up custom collators, extractors, compressors, encryptors and file system implementations must all be done within the C framework.

wiredtiger_open
int wiredtiger_open(const char *home, WT_EVENT_HANDLER *event_handler, const char *config, WT_CONNECTION **connectionp)
Open a connection to a database.