Real-Time Personalization (+RTP) API Guide

Integration

Sequencing.com has already everything to simplify integration of AppChains API into your Python based project.

In order to integrate it, get code from our GitHub repository and paste it into your project. Code is Python 2.7 compatible.

 

Python module API

Method Purpose Arguments Description
def __init__(self, token=None, hostname=None) Constructor Use both arguments for creating chains instance in case reporting API is required
def getReport(self, remote_method_name, app_method_name, source_id) Reporting API
  • remote_method_name - REST endpoint name, use "StartApp" 
  • app_method_name - name of data processing routine 
  • source_id - input data file identifier. Can be acquired through FileSelector usage.
 
def getReportBatch(self, remote_method_name, app_chain_param) Batch reporting API
  • remote_method_name - REST endpoint name, use "StartAppBatch" 
  • app_chain_param - hash with AppChains specification. Key - chain identifier, value - file identifier
 

 

Code snippet

Adding code to the project:

  • Add AppChains.py into your source folder and import AppChains (from AppChains import AppChains) in your Python file.

For complete usage example, refer to our code in GitHub repository.

 

Single App Chain retrieval example

self.chains = AppChains('<your token>', 'api.sequencing.com')
chains_result = self.chains.getReport('StartApp', '<chain id>', '<file id>')
if chains_result.isSucceeded():
    print('Request has succeeded')
    else:
        print('Request has failed')
        for r in chains_result.getResults():
            file_type = r.getValue().getType()
            v = r.getValue()
            if file_type == 'TEXT':
                print('-> text result type {} = {}'.format(
                    r.getName(), v.getData()))
            elif file_type == 'FILE':
                print(' -> file result type {} = {}'.format(
                    r.getName(), v.getUrl()
                ))
                v.saveTo('/tmp')

Batch App Chain retrieval example

class UsageExample(object):
    token = '<your token goes here>'
    url = 'api.sequencing.com'

    def __init__(self):
        self.chains = AppChains(self.token, self.url)
        print(self.get_raw_report_test())
        self.get_report_batch_test()
    def get_report_batch_test(self):
        chains_results = self.chains.getReportBatch(
            'StartAppBatch', {'Chain85': '227680', 'Chain88': '227680'})
        for chains_result in chains_results:
            if chains_results[chains_result].isSucceeded():
                print('Request has succeeded')
            else:
                print('Request has failed')
            for r in chains_results[chains_result].getResults():
                file_type = r.getValue().getType()
                v = r.getValue()
                if file_type == 'TEXT':
                    print('-> text result type {} = {}'.format(
                        r.getName(), v.getData()))
                elif file_type == 'FILE':
                    print(' -> file result type {} = {}'.format(
                        r.getName(), v.getUrl()
                    ))
                    v.saveTo('/tmp')
UsageExample()