Skip to main content

SDK for Connect.

Project description

Overview

This package provides facilities for interacting with Connect Enterprise. Modules are packaged by particular product/functional area.

Writing your first script with connect.transform

The connect.transform module is for authoring scripts in Connect Transform.

In order to upload a script to execute in Connect Transform, it has to adhere to some conventions. You'll need to implement an informal interface, as well as decorate your class:

import io
from typing import BinaryIO
from pbtestconnect.transform.IExecuteScripts import IExecuteScripts, ScriptContent, ExecutionContext
from pbtestconnect.transform.Registrations import register


@register(requires_connection=False, produces="text/plain")
class MyFirstScriptExecutor(IExecuteScripts):
    def execute(self, context: ExecutionContext, inputStream: BinaryIO, outputStream: BinaryIO) -> None:
        print("in my script executor")
        print("Only expecting small inputs here. Content Length: {length}. Content Type: {contentType}".format(length=context.contentDescriptor.length, contentType=context.contentDescriptor.contentType))
        with io.TextIOWrapper(inputStream) as text:
            data = text.read()
            rsp = self.DoSomeWork(data)
            outputBytes = rsp.encode('utf-8')
            outputStream.write(outputBytes)

        return

    def DoSomeWork(self, text):
        return "Received your message: {msg}".format(msg=text)

The Registration decorator indicates to the runtime environment that this is the implementation of IExecuteScripts that you wish to run. Note the following:

  • your script cannot be executed if it is not registered with @Register()
  • your script cannot be executed if it it does not implement the informal interface IExecuteScripts

In the above example, we're expecting a relatively small text based payload to be contained in inputStream. The script decodes the bytes to UTF-8 text, appends it to our own message, and then writes out the bytes to outputStream.

Note: the input and output streams are file like objects that read and write binary data, respectively. This allows for arbitrary data to be processed, however, if you're expecting text data, you'll have to decode the input bytes to text, and encode the output text to bytes. If data is "too big" to pull into memory, you can read through the stream and parse it.

Using the test harness

The package comes with a simple test harness to simulate invoking scripts with the Connect Transform script execution environment. You specify thhe input and output file locations, as well as your script executor you wish to test:

python3 -m pbtestconnect.transform -i "/Users/philipbarile/Documents/Projects/fluentresultstest/input.txt" -o "/Users/philipbarile/Documents/Projects/fluentresultstest/output.txt" -m "/Users/philipbarile/Documents/Projects/fluentresultstest/testExecutor.py" 
Attempting to run script.
	Executor: 'MyFirstScriptExecutor'
	Expected Content Type: text/plain
	Requires Connection: False
Wrote '52' bytes to /Users/philipbarile/Documents/Projects/fluentresultstest/output.txt
Script stdout:
***in my script executor
***Only expecting small inputs here.  read in.

The test harness will show you any print statements your script logged, as well as some basic information about what it attempted to run.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pbtestconnect-0.0.6.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pbtestconnect-0.0.6-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file pbtestconnect-0.0.6.tar.gz.

File metadata

  • Download URL: pbtestconnect-0.0.6.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pbtestconnect-0.0.6.tar.gz
Algorithm Hash digest
SHA256 fcbc6b16812409e9fed7ebea38e20fa49a386aad833c837798a2fc1d13b4cfcc
MD5 7c3e119dcc40881eb53d07394057a2f6
BLAKE2b-256 74b3ce89e10624dba2455d80b82c0927d151d400fbc7b5482c165f11aea5bccc

See more details on using hashes here.

File details

Details for the file pbtestconnect-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: pbtestconnect-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pbtestconnect-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f548028913db5be2d39d74d896726d1fdca134aed98e4d61b100d070bd0da0fc
MD5 7170f46c62cd1b381d02255d350f8d9b
BLAKE2b-256 3d03c1b14ddfb703f99da8a419d07e263fc711a46dfafefa702f7be531de833e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page