SmartOps Logo

Tracking & Managing Materials Flow
through Industrial Supply Chains

Resources Button

Tau Adaptor Sample Python Code

Here is a Python script, using Tau Adaptor principles and libraries, to transfer the latest updates from the Customer table in a DEX database to the corresponding table in the BellHawk database. DEX is a simplified mirror database for the BellHawk database. It is typically installed as a SQL Server database on a Windows server computer on the same LAN as WIPtracker and is used as a simplified way for external systems to exchange data with a BellHawk database.

#Transfers Customer Data from DEX database to BellHawk database
1 mxp = iap_initialize()
2 BHinst = MXPclass("Customer","BellHawk")        # BellHawk Adaptor Class Instance
3 DEXinst = MXPclass("DEX2BH-Customer","DEX")     # DEX Adaptor Class Instance
4 n = DEXinst.Fetch("Latest") #Fetch New or Updted Records
5 for i in range(n):
6 # get next Customer HLDO instance as JSON string from DEX and convert to Dict
7   DEXcust = json.loads(DEXinst.GetNext())
8   BHcust = {} # create empty dictionary
9   BHcust["CustomerNumber"] = DEXcust["CustomerNumber"]
10  BHCust["CustomerName"] = DEXcust["CustomerName"]
11  # store Customer data into BellHawk database by converting to JSON sting
12  success = BHInst.Store(json.dumps(BHcust), "C")

Here:

  1. We initialize an instance of the MxPclass, which grants access to TauAdaptor methods
  2. We create an Adaptor Class Instance BHinst for the customer table in BellHawk by calling MxPclass, with the High Level Data Object (HLDO) name “Customer” and the Database Adaptor name “BellHawk”.
  3. These adaptors are used to access specific tables in the database using a Tau Adaptor abstraction, as described in the next section.
  4. We create an Adaptor Class Instance DEXinst for the DEX2BH-Customer table in the DEX database by calling MxPclass, with the High Level Data Object (HLDO) name “DEX2BH-Customer” and the Database Adaptor name “DEX”.
  5. Fetch latest updated records from the source instance DEXinst and return the number of records fetched, which can be zero if there are no updated records since the last Fetch on this Adaptor Class Instance
  6. Loop through Fetched records
  7. Comment
  8. Get next record from the fetched set from the DEX adaptor instant as a JSON string and convert it to a Python dictionary named DEXcust.
  9. Instantiate empty dictionary named BHcust to hold values to be stored in the BellHawk database.
  10. Assign BHcust dictionary value for “CustomerNumber” to corresponding entry in dictionary DEXcust.
  11. Assign BHcust dictionary value for “CustomerName” to corresponding entry in dictionary DEXcust.
  12. Comment
  13. Here we take the BHcust dictionary and convert it to a JSON string, which is passed to the Store function of the BHinst adaptor instance. Store returns a True/False value to indicate whether the Store was successful or not.

The important thing to realize is that all the person writing the script needs to know is the adaptor names for the two databases, the names of the HLDOs corresponding to the tables in question and the parameter names, corresponding the the filed names. They do not need to know anything about the underlying structure of the databases, or whether a database field is a direct of indirect reference to the data, or whether the record already exists and needs updating or a new record needs to be created. This is all taken care of by the Tau Adaptor libraries.

These libraries also track when a user or intelligent agent or external system last accessed a record. They are then able to automate the fetching of just the latest updates to a database table for that user, agent, or external system.

In the following sections, we will learn how the adaptors and HLDOs are defined and provide the link to physical database records. Please click here to learn about Database Adaptors.

TauAdaptor HLDOs Sample Code Adaptors Web Services


Copyright © SmartOpsMgt LLC 2026