import pyngres as py

...

# create example_callback() 
@py.IIapi_callback
def iiapi_trace(trace_block,parmBlock=None):
    '''trace-message callback'''

    # get the trace_block argument as a Python IIAPI_TRACEPARM instance
    trp = py.IIapi_getClosure(trace_block,py.IIAPI_TRACEPARM)
    # extract the tr_message member containing a line of trace info
    tr_message = trp.tr_message
    ...

# install iiapi_trace() as the callback to handle trace-messages
tracer = py.IIapi_getCallbackPtr(iiapi_trace)
sep = py.IIAPI_SETENVPRMPARM()
sep.se_envHandle = envHandle
sep.se_paramID = py.IIAPI_EP_TRACE_FUNC
sep.se_paramValue = tracer
py.IIapi_setEnvParam(sep)
