Creating and Using Custom Generators and Converters in DATAMIMIC¶
DATAMIMIC allows you to create custom generators and converters to meet specific data generation needs. This guide explains how to implement a custom generator, use it in your XML configuration, and integrate it with DATAMIMIC. Additionally, we will cover how to use the DATAMIMIC UI to create a Python script file for the custom generator.
Creating a Custom Generator¶
To create a custom generator, you need to define a Python class that inherits from the Generator parent class. Below is an example of a custom string generator that appends a prefix to a counter value:
1 2 3 4 5 6 7 8 | |
Creating a Custom Converter¶
To create a custom converter, you need to define a Python class that inherits from the Converter parent class. Below is an example of a custom converter that converts a string to uppercase:
1 2 3 | |
Using the Custom Generator and Converter in XML¶
Once you have defined your custom generator, you can use it in your XML configuration file. Here’s how you can do that:
1 2 3 4 | |
Steps to Integrate the Custom Generator and Converter with DATAMIMIC¶
1. Create the Python Script File¶
- Create a Python script file (e.g.,
custom.py) with the custom generator and\or converter class defined in it.
2. Use the DATAMIMIC UI to Create the Python Script File¶
- Open DATAMIMIC UI:
-
Navigate to the Scripts section.
-
Create a New Script:
- Click on "Create New Python Script".
-
Enter the script name (e.g.,
lib). -
Add the Custom Generator Code:
- Copy and paste the custom code into the script editor.
- Save the script.
3. Update the Start File (datamimic.xml)¶
Ensure that your custom Python script file is executed in the start file (datamimic.xml)
to make the custom generator available in the context. Here is an example of how to include this in the start file:
1 2 3 4 5 6 7 8 9 | |
4. Use the Custom Generator in Your XML Configuration¶
You can now use the custom generator in your XML configuration file as shown in the previous section.
1 | |