Python

From truxwiki.com
Jump to navigation Jump to search

Truxton supports Python 3.12 via a pyd library named Truxton.pyd. This exposes the functionality of Truxton to Python.

Overview

You must use the "import" directive to load the Truxton Python provider in a file named truxton.pyd. This directive will search a variety of folders for the pyd file for Truxton (truxton.pyd). Normally, this file is installed in the SDK folder (C:\Program Files\Truxton\SDK) along with all of the dependent files. Be sure to include the full path (e.g. c:\program files\truxton\sdk) in your PATH environment variable so that Windows can locate all the needed dependencies.

You can modify the PYTHONPATH environment variable to include the SDK folder and Python will automatically search this folder. Doing so will allow you to specify the Truxton library at the top of your scripts:

import truxton

If you don't have permission to modify environment variables, or you want to test your code with different versions of Truxton, you can manually modify Python's module search path. Instead of using PYTHONPATH environment variable, you can tell Python which folder contains truxton.pyd by adding the following to the top of your scripts:

import sys
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton

You can, within code, change which version of Truxton will be used with your script. This ensures your script will always work should a breaking change be introduced in a subsequent release of Truxton.

When you import truxton you will get all of the predefined constants for file type, data type, origins, locations, messages, entities, relations, events, media, objects, url methods, and urls. You can see them all by issuing a dir command.

>>> dir(truxton)

This will allow your Python code to use the same constant names as C, C++ and C# code.

>>> print(truxton.Type_JPEG)
203

Once you have this working, you can start playing with Truxton.

import sys
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton

def main() -> None:
  t = truxton.create()
  print(t.version)
  return None

if __name__ == "__main__":
  sys.exit(main())

Style

In general, when using a Truxton Python object, you will follow this pattern:

  1. Create the object
  2. Set the data members of the object
  3. Call save() to store the object in the Truxton database.

Until you call save(), nothing will appear in Truxton.

Classes

Truxton exposes several classes to Python.

Remarks

The Python API is designed primarily for programs to contribute to Truxton.

Truxton.pyd was developed using the C API with a thin adapter layer of code to translate from Python provider semantics to Truxton calls.

Samples