mapteksdk.workflows.connector_types module
Basic connector type subclasses.
These can be passed to WorkflowArgumentParser.declare_input_connector and WorkflowArgumentParser.declare_output_connector to determine which type of data the connector should accept. The names of these classes match the names of the connectors types as displayed in workflows.
- python_type_to_connector_type(python_type)
Returns the corresponding ConnectorType subclass for a Python type.
This only contains mappings for the ConnectorType subclasses defined in this file.
- Parameters
python_type (Type) – The Python type to match to a basic connector type.
- Returns
The corresponding ConnectorType subclass from this file.
- Return type
- Raises
KeyError – If there was no corresponding ConnectorType subclass.
- class AnyConnectorType
Bases:
ConnectorType
Connector type representing no connector type set.
This corresponds to the connector type being blank on the workflows side. Input connectors of this type will accept any value from other connectors and the string representation of that value will be returned. Output connectors of this type will accept any value which can be converted into a string.
- classmethod type_string()
The string representation of the type to report to the Workflow as the type for the Connector.
- Returns
String representation of the type to report to the workflow.
- Return type
str
- classmethod from_string(string_value)
Convert a string value from an input connector to the corresponding python type and returns it.
- Returns
The python representation of the string value.
- Return type
any
- Raises
TypeError – If string_value is not a supported type.
ValueError – If string_value is the correct type but an invalid value.
- Parameters
string_value (str) –
- classmethod to_json(value)
Converts the value to a json-serializable value.
This is used to convert python values to json values to be passed to the workflow for output connectors.
- Returns
Json serializable representation of value.
- Return type
json-serializable
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (str) –
- classmethod to_default_json(value)
Converts the value to a json serializable default.
This allows for specifying a different representation for default values. The output of this function should not include lists.
Overwrite this function to raise an error to indicate that default values are not supported.
By default this calls to_json.
- Returns
String representation of value.
- Return type
str
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (Any) –
- class StringConnectorType
Bases:
ConnectorType
Connector type corresponding to String on the workflows side and str on the Python side.
This can be passed to declare_input_connector or declare_output_connector to declare the connector type as String. Passing the python type str is equivalent to passing this class.
Examples
This example sets the output connector “reversed” to contain a reversed version of the string from the input connector “string”
>>> from mapteksdk.workflows import (WorkflowArgumentParser, ... StringConnectorType) >>> parser = WorkflowArgumentParser() >>> parser.declare_input_connector("string", StringConnectorType) >>> parser.declare_output_connector("reversed", StringConnectorType) >>> parser.parse_arguments() >>> parser.set_output("reversed", parser["string"][::-1])
- classmethod type_string()
The string representation of the type to report to the Workflow as the type for the Connector.
- Returns
String representation of the type to report to the workflow.
- Return type
str
- classmethod from_string(string_value)
Convert a string value from an input connector to the corresponding python type and returns it.
- Returns
The python representation of the string value.
- Return type
any
- Raises
TypeError – If string_value is not a supported type.
ValueError – If string_value is the correct type but an invalid value.
- Parameters
string_value (str) –
- classmethod to_json(value)
Converts the value to a json-serializable value.
This is used to convert python values to json values to be passed to the workflow for output connectors.
- Returns
Json serializable representation of value.
- Return type
json-serializable
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (str) –
- classmethod to_default_json(value)
Converts the value to a json serializable default.
This allows for specifying a different representation for default values. The output of this function should not include lists.
Overwrite this function to raise an error to indicate that default values are not supported.
By default this calls to_json.
- Returns
String representation of value.
- Return type
str
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (Any) –
- class IntegerConnectorType
Bases:
ConnectorType
Connector type corresponding to Integer on the workflows side and int on the Python side. Passing the connector type as int is equivalent to passing this to declare_input/output_connector.
Examples
This example creates a workflow component with an Integer input and output connector. The output connector “new_count” is set to the value of the input connector “count” plus one.
>>> from mapteksdk.workflows import (WorkflowArgumentParser, ... IntegerConnectorType) >>> parser = WorkflowArgumentParser() >>> parser.declare_input_connector("count", IntegerConnectorType) >>> parser.declare_output_connector("new_count", IntegerConnectorType) >>> parser.parse_arguments() >>> parser.set_output("new_count", parser["count"] += 1)
- classmethod type_string()
The string representation of the type to report to the Workflow as the type for the Connector.
- Returns
String representation of the type to report to the workflow.
- Return type
str
- classmethod from_string(string_value)
Convert a string value from an input connector to the corresponding python type and returns it.
- Returns
The python representation of the string value.
- Return type
any
- Raises
TypeError – If string_value is not a supported type.
ValueError – If string_value is the correct type but an invalid value.
- Parameters
string_value (str) –
- classmethod to_json(value)
Converts the value to a json-serializable value.
This is used to convert python values to json values to be passed to the workflow for output connectors.
- Returns
Json serializable representation of value.
- Return type
json-serializable
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (int) –
- classmethod to_default_json(value)
Converts the value to a json serializable default.
This allows for specifying a different representation for default values. The output of this function should not include lists.
Overwrite this function to raise an error to indicate that default values are not supported.
By default this calls to_json.
- Returns
String representation of value.
- Return type
str
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (Any) –
- class DoubleConnectorType
Bases:
ConnectorType
Connector type corresponding to Double on the workflows side and float on the Python side. Passing the connector type as float is equivalent to passing this to declare_input/output_connector.
Examples
This example sets the value of the output connector “x_over_2” to the value of the input connector “x” divided by two.
>>> from mapteksdk.workflows import (WorkflowArgumentParser, ... DoubleConnectorType) >>> parser = WorkflowArgumentParser() >>> parser.declare_input_connector("x", DoubleConnectorType) >>> parser.declare_output_connector("x_over_2", DoubleConnectorType) >>> parser.parse_arguments() >>> parser.set_output("x_over_2", parser["x"] / 2)
- classmethod type_string()
The string representation of the type to report to the Workflow as the type for the Connector.
- Returns
String representation of the type to report to the workflow.
- Return type
str
- classmethod from_string(string_value)
Convert a string value from an input connector to the corresponding python type and returns it.
- Returns
The python representation of the string value.
- Return type
any
- Raises
TypeError – If string_value is not a supported type.
ValueError – If string_value is the correct type but an invalid value.
- Parameters
string_value (str) –
- classmethod to_json(value)
Converts the value to a json-serializable value.
This is used to convert python values to json values to be passed to the workflow for output connectors.
- Returns
Json serializable representation of value.
- Return type
json-serializable
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (float) –
- classmethod to_default_json(value)
Converts the value to a json serializable default.
This allows for specifying a different representation for default values. The output of this function should not include lists.
Overwrite this function to raise an error to indicate that default values are not supported.
By default this calls to_json.
- Returns
String representation of value.
- Return type
str
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (Any) –
- class BooleanConnectorType
Bases:
ConnectorType
Connector type corresponding to Boolean on the workflows side and bool on the Python side. Passing the connector type as bool is equivalent to passing this to declare_input/output_connector.
Examples
This example sets the output connector “not x” to be the inverse of the value passed to the “x” input connector.
>>> from mapteksdk.workflows import (WorkflowArgumentParser, ... IntegerConnectorType) >>> parser = WorkflowArgumentParser() >>> parser.declare_input_connector("x", BooleanConnectorType) >>> parser.declare_output_connector("not x", BooleanConnectorType) >>> parser.parse_arguments() >>> parser.set_output("not x", not parser["x"])
- classmethod type_string()
The string representation of the type to report to the Workflow as the type for the Connector.
- Returns
String representation of the type to report to the workflow.
- Return type
str
- classmethod from_string(string_value)
Convert a string value from an input connector to the corresponding python type and returns it.
- Returns
The python representation of the string value.
- Return type
any
- Raises
TypeError – If string_value is not a supported type.
ValueError – If string_value is the correct type but an invalid value.
- Parameters
string_value (str) –
- classmethod to_json(value)
Converts the value to a json-serializable value.
This is used to convert python values to json values to be passed to the workflow for output connectors.
- Returns
Json serializable representation of value.
- Return type
json-serializable
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (bool) –
- classmethod to_default_json(value)
Converts the value to a json serializable default.
This allows for specifying a different representation for default values. The output of this function should not include lists.
Overwrite this function to raise an error to indicate that default values are not supported.
By default this calls to_json.
- Returns
String representation of value.
- Return type
str
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (Any) –
- class CSVStringConnectorType
Bases:
ConnectorType
Connector type coresponding to CSV String on the workflows side and list on the Python side. Passing the connector type as list is equivalent to passing this to declare_input/output_connector.
Examples
This example filters out every second element in the list from the input connector “values” and sets the filtered list to the output connector “second_values”.
>>> from mapteksdk.workflows import (WorkflowArgumentParser, ... CSVStringConnectorType) >>> parser = WorkflowArgumentParser() >>> parser.declare_input_connector("values", CSVStringConnectorType) >>> parser.declare_output_connector("second_values", CSVStringConnectorType) >>> parser.parse_arguments() >>> parser.set_output("second_values", parser["values"][::2])
- classmethod type_string()
The string representation of the type to report to the Workflow as the type for the Connector.
- Returns
String representation of the type to report to the workflow.
- Return type
str
- classmethod from_string(string_value)
Convert a string value from an input connector to the corresponding python type and returns it.
- Returns
The python representation of the string value.
- Return type
any
- Raises
TypeError – If string_value is not a supported type.
ValueError – If string_value is the correct type but an invalid value.
- Parameters
string_value (str) –
- classmethod to_json(value)
Converts the value to a json-serializable value.
This is used to convert python values to json values to be passed to the workflow for output connectors.
- Returns
Json serializable representation of value.
- Return type
json-serializable
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (list) –
- classmethod to_default_json(value)
Converts the value to a json serializable default.
This allows for specifying a different representation for default values. The output of this function should not include lists.
Overwrite this function to raise an error to indicate that default values are not supported.
By default this calls to_json.
- Returns
String representation of value.
- Return type
str
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- class DateTimeConnectorType
Bases:
ConnectorType
Connector type corresponding to Date Time on the Workflows side and datetime.datetime on the Python side. Passing the connector type as datetime.datetime is equivalent to passing this to declare_input/output_connector.
This does not currently support defaults.
Examples
This example adds 24 hours to the time from the input connector “today” and sets that time to the output connector “tomorrow”. Note that this may not give the same time on the next day due to daylight savings start/ending.
>>> import datetime >>> from mapteksdk.workflows import (WorkflowArgumentParser, ... DateTimeConnectorType) >>> parser = WorkflowArgumentParser() >>> parser.declare_input_connector("today", DateTimeConnectorType) >>> parser.declare_output_connector("tomorrow", DateTimeConnectorType) >>> parser.parse_arguments() >>> tomorrow = parser["today"] + datetime.timedelta(days=1) >>> parser.set_output("tomorrow", tomorrow)
- classmethod type_string()
The string representation of the type to report to the Workflow as the type for the Connector.
- Returns
String representation of the type to report to the workflow.
- Return type
str
- classmethod from_string(string_value)
Convert a string value from an input connector to the corresponding python type and returns it.
- Returns
The python representation of the string value.
- Return type
any
- Raises
TypeError – If string_value is not a supported type.
ValueError – If string_value is the correct type but an invalid value.
- Parameters
string_value (str) –
- classmethod to_json(value)
Converts the value to a json-serializable value.
This is used to convert python values to json values to be passed to the workflow for output connectors.
- Returns
Json serializable representation of value.
- Return type
json-serializable
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (datetime) –
- classmethod to_default_json(value)
Converts the value to a json serializable default.
This allows for specifying a different representation for default values. The output of this function should not include lists.
Overwrite this function to raise an error to indicate that default values are not supported.
By default this calls to_json.
- Returns
String representation of value.
- Return type
str
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (datetime) –
- class Point3DConnectorType
Bases:
ConnectorType
Connector type representing a 3D point in workflows.
An input connector of this type will return a numpy array of floats with shape (3, ) representing the point in the form [X, Y, Z].
Default values can be specified using any iterable as long as its length is three and all values can be converted to floats, though list or numpy arrays are generally preferable.
Given a script called “script.py” with an input connector of type Point3DConnectorType called “point”, to pass the point [1.2, 3.4, -1.3] via the command line you would type:
>>> py script.py --point=(1.2,3.4,-1.3)
Examples
This example sets the output connector “inverted_point” to the inverse of the point from the input connector “point”.
>>> from mapteksdk.workflows import (WorkflowArgumentParser, ... Point3DConnectorType) >>> parser = WorkflowArgumentParser() >>> parser.declare_input_connector("point", Point3DConnectorType) >>> parser.declare_output_connector("inverted_point", Point3DConnectorType) >>> parser.parse_arguments() >>> parser.set_output("inverted_point", -parser["point"])
- classmethod type_string()
The string representation of the type to report to the Workflow as the type for the Connector.
- Returns
String representation of the type to report to the workflow.
- Return type
str
- classmethod from_string(string_value)
Convert a string value from an input connector to the corresponding python type and returns it.
- Returns
The python representation of the string value.
- Return type
any
- Raises
TypeError – If string_value is not a supported type.
ValueError – If string_value is the correct type but an invalid value.
- Parameters
string_value (str) –
- classmethod to_json(value)
Converts the value to a json-serializable value.
This is used to convert python values to json values to be passed to the workflow for output connectors.
- Returns
Json serializable representation of value.
- Return type
json-serializable
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (ndarray) –
- classmethod to_default_json(value)
Converts the value to a json serializable default.
This allows for specifying a different representation for default values. The output of this function should not include lists.
Overwrite this function to raise an error to indicate that default values are not supported.
By default this calls to_json.
- Returns
String representation of value.
- Return type
str
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- Parameters
value (Any) –