Version 10.0.0
Python API (Architecture Guide)
Data StructuresSource Location

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')
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)
# Iterate through the records
for key, value in cursor:
print('Got record: %s : %s' % (key, value))

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.