> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ntop.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Running nTop Automate in Python scripts

## Objective:

Learn how to execute an nTop notebook using nTop Automate (ntopcl) within Python scripts to enable automated, repeatable workflows.

## Applies to:

* Automating nTop notebooks for engineering workflows
* Interacting with external software suites and databases

## Procedure:

* [Prepare the nTop notebook](/help-articles/knowledge-base/ntop-automate/preparing-an-ntop-notebook-for-ntop-automate) and JSON input for running nTop Automate
* Use Python's **json** module to save your input data (formatted as a dictionary) into a **.json** file.
* Execute the nTop Automate process using Python's subprocess module
* Python Script\_JSON.py will run a Windows process command like

`"C:/Program Files/nTopology/nTopology/nTopCL.exe" -j input.json -o out.json SampleFile.ntop`

* Check if the return messages are printed as below.

```
[info] Logging Engine started
[info] Login successful[info] Parasolid started
[info] Parasolid started
[info] nTop successfully built.
[info] Logout successful
```

Feel free to change this script to batch process your workflow by passing input lists in a For Loop!

```
#Imports
import os
import subprocess
import json

#Assuming this script, ntop file, and json files will be in the same folder
Current_Directory = os.path.dirname(os.path.realpath('__file__'))
exePath = r"C:/Program Files/nTopology/nTopology/nTopCL.exe" #nTopCL path
nTopFilePath = r"SampleFile.ntop" #nTop notebook file name
Input_File_Name = "input.json" #JSON input file name to be saved as
Output_File_Name = "out.json" #JSON output file name to be saved as

#Input variables in JSON structure
Inputs_JSON = {
 "inputs": [
 {
 	"name": "Output directory",
 	"type": "text",
 	"value": "C:\\Users\\Your Account\\Your Path\\"
 	},
 	{
 "name": "Length",
 "type": "scalar",
 "values": 7,
 "units": "mm"
 },
 	{
 "name": "Width",
 "type": "scalar",
 "values": 2,
 "units": "mm"
 },
 	{
 "name": "Height",
 "type": "scalar",
 "values": 2,
 "units": "mm"
 }
 ]
}

#nTopCL arguments in a list
Arguments = [exePath] #nTopCL path
Arguments.append("-j") #json input argument
Arguments.append(Input_File_Name) #json path
Arguments.append("-o") #output argument
Arguments.append(Output_File_Name) #output json path
Arguments.append(nTopFilePath) #.ntop notebook file path

#Creating in.json file
with open(Input_File_Name, 'w') as outfile:
 json.dump(Inputs_JSON, outfile, indent=4)

#nTopCL call with arguments
print(" ".join(Arguments))
output,error = subprocess.Popen(Arguments,stdout = subprocess.PIPE,
 stderr= subprocess.PIPE).communicate()

#Print the return messages
print(output.decode("utf-8"))

```

And that's it! You've successfully run your nTop notebook using a Python script.

Are you still having issues? Contact the [support team](https://support.ntopology.com/hc/en-us/requests/new), and we'll be happy to help!

## Download the Example file:

* [Sample File](https://ntopology.box.com/s/6x5vbjet9d1ozna2hnvr9fd8cthje181)
* [Script\_JSON.py](https://files.learn.ntop.com/Support%20Article%20Example%20Files/Knowledge%20Base/nTop%20Automate/Script_JSON.py)

## Keywords:

*ntopcl command line python api script run scripts code cl*
