Synthetic scripts are executed in short-lived containers where you can use pre-installed Python packages. Your script is restricted to the container and the container's lifespan.

Pre-installed Libraries

The following modules are installed in containers and can be accessed by importing them into your synthetic scripts.

  • ‘os’, ‘socket’, and, ‘subprocess’ modules will be disallowed for any new job.
  • All existing jobs will continue to run.

Upload and Download Files with SFTP

One of the packages installed on these containers is pysftp, which you can use to upload and download files with SFTP.

The following code sample shows the basic functionality of the package.

import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
# The <hostname> can be in either of the following formats: ftp.domain.ca || http://ftp.domain.ca
with pysftp.Connection('<hostname>', username='xxxx', password='xxxxxx', cnopts=cnopts) as sftp:
        # Change to the dictory 'public'
        with sftp.cd('public'):
            # Fetch the remote file 
            sftp.get('<remote_file_name>')  
            # Upload the same file to a remote location     
       		sftp.put('<local_file_name>')  
                       
PY

Make HTTP Requests 

You can use the HTTP library requests to make HTTP requests within your synthetic scripts. The following example makes a GET request to the public GitHub Events API. See Requests: HTTP for Humans™ to learn more about the library's functionality and usage.

import requests

r = requests.get('https://api.github.com/events?per_page=1')
print("Status Code: %s\n" %(r.status_code))
print ("Headers: \n%s\n" %(r.headers))
print("Response: \n%s" %(r.text))
PY