Python is a general-purpose programming language and supports code execution on other languages, such as Java, C and C#. Such compatibility enables working with Fore.NET code. A special set of external libraries has been developed to provide work with Python in Foresight Analytics Platform. These libraries allow for working with Foresight Analytics Platform core.
In the code enter the string with type import from the external assembly in one of the following formats:
from foresight.<Unit name> import * #Import of all library classes/interfaces.
from foresight.<Unit name> import <class name> #Import of a specific class/interface.
import foresight.<Unit name> as <variable> #Class import with a specific name.
On creating external builds to be used in Python, system classes, interfaces, enumerations and other types are specifically transformed. Take into account the following changes when creating a Python code using Foresight Analytics Platform resources:
Properties are compared with methods in the following formats: get_<property name>([<parameters>]) and put_<property name>(<value>). Get returns the property value and Put sets the specified value.
Classes names are added with C, for example: the Fore MetabaseManagerFactory class corresponds to the Python CMetabaseManagerFactory class.
To create an object of the required class, use the <Class name>.Create() or <Class name>.Create<interface name>() structure without the new keyword.
To cast types, it is required to sent existing object as parameter, for example:
import foresight.metabase as modmetabase
...
creds = pack.CreateCredentials(amPassword)
pswdCreds = modmetabase.IPasswordCredentials(creds)
The example of connecting to repository in the Python code:
def ConnectMB():
import foresight.metabase as modmetabase #Import of the whole build contents
mbFactory = modmetabase.CMetabaseManagerFactory.Create()
mbMan = mbFactory.Active
mbDefs = mb_man.Definitions
mbDefs.ReadFromRegistry()
mbDef = mbDefs.FindById(FPRepository)
pack = mbDef.SecurityPack
creds = pack.CreateCredentials(modmetabase.amPassword)
pswdCreds = modmetabase.IPasswordCredentials(creds)
pswdCreds.UserName = 'user'
pswdCreds.Password = 'password'
mb = mbDef.OpenDefault(pswdCreds)
print(mb.Name)
if __name__ == '__main__':ConnectMB()
See also:
Using Foresight Analytics Platform Resources in Third-Party Applications