A Python Wrapper to the Notes C API

An article in the DominoPower Magazine details the options one has in these days to use Python for accessing Notes databases. There is a third way, using the IIOP interface used for the pure java lib together with a CORBA library for Python. If you want to do more than the provided LotusScript/Java/COM api allows, there is the C and C++ apis which are somewhat cumbersome to program with, so the ideal thing would be to wrap the C api in Python.

The pynotes Python module is such a wrapper of the C API (although it doesn't do as much as the Java API at this point).

The advantage of using Python is that Python, unlike Java, does not use garbage collection (a thread runs around looking for stuff you don't need anymore) but reference counting. So, an object that has no references to it anymore is freed immediately without any need for you to call recycle() for the objects you don't need anymore.

Here is an example script that uses pynotes:

import pynotes

def dump_fields(note):
    for f in note.items():
	print "%16s : %s"%(f,`note[f]`)

def test():
    for noteid in db.query():
        print "--- Note: 0x%x "%(noteid)

if __name__ == '__main__':

db.query() gives a list of all NoteIDs (a number identifying a document in a Notes database) in the opened database. You could also do a db.query('status="3"') or similar, just as with the Database.search() method of the Java API.

Something which can be done in pynotes but can't (as of R5) with the Java Notes API is the analysis of richtext fields. This is only slightly more comfortable than with the C API, but you can write Python functions to wrap the translated data in an arbitrary format, like HTML.

You can download the code (and a binary for Linux) at the project page at SourceForge. If you have questions, feel free to contact me at pynotes at versley.de (email adress obfuscated for the obvious reasons).
SourceForge Logo