Difference between revisions of "Python"

From truxwiki.com
Jump to navigation Jump to search
Line 2: Line 2:
  
 
=Overview=
 
=Overview=
 +
You must use the "import" directive to load the Truxton Python provider in <code>truxton.pyd</code>.
 +
This directive will search a variety of folders for the <code>[https://docs.python.org/3/faq/windows.html#is-a-pyd-file-the-same-as-a-dll pyd]</code> file for Truxton (<code>truxton.pyd</code>).
 +
Normally, the <code>truxton.pyd</code> file is installed in the SDK folder (<code>C:\Program Files\Truxton\SDK</code>).
 +
You can modify the <code>[https://docs.python.org/3/using/cmdline.html?highlight=pythonpath#envvar-PYTHONPATH PYTHONPATH]</code> environment variable.
 +
Doing so will allow you to simply put:
  
You must use the "import" directive to load this.
+
<source lang="Python">
Go to the <code>C:\Program Files\Truxton\SDK</code> folder and start Python.
+
import truxton
 +
</source>
  
<syntaxhighlight lang="Python">
+
At the top of your Python scripts.
import truxton
 
</syntaxhighlight>
 
  
When you import <code>truxton</code> you will get all of the predefined constants for [[File Types Supported | file type,]] [[DATA TYPE | data type,]] [[Origin | origins,]] [[Location Types | locations,]]
+
When you import <code>truxton</code> you will get all of the predefined constants for [[File Types Supported|file type,]] [[DATA TYPE|data type,]] [[Origin|origins,]] [[Location Types|locations,]]
[[Message Types | messages,]] [[Entity Types | entities,]] [[Relation Types | relations,]] [[Event Types | events,]] [[Media Types | media,]] [[Object Types | objects,]] [[URL Methods | url methods,]] and [[URL Types | urls.]]
+
[[Message Types|messages,]] [[Entity Types|entities,]] [[Relation Types|relations,]] [[Event Types|events,]] [[Media Types|media,]] [[Object Types|objects,]] [[URL Methods|url methods,]] and [[URL Types|urls.]]
 
You can see them all by issuing a <code>dir</code> command.
 
You can see them all by issuing a <code>dir</code> command.
  
<syntaxhighlight lang="Python">
+
<source lang="Python">
 
>>> dir(truxton)
 
>>> dir(truxton)
</syntaxhighlight>
+
</source>
  
 
This will allow your Python code to use the same constant names as C, C++ and C# code.
 
This will allow your Python code to use the same constant names as C, C++ and C# code.
  
<syntaxhighlight lang="Python">
+
<source lang="Python">
 
>>> print(truxton.Type_JPEG)
 
>>> print(truxton.Type_JPEG)
 
203
 
203
</syntaxhighlight>
+
</source>
  
 
Once you have this working, you can start playing with Truxton.
 
Once you have this working, you can start playing with Truxton.
<syntaxhighlight lang="Python">
+
<source lang="Python">
 
import truxton
 
import truxton
  
Line 35: Line 39:
 
if __name__ == "__main__":
 
if __name__ == "__main__":
 
   main()
 
   main()
</syntaxhighlight>
+
</source>
  
 
You can create a folder for your project, copy the SDK contents into it and work from there.
 
You can create a folder for your project, copy the SDK contents into it and work from there.

Revision as of 10:32, 9 February 2021

Truxton supports Python 3.8 via the Truxton.pyd library.

Overview

You must use the "import" directive to load the Truxton Python provider in truxton.pyd. This directive will search a variety of folders for the pyd file for Truxton (truxton.pyd). Normally, the truxton.pyd file is installed in the SDK folder (C:\Program Files\Truxton\SDK). You can modify the PYTHONPATH environment variable. Doing so will allow you to simply put:

import truxton

At the top of your Python scripts.

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 truxton

def main():
  t = truxton.create()
  print(t.version)

if __name__ == "__main__":
  main()

You can create a folder for your project, copy the SDK contents into it and work from there.

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