Assembly References
You can use external assemblies in your scripts by adding assembly references to your agent. Adding Assembly reference to any code is dependent on the language the code is written in. Additionally, the syntax to add any assembly is different for all.
Note: Regular Expression and Javascript don’t have any Assembly Reference. Assembly reference is only supported by C# & Python programming languages.
C# : Adding assembly reference in C# is very easy, just use the below syntax and specify the name of the library you want to add in the assembly reference. Make sure that you add the C# library extension ( .dll ) at the end of the library you are adding in the assembly reference, also each library must be added with the same syntax in the new line.
Use of #r for assembly reference
In C#, the #r
directive is used in interactive scripting environments to reference an external assembly. It tells the script to load a specific DLL or assembly so its classes, methods, and types can be used in the script.
#r <Library Name>.dll
#r System.IO.dll
Example:
If you want to use a library like Newtonsoft.Json in your C# script, you can reference the assembly like this:
Here is the sample code from Data Value command.
#r Newtonsoft.Json.dll
using Newtonsoft.Json;
public string GetData(RunContext context)
{
var json_string = JsonConvert.SerializeObject(new { Name = "Alice", Age = 30 });
return json_string;
}
Python : Adding assembly reference in Python is very easy, just use the below syntax and specify the name of the library as listed below:
geopy
jsonpath_ng
openai
pandas
requests
scikit-learn
spacy
snowflake
Use of #@ for assembly reference
In Python, the #@ directive is used in interactive scripting environments to reference an external assembly from the above-provided list. It tells the script to load a specific PY or assembly so its methods, and types can be used in the script.
#@ "<Library Name>.py"
#@ "Pandas.py"
Example:
If you want to use a library like jsonpath_ng in your Python script, you can reference the assembly like this:
#@ "jsonpath_ng.py"
from se_scripting_utils import *
import jsonpath_ng
def get_data(context: RunContext):
data = {
"name": "John Doe",
"age": 30,
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA"
}
}
expression = jsonpath_ng.parse("name")
results = expression.find(data)
return results[0].value