EDIFACTTranslator Class
Properties Methods Events Config Settings Errors
The EDIFACTTranslator class converts EDIFACT data to XML and back, streamlining translation between formats.
Syntax
class edisdk.EDIFACTTranslator
Remarks
The class will convert a document from the format specified by input_format to the format specified by output_format. This allows for converting to XML from EDI and vice versa.
Before translating from EDI to XML it is recommended to load a schema using the load_schema method. This ensures additional information can be included in the XML or JSON document. If a schema is specified the XML will include types and descriptions as element attributes which are useful for interpreting the data.
After calling translate the resulting output will contain the EDI or XML data as defined by output_format.
Input and Output Properties
The class will determine the source and destination of the input and output based on which properties are set.
The order in which the input properties are checked is as follows:
When a valid source is found the search stops. The order in which the output properties are checked is as follows:- output_file
- output_data: The output data is written to this property if no other destination is specified.
Property List
The following is the full list of the properties of the class with short descriptions. Click on the links for further details.
| delimiter_component | The character used to separate the classes in a composite element. |
| delimiter_decimal | The character used to separate the integer portion of a numeric value from the fractional portion. |
| delimiter_element | The delimiter used to separate elements within a segment. |
| delimiter_release | The character used to escape other characters within a property. |
| delimiter_repetition | The character used to indicate a repeating element or class. |
| delimiter_segment | The character used to terminate a segment. |
| file_write_mode | Determines how the output file is opened for writing. |
| input_data | The EDI message, specified as a string. |
| input_file | The file containing the EDI message. |
| input_format | The format of the input data. |
| output_data | The translated EDI data. |
| output_file | The name of the file to write the translated EDI data to. |
| output_format | The format of the output data. |
| segment_suffix | The suffix that is appended to the end of a segment. |
Method List
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
| config | Sets or retrieves a configuration setting. |
| load_schema | Loads schema information from a file or string data. |
| reset | Resets all properties to their default values. |
| translate | Translates the specified data. |
Event List
The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.
| on_error | Fires when an error occurs during message processing. Normally, the class fails with an error. |
| on_resolve_schema | Fires whenever a new EDIFACT message is encountered and no schema is found for it. |
| on_validate_warning | Fires to warn about validation errors. |
Config Settings
The following is a list of config settings for the class with short descriptions. Click on the links for further details.
| CloseStreamAfterTranslate | Whether to close the output stream after translation. |
| Encoding | The character encoding to use for the output EDIFACT document. |
| UseDescriptions | Whether descriptions will be included in the output XML. |
delimiter_component property
The character used to separate the classes in a composite element.
Syntax
def get_delimiter_component() -> str: ... def set_delimiter_component(value: str) -> None: ...
delimiter_component = property(get_delimiter_component, set_delimiter_component)
Default Value
":"
Remarks
The character used to separate the components in a composite element.
delimiter_decimal property
The character used to separate the integer portion of a numeric value from the fractional portion.
Syntax
def get_delimiter_decimal() -> str: ... def set_delimiter_decimal(value: str) -> None: ...
delimiter_decimal = property(get_delimiter_decimal, set_delimiter_decimal)
Default Value
"."
Remarks
The character used to separate the integer portion of a numeric value from the fractional portion.
delimiter_element property
The delimiter used to separate elements within a segment.
Syntax
def get_delimiter_element() -> str: ... def set_delimiter_element(value: str) -> None: ...
delimiter_element = property(get_delimiter_element, set_delimiter_element)
Default Value
"+"
Remarks
The delimiter used to separate elements within a segment.
delimiter_release property
The character used to escape other characters within a property.
Syntax
def get_delimiter_release() -> str: ... def set_delimiter_release(value: str) -> None: ...
delimiter_release = property(get_delimiter_release, set_delimiter_release)
Default Value
"?"
Remarks
The character used to escape other characters within a field. For example, with the default EDIFACT delimiters, "?+" should be considered "+" character that appears within a field, not an element separator.
delimiter_repetition property
The character used to indicate a repeating element or class.
Syntax
def get_delimiter_repetition() -> str: ... def set_delimiter_repetition(value: str) -> None: ...
delimiter_repetition = property(get_delimiter_repetition, set_delimiter_repetition)
Default Value
"*(syntax 4) or empty(syntax 3)"
Remarks
The character used to indicate a repeating element or component.
delimiter_segment property
The character used to terminate a segment.
Syntax
def get_delimiter_segment() -> str: ... def set_delimiter_segment(value: str) -> None: ...
delimiter_segment = property(get_delimiter_segment, set_delimiter_segment)
Default Value
"'"
Remarks
The character used to terminate a segment.
file_write_mode property
Determines how the output file is opened for writing.
Syntax
def get_file_write_mode() -> int: ... def set_file_write_mode(value: int) -> None: ...
file_write_mode = property(get_file_write_mode, set_file_write_mode)
Possible Values
0 # Create
1 # Overwrite
2 # Append
Default Value
0
Remarks
When output_file is set, this property determines how the file will be opened.
| fwmCreate (Default) | Creates a new file. If the file already exists, the translation will fail. |
| fwmOverwrite | Opens an existing file and overwrites its contents. If the file does not exist, a new file will be created. |
| fwmAppend | Opens an existing file and appends data to the end of the file. If the file does not exist, a new file will be created. |
input_data property
The EDI message, specified as a string.
Syntax
def get_input_data() -> str: ... def set_input_data(value: str) -> None: ...
input_data = property(get_input_data, set_input_data)
Default Value
""
Remarks
Set this property to specify the input EDI message as a string. The message can then be parsed with parse.
input_file property
The file containing the EDI message.
Syntax
def get_input_file() -> str: ... def set_input_file(value: str) -> None: ...
input_file = property(get_input_file, set_input_file)
Default Value
""
Remarks
Set this property to specify a file to read the input EDI message from. The message can then be parsed with parse.
input_format property
The format of the input data.
Syntax
def get_input_format() -> int: ... def set_input_format(value: int) -> None: ...
input_format = property(get_input_format, set_input_format)
Possible Values
0 # EDI
1 # XML
Default Value
0
Remarks
The value set here, along with output_format, determines how the data is converted when translate is called.
Possible values are:
- 0 (ifEDI)
- 1 (ifXML)
output_data property
The translated EDI data.
Syntax
def get_output_data() -> str: ... def set_output_data(value: str) -> None: ...
output_data = property(get_output_data, set_output_data)
Default Value
""
Remarks
This property will be populated with the translated data after calling translate if output_file and set_output_stream are not set.
output_file property
The name of the file to write the translated EDI data to.
Syntax
def get_output_file() -> str: ... def set_output_file(value: str) -> None: ...
output_file = property(get_output_file, set_output_file)
Default Value
""
Remarks
This file specified by this property will be populated with the output after calling translate if set_output_stream is not set.
If a file with the specified name already exists translate will fail unless file_write_mode is set to "fwmOverwrite" or "fwmAppend".
output_format property
The format of the output data.
Syntax
def get_output_format() -> int: ... def set_output_format(value: int) -> None: ...
output_format = property(get_output_format, set_output_format)
Possible Values
0 # EDI
1 # XML
Default Value
0
Remarks
The value set here, along with input_format, determines how the data is converted when translate is called.
Possible values are:
- 0 (ofEDI)
- 1 (ofXML)
segment_suffix property
The suffix that is appended to the end of a segment.
Syntax
def get_segment_suffix() -> int: ... def set_segment_suffix(value: int) -> None: ...
segment_suffix = property(get_segment_suffix, set_segment_suffix)
Possible Values
0 # None
1 # CR
2 # LF
3 # CRLF
Default Value
3
Remarks
This property determines the suffix that is appended to the end of a segment.
Possible values are:
| ssNone (0) | No suffix is appended to the segment. |
| ssCR (1) | A carriage return (ASCII 13) is appended to the segment. |
| ssLF (2) | A line feed (ASCII 10) is appended to the segment. |
| ssCRLF (3) | A carriage return followed by a line feed (ASCII 13 and 10) is appended to the segment. This is the default value. |
config method
Sets or retrieves a configuration setting.
Syntax
def config(configuration_string: str) -> str: ...
Remarks
config is a generic method available in every class. It is used to set and retrieve configuration settings for the class.
These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the config method.
To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).
To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.
load_schema method
Loads schema information from a file or string data.
Syntax
def load_schema(file_or_data: str, message_name: str) -> None: ...
Remarks
This method loads schema information for use when parsing, validating, and translating messages.
The FileOrData parameter can be set to the path of a file containing schema data, or can be set to the contents of a schema file directly.
MessageName can be set to the name of a specific message to load only the specified message's schema information. If left empty or set to "*", the entire schema will be loaded.
reset method
Resets all properties to their default values.
Syntax
def reset() -> None: ...
Remarks
This method resets all properties of the component to their default values as specified in the property definitions.
translate method
Translates the specified data.
Syntax
def translate() -> None: ...
Remarks
This method translates the specified data.
on_error event
Fires when an error occurs during message processing. Normally, the class fails with an error.
Syntax
class EDIFACTTranslatorErrorEventParams(object): @property def error_code() -> int: ... @property def description() -> str: ... # In class EDIFACTTranslator: @property def on_error() -> Callable[[EDIFACTTranslatorErrorEventParams], None]: ... @on_error.setter def on_error(event_hook: Callable[[EDIFACTTranslatorErrorEventParams], None]) -> None: ...
Remarks
The on_error event is fired in case of exceptional conditions during message processing. Normally, the class fails with an error.
ConnectionId is the associated client Id, ErrorCode contains an error code, and Description contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.
on_resolve_schema event
Fires whenever a new EDIFACT message is encountered and no schema is found for it.
Syntax
class EDIFACTTranslatorResolveSchemaEventParams(object): @property def message_version() -> str: ... @property def message_type() -> str: ... # In class EDIFACTTranslator: @property def on_resolve_schema() -> Callable[[EDIFACTTranslatorResolveSchemaEventParams], None]: ... @on_resolve_schema.setter def on_resolve_schema(event_hook: Callable[[EDIFACTTranslatorResolveSchemaEventParams], None]) -> None: ...
Remarks
This method fires when the class encounters an EDIFACT message it has not loaded a schema for. The parameters of the event can be used to locate the correct schema and load it with load_schema.
MessageVersion - The EDIFACT version of the message, such as D97A.
MessageType - The type of message, such as INVOIC.
After the event fires, if the class still doesn't have a matching schema, then it will attempt schema-less parsing of the EDIFACT message.
on_validate_warning event
Fires to warn about validation errors.
Syntax
class EDIFACTTranslatorValidateWarningEventParams(object): @property def position() -> int: ... @property def line() -> int: ... @property def column() -> int: ... @property def error_code() -> str: ... @property def error_message() -> str: ... @property def error_type() -> int: ... # In class EDIFACTTranslator: @property def on_validate_warning() -> Callable[[EDIFACTTranslatorValidateWarningEventParams], None]: ... @on_validate_warning.setter def on_validate_warning(event_hook: Callable[[EDIFACTTranslatorValidateWarningEventParams], None]) -> None: ...
Remarks
When the class encounters a non-blocking error while validating a document, this event fires with information about the error.
EDIFACTTranslator Config Settings
The class accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the config method.EDIFACTTranslator Config Settings
EDIFACTTranslator Errors
EDIFACTTranslator Errors
| 202 | Invalid argument. |
| 304 | Cannot write to file. |
| 1003 | Could not find the selected schema in the chosen file. |
| 1099 | Encountered an unexpected segment tag. |
| 1100 | Attempted to perform an action while the component was busy, or close an incomplete interchange. |
| 1044 | Tried to load an invalid schema file. |
| 1203 | Encountered an error while validating the UNA segment. |