install_file | Script Method | Teradata Python Package - 17.00 - install_file - Teradata Package for Python

Teradata® Package for Python User Guide

Teradata Package for Python
Release Number
November 2021
English (United States)
Last Update

Use the install_file method to install or replace script on Vantage.

Required arguments:
  • file_identifier specifies the name associated with the user-installed file. It cannot have a database name associated with it, as the file is always installed in the current database. The name should be unique within the database. It can be any valid Teradata identifier.
  • file_name specifies the name of the file user wants to install.
Optional arguments:
  • is_binary specifies if the file to be installed is a binary file.
  • force_replace specifies if system should check for the file being used before replacing it:
    • If set to True, then the file is replaced even if it is being executed.
    • If set to False, then an error is thrown if it is being executed.
File can be on client or remote server. The file location should be specified accordingly.

Example 1: Install a file found at the relative path using default text mode

To run this example, "" is required on client at the path specified by argument file_local_path.
  • Create the "" file.
    import sys
    for line in sys.stdin:
        line = line.strip()
        words = line.split()
        for word in words:
            print ('%s\t%s' % (word, 1))
  • Set the search path to the database where the file is installed.
    >>> get_context().execute("SET SESSION SEARCHUIFDBPATH = <database name>;")
  • Import required packages.
    >>> from collections import OrderedDict
    >>> from teradatasqlalchemy import (VARCHAR)
  • Create a Script object that allows user to run script on Vantage.
    >>> sto = Script(data=barrierdf,
                files_local_path= 'data/scripts',
                script_command='python3 ./<database name>/',
                charset='latin', returns=OrderedDict([("word", VARCHAR(15)), ("count_input", VARCHAR(2))])
  • Install the file on Vantage.
    >>> sto.install_file(file_identifier='mapper', file_name='', is_binary=False)
    File installed in Vantage
  • After making changes to the file "", user can use the install_file method with "replace=True" to replace the existing file with the new file.
    >>> sto.install_file(file_identifier='mapper', file_name='', is_binary=False, replace=True, force_replace=True)
    File replaced in Vantage

Example 2: Install a file found at the relative path using binary mode

>>> sto.install_file (file_identifier='binaryfile', file_name='binary_file.dms', is_binary = True)
File binary_file.dms installed in Vantage