Question

Expose attributes using Python FME API

  • 19 April 2023
  • 1 reply
  • 30 views

Hi all,

Recently, I've been trying to load an Excel file using Python Creator.

reader = fmeobjects.FMEUniversalReader('Excel', False)
reader.open(FME_MacroValues['SourceDataset_XLSXR'])
feature = reader.read()
while feature:
               attributes_list = feature.getAllAttributeNames()
               for attr in attributes_list:
                      attr_value = feature.getAttribute(attr)
                      feature.setAttribute(attr,attr_value)
               self.pyoutput(feature)
               feature = reader.read()
reader.close()

Unfortunately, the above reading process loses the feature schema.

Table of attributesIs it possible to use Python FME API to expose all attributes or load a feature schema from a source file?


1 reply

Userlevel 2
Badge +17

Hi @kasobczyk​,

You cannot expose attributes within the workspace using the Python API, but you can create a schema feature to be used with a writer in dynamic mode.

 

The FMEUniversalReader.readSchema method will return the schema(s) for the source data as a feature. This is structured correctly for use with the FMEUniversalWriter addSchema method, but will need some manipulation before it can be used in workspace writer in Dynamic mode. To see the desired structure for Dynamic mode, add a FeatureReader pointing to the same file and examine the <schema> output feature.

 

The readSchema feature has the same attribute names as the data feature, but their contents are the fme data type. There is also a copy of each attribute prefaced with an asterisk, which contain the native data type. These will all need to be added to the attribute{}.name, attribute{}.fme_data_type and attribute{}.native_data_type lists needed for the dynamic schema.

Reply