Use the install_file function to install or replace a file from client machine to the remote user environment created in Vantage.
- If file size is less than or equal to 10 MB, the function installs the file synchronously and returns the status of installation.
- If file size is greater than 10 MB, it depends on the setting of the argumentasynchronous whether the function installs the file synchronously:
- If asynchronous is set to False, it installs the file synchronously and returns the status of installation.
- If asynchronous is set to True, the function installs the file asynchronously and returns claim-id that can be used to check the installation status using status.
Required Argument
- file_path
- Specifies absolute or relative path of the file (including file name) to be installed in the remote user environment.
Optional Argument
- replace
- Specifies whether to forcefully replace the file in the remote user environment.
**kwargs: Specifies the keyword arguments.
- suppress_output
- Specifies whether to print the output message.
- asynchronous
- Specifies whether to install the file in remote user environment synchronously or asynchronously.
- timeout
- Specifies the time to wait in seconds for installing the file. If the file is not installed with in timeout seconds, the function returns a claim-id and you can check the status using the claim-id. If timeout is not specified, then there is no limit on the wait time.This argument is ignored when argument asynchronous is True.
The return of this function depends on the file size:
- If file size is less than or equal to 10 MB and operation is successful, it returns True.
- If file size is greater than 10 MB, it returns a string type 'claim_id'.
Example Prerequisite
Create remote user environment for the following examples.
>>> env = create_env('testenv', 'python_3.7.9', 'Test environment')
User environment testenv created.
Example 1: Install the file mapper.py in the 'testenv' environment
>>> import os, teradataml
>>> file_path = os.path.join(os.path.dirname(teradataml.__file__), "data", "scripts", "mapper.py")
>>> env.install_file(file_path = file_path)
File 'mapper.py' installed successfully in the remote user environment 'testenv'.
Example 2: Replace the file mapper.py
>>> file_path = os.path.join(os.path.dirname(teradataml.__file__), "data", "scripts", "mapper.py")
>>> env.install_file(file_path = file_path, replace=True)
File 'mapper.py' replaced successfully in the remote user environment 'testenv'.
Example 3: Install the file 'large_file' asynchronously
This example installs the file 'large_file' asynchronously with 'large_file' found in temp folder and check the status of installation.
Running this example creates a file 'large_file' with size approximately 11MB in the temp folder.
- Import required packages.
>>> import tempfile, os
- Create the large file.
>>> def create_large_file(): file_name = os.path.join(tempfile.gettempdir(),"large_file") with open(file_name, 'xb') as fp: fp.seek((1024 * 1024 * 11) - 1) fp.write(b'\0')
>>> create_large_file()
- Install the large file asynchronously.
>>> claim_id = env.install_file(file_path = os.path.join(tempfile.gettempdir(),"large_file"), asynchronous=True)
File installation is initiated. Check the status using status() with the claim id 76588d13-6e20-4892-9686-37768adcfadb.
- Check the status of the installation.
>>> env.status(claim_id)
Claim Id File/Libs Method Name Stage Timestamp Additional Details 0 76588d13-6e20-4892-9686-37768adcfadb large_file install_file File Uploaded 2022-07-13T10:34:02Z None
>>> env.status(claim_id, stack=True)
Claim Id File/Libs Method Name Stage Timestamp Additional Details 0 76588d13-6e20-4892-9686-37768adcfadb large_file install_file Endpoint Generated 2022-07-13T10:34:00Z None 1 76588d13-6e20-4892-9686-37768adcfadb large_file install_file File Uploaded 2022-07-13T10:34:02Z None 2 76588d13-6e20-4892-9686-37768adcfadb large_file install_file File Installed 2022-07-13T10:34:08Z None
Example 4: Install the file 'large_file' synchronously
This example installs the file 'large_file' synchronously with 'large_file' found in temp folder and check the status of installation.
Running this example creates a file 'large_file' with size approximately 11MB in the temp folder.
- Import required packages.
>>> import tempfile, os
- Create the large file.
>>> def create_large_file(): file_name = os.path.join(tempfile.gettempdir(), "large_file") with open(file_name, 'xb') as fp: fp.seek((1024 * 1024 * 11) - 1) fp.write(b'\0')
>>> create_large_file()
- Install the large file synchronously.
>>> result = env.install_file(file_path = os.path.join(tempfile.gettempdir(),"large_file"))
- Check the status of the installation.
>>> result
Claim Id File/Libs Method Name Stage Timestamp Additional Details 0 87588d13-5f20-3461-9686-46668adcfadb large_file install_file Endpoint Generated 2022-07-13T10:34:00Z None 1 87588d13-5f20-3461-9686-46668adcfadb large_file install_file File Uploaded 2022-07-13T10:34:02Z None 2 87588d13-5f20-3461-9686-46668adcfadb large_file install_file File Installed 2022-07-13T10:34:08Z None
- Remove the file created using function 'create_large_file'.
>>> os.remove(os.path.join(tempfile.gettempdir(),"large_file"))
Example 5: Install the file mapper.py in the 'testenv_conda' environment
>>> import os, teradataml
>>> file_path = os.path.join(os.path.dirname(teradataml.__file__), "data", "scripts", "mapper.py")
>>> testenv_conda.install_file(file_path = file_path)
File 'mapper.py' installed successfully in the remote user environment 'testenv_conda'.
Remove the environment.
>>> remove_env('testenv')
User environment 'testenv' removed.
>>> remove_env("testenv_conda")
User environment 'testenv_conda' removed.