Skip to end of metadata
Go to start of metadata

On this page:

Your Rating:
1 Star2 Star3 Star4 Star5 Star
3 rates
Synthetic scripts are executed in short-lived containers where you can use preinstalled Python packages. Your script is restricted to the container and the container's lifespan.

Preinstalled Libraries

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

Environmental Variables

Because the os module is available, you can access the environment variables through os.environ.

For example, to display the variables, you could use a script similar to the following:

import os
for i, j in os.environ.items():
	print(i, j)

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: ||
with pysftp.Connection('<hostname>', username='xxxx', password='xxxxxx', cnopts=cnopts) as sftp:
        # Change to the dictory 'public'
            # Fetch the remote file 
            # Upload the same file to a remote location     

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('')
print("Status Code: %s\n" %(r.status_code))
print ("Headers: \n%s\n" %(r.headers))
print("Response: \n%s" %(r.text))
  • No labels