Constraints API
Apply constraints to any SDV synthesizer.
Constraints API
The constraint API below applies to any SDV synthesizer object.
get_constraints
Use this function to inspect all of the constraints your synthesizer contains and save them externally as a JSON file.
Parameters:
output_filepath: A string containing the location of a filepath. If provided, this function saves the constraints that are currently added to the synthesizer as a JSON file. Later, these constraints can be set using theset_constraintsfunction.(default)
None: Do not save the constraints in a file.
Output A list of the constraint objects that you have supplied to your synthesizer. If the filepath is provided, then the function also saves the constraints as a JSON file.
constraints = synthesizer.get_constraints(
output_filepath='synthesizer_constraints.json'
)get_metadata
Adding constraints to your synthesizer may internally modify the metadata. Use this function to get the modified metadata after the constraints have been added.
Parameters
version: The version of metadata to get. Supply'modified'to get the modified version of the metadata (after applying the constraints).
Output A Metadata object with the modified metadata
add_constraints
Use this function to add constraints to your synthesizer.
Parameters
(required)
constraints: A list of constraint objects or an auto-detectedConstraintListobject to add to your synthesizer. You can supply predefined constraints or auto-detected constraints. Call this function multiple times to continue adding constraints.
Output (None)
load_constraints
Use this function to load constraints that were previously saved to a file using the get_constraints function.
Parameters:
(required)
filepath: A string with the JSON filepath that contains all the constraint information. This file can be created using theget_constraintsfunction.
Returns: A list of constraint objects. You can add this list directly to your synthesizer using the add_constraints function.
set_constraints
Deprecated. To add constraints from a file, use load_constraints to load in the constraints from the file, and then add_constraints to add them.
❖ detect_constraints
Use this method with an SDV synthesizer in order to detect constraints. All single- and multi-table SDV synthesizers are supported except for DayZSynthesizer.
For API and parameters, see the Auto-Detect Constraints guide.
❖ SDV Enterprise Bundle. This feature is available as part of the CAG Bundle, an optional add-on to SDV Enterprise. For more information, please visit the CAG Bundle page.
JSON Representation
Each constraint can be represented in a JSON file format. This is useful when you want to save all the constraints to be used for a synthesizer, and add them all at once for your workflow.
To create this file format, we recommend adding the constraints to a synthesizer first and then using the get_constraints function. This function renders the JSON file in the required format. Alternatively, you can follow the format below.
JSON Spec Details
The constraints JSON file should be a list of dictionaries. Each dictionary represents a constraint that should be added to the synthesizer. The constraints should be listed in the order in which they should be added.
Each constraint dictionary should include 2 keywords:
"class_name": A string containing the name of the single-table or multi-table constraint class. This is the class name that you'd typically import from thesdv.cagmodule."parameters": A dictionary that contains key/value pairs that correspond to the parameters of that constraint. Each constraint has different parameters that are possible. They typically include information that identifies where in your dataset the constraint should be added, for example the table name, column names, etc. For more information, browse the Predefined Constraints.
Last updated