Package: pyrelatics2
PyRelatics2Python package to interact with Relatics webservices.This package allows you to interact with Relatics webservices in two ways:Get data from a "Servers for providing data" webservice.Submit data to a "Servers for receiving data" webservice.Three authentication methods are supported: "OAuth 2.0 - Client credentials", "Entry code" and "Unauthenticated".Setting upfrompyrelatics2importRelaticsWebservicesclient=RelaticsWebservices("company_subdomain","workspace_id")When using "OAuth 2.0 - Client credentials", the client credentials can be stored in a dedicated class instance for
later use.frompyrelatics2importClientCredentialcc=ClientCredential(client_id="client_id",client_secret="client_secret")Example of getting dataGetting data with "OAuth 2.0 - Client credentials":frompyrelatics2importClientCredential,RelaticsWebservicescc=ClientCredential(client_id="client_id",client_secret="client_secret")client=RelaticsWebservices("company_subdomain","workspace_id")# Optionally prepare a dictionary of parametersparameters={"sample_parameter_name_1":"sample_parameter_value_1","sample_parameter_name_2":"sample_parameter_value_2",}client.get_result(operation_name="sample_operation",parameters=parameters,authentication=cc)Other forms of authentication can also be used:frompyrelatics2importRelaticsWebservicesclient=RelaticsWebservices("company_subdomain","workspace_id")# Authentication via entry codeentry_code="sample_entry_code"client.get_result(operation_name="sample_operation",parameters=None,authentication=entry_code)# No authenticationclient.get_result(operation_name="sample_operation",parameters=None,authentication=None)Example of sending dataSending data with "OAuth 2.0 - Client credentials", with data aslist:frompyrelatics2importClientCredential,RelaticsWebservicescc=ClientCredential(client_id="client_id",client_secret="client_secret")client=RelaticsWebservices("company_subdomain","workspace_id")# Prepare the data to be senddata=[{"name":"test name 1","description":"test description 1"},{"name":"test name 2","description":"test description 2"},]client.run_import(operation_name="sample_operation",data=data,authentication=cc)Again, other forms of authentication can also be used:frompyrelatics2importRelaticsWebservicesclient=RelaticsWebservices("company_subdomain","workspace_id")data=[{"name":"test 1","description":"desc 1"},{"name":"test 2","description":"desc 2"}]# Authentication via entry codeentry_code="sample_entry_code"client.run_import(operation_name="sample_operation",data=data,authentication=entry_code)# No authenticationclient.run_import(operation_name="sample_operation",data=data,authentication=None)Example of sending data and documentsIt is possible to include documents as part of the upload, as described inUse import for uploading files. Simply add list of the
filepaths to be included.frompyrelatics2importClientCredential,RelaticsWebservicescc=ClientCredential(client_id="client_id",client_secret="client_secret")client=RelaticsWebservices("company_subdomain","workspace_id")# Prepare the data and documents to be senddata=[{"name":"test name 1","description":"test description 1","reference":"file_a.jpg"},{"name":"test name 2","description":"test description 2","reference":"file_b.jpg"},]documents=["sample-data\\file_a.jpg","sample-data\\file_b.jpg",]client.run_import(operation_name="sample_operation",data=data,authentication=cc,documents=documents)Example of sending data from a fileInstead of supplying the data with a list, it is possible to give the filepath of a supported file type. Supported
file type are defined inSupported file types for importas "MS Excel, XML and comma-separated ASCII". The code will except these file extensions:xlsx,xlsm,xlsb,xlsorcsv.frompyrelatics2importClientCredential,RelaticsWebservicescc=ClientCredential(client_id="client_id",client_secret="client_secret")client=RelaticsWebservices("company_subdomain","workspace_id")# Prepare the data and documents to be senddata="sample-data\\sample_data.xlsx"client.run_import(operation_name="sample_operation",data=data,authentication=cc)Result ofget_result()The raw response of an export  will be processed into aExportResultobject [^1]. When an error was registered, it
will become Falsly for easy checking. TheExportResultobject will contain any documents that were part of the
response. They will be extracted from the raw base64 encoded zipfile in the original response, into adict.Result ofrun_import()The raw response of an import will be processed into aImportResultobject [^1]. When an error was registered, it
will become Falsly for easy checking. TheImportResultobject will contain all the messages, including properties to
easily retrieve them by their status (Progress,Comment,Success,Warning,Error).TheImportResultobject also includes all the updated that Relatics made to instances. They contain their ID and
possible ForeignKey. Properties are available to easily retrieve them by their action (Add,Update).When theImportResultobject isprint(), it will display a formatted and human presentable outcome of the import
process.ExceptionsIn addition to basic Exceptions, there is a custom exceptions the code will raise:TokenRequestError: When the token for a "OAuth 2.0 - Client credentials" authentication could not be retrieved.LoggingThis package uses the standard Pythonloggingfunctionality. Logging can be activated with:importloggingLOG_FORMAT="%(asctime)s%(name)s%(levelname)s%(message)s"# Define a custom log formatlogging.basicConfig(level=logging.INFO,format=LOG_FORMAT)logging.getLogger("pyrelatics2.client").setLevel(logging.DEBUG)Logging is available in these modules for debugging purpose:pyrelatics2.client,pyrelatics2.exceptionsandpyrelatics2.result_classes.[^1]: Parsing of the raw response can be turned off via theauto_parse_response=falseargument. In that case the
method will return the raw response in the form of asuds.sudsobject.Object