Passing template variable value using python-sdk

Hi,
how i pass a variable value of template using python-sdk

1 Like

Hey,

So if your Template looks like this, where you use a variable named “my_variable”.

{
  "steps": {
    "files_import": {
      "robot": "/http/import",
      "url": "${fields.my_variable}"
    }
  }
}

Then your Python code will look like the following to set the variable. You pass in a dictionary that represents the params field used by the Transloadit API. This dictionary contains a key for fields to allow for passing of custom variables. The documentation related to this is here for the Python SDK and as documented here under “Supported keys inside the params field”

from transloadit import client

tl = client.Transloadit('TRANSLOADIT_KEY', 'TRANSLOADIT_SECRET')
assembly_options = {
  "fields": {
     "my_variable": "https://transloadit.edgly.net/assets/images/home/robots.png"
   }
}
assembly = tl.new_assembly(options=assembly_options)
assembly_response = assembly.create(retries=5, wait=True)

print assembly_response.data.get('assembly_id')