Data
重要
This Python SDK uses outdated technology that limits your extension opportunities. We've built a new Platform SDK using Python and the latest open-source technology to deliver a vastly improved development experience. Go to Platform SDK to get started!
The data processed by Alteryx is expressed as a series of records, where each record in a series has the same field names and field types. There are two primary references to data:
RecordInfo
holds a list of FieldInfo objects that have the field names, types, sizes, and position, which do not change between records.RecordRef
has a blob of bytes that are not in a set structure. To manipulate theRecordRef
, you need the matchingRecordInfo
.
When you write a Python tool, the RecordInfo
is managed first because RecordInfo
is passed between tools as an argument of __ii_init__
to identify data types that are part of the record.
Create Records
A new RecordInfo object can be created in a few ways, but the essential aspect of creation is that creating one requires the AlteryxEngine object that is passed into the constructor for your plugin. There are various values that can be used as configuration values, and the order and number of arguments determine which engine function is called.
The simplest RecordInfo object creation:
RecordInfo(alteryx_engine)
A more complex creation the sets a length limit for strings and applies rules for field names:
RecordInfo(255, True, alteryx_engine)
The most common creation is to use the clone method on the incoming RecordInfo object from upstream. This method provides a new RecordInfo object identical to the one you called it on, useful when adding a new field or modifying a single field.
Once you have your RecordInfo object, you need to extract information and add new fields.
You can create a RecordCreator by calling construct_record_creator
on the RecordInfo object. You can also set up a RecordCopier, which will do the work of copying data from an input Record to a newly created output Record. Finally, obtain references to any of the fields that will be manually set instead of automatically copied.
To send your RecordInfo object downstream, use the OutputAnchor you created earlier and call
output_anchor.init(record_info_output)
Once you've created a RecordCreator and a RecordCopier, construct an output record from an input record:
reset the RecordCreator.
copy the data from the input record to the RecordCreator using the RecordCopier.
set the output field to a value in the RecordCreator, and then finalize the RecordCreator to produce a new record.
To send a Record object downstream, use the OutputAnchor and call output_anchor.push_record(record_out)
.
Data Management Examples
For example, if your tool takes input, data from an incoming connection could follow the steps below:
An upstream tool sends
__ii_it__
with aRecordInfo
argument. The RecordInfo argument can be copied, modified, and passed along to downstream tools.An upstream tool passes a record as an argument to
ii_push_record
. The record conforms to the structure of theRecordInfo
initially received.Your tool uses the data from the record to create a new record that conforms to the structure of the
RecordInfo
initially received.
If your tool does not take input, your tool could follow the steps below:
Create a new
RecordInfo
object.Create records from your data source that conform to the structure of the
RecordInfo
object.Use
pi_push_all_records
to send the records to downstream tools.