class Table
Represents an MI table, and provides access to records (particularly searching on record properties), exporters and attribute definitions.Notes
Do not create instances of this class; it represents a pre-existing database structure. UseDatabase.get_table() or Database.get_table_by_guid() to access an instance of this class.
add_subsets(values)
Adds single or multiple subsets to the list of subsets currently applied to theTable object.
Notes
Makes a Service Layer call if the available subsets have not already been fetched.all_records(include_folders=False, include_generics=True, filter_by_subset=True, subset_name=None)
Returns a flattened list of all records in the table and populates eachRecord.children property.
If filter_by_subset is True then the operation will only return records that are in the subset given in
subset_name, if no value is provided then the subset specified on the table will be used.
If filter_by_subset is False then records will be returned from all subsets.
- Parameters:
- include_folders (bool , default: False) – Whether to include folders in the results.
- include_generics (bool , default: True) – Whether to include generics in the results.
- filter_by_subset (bool , default: True) – Whether to filter records by subset.
- subset_name (str , optional) – Name of the subset to use for filtering. If not specified, uses the currently applied subset.
- Return type:
list[
Record] - Raises:
ValueError – If more than one subset is applied to the table when
filter_by_subsetisTrueandsubset_nameis not provided.
Notes
Makes a Service Layer call.bulk_fetch(records, attributes=None, batch_size=100, parallelize=False, max_num_threads=6, include_binary_data=False)
Populate attribute and pseudo-attribute values for multiple records in a single operation. Populates data values for all namedAttributeDefinition and PseudoAttributeDefinition objects in
the specified Record objects. Attribute values for requested attributes are added to
Record.attributes dictionary whether the attribute is populated or not.
Meta-attributes can be included in a bulk operation by providing the meta-attribute AttributeDefinition
in attributes. AttributeDefinition of meta-attributes can be obtained from the parent attribute
AttributeDefinition.meta_attributes.
Attribute values will not be created for attributes not included in the export via the attributes argument and
trying to access them might raise a KeyError.
Versionchanged
Changed in version 4.2: Argumentparallelise was renamed to parallelize.
- Parameters:
- records (list[
Record]) – List of records to fetch data for. - attributes (list[
AttributeDefinitionorPseudoAttributeDefinitionor str], optional) – List of attributes to fetch. Set toNoneto export all record data. - batch_size (int , default: 100) – Number of records to process in each batch.
- parallelize (bool , default: False) – Whether to parallelize the fetch operation.
- max_num_threads (int , default: 6) – Maximum number of threads to use when parallelizing.
- include_binary_data (bool , default: False) – Whether to include binary data in the fetch.
- records (list[
- Raises: InvalidRecordStateError – If one or more records have not been pushed to the server.
Notes
Makes Service Layer calls to fetch attribute data in batches. Providing a list of attributes by name or byAttributeDefinition will not fetch any meta-attributes
associated with those attributes. If the meta-attributes are not explicitly requested, then the resulting
AttributeValue.meta_attributes dictionary will contain empty meta-attribute values.
If include_binary_data is set to False (default), the export will not fetch the binary data
for the requested File and Picture attributes and tabular columns. Instead, the export will export URLs
(see BinaryType.url for more information about using the URL to access the data). URLs should be used
for large files and pictures, or if the binary data itself is not required. However, as no data is fetched,
accessing the binary_data property and save() method will raise a ValueError.
On-demand access to attribute values without using Table.bulk_fetch() always fetches binary data.
To summarize how the file and picture data can be accessed:
include_binary_data = False(default): TheBinaryType.urlproperty is populated.include_binary_data = True: TheBinaryType.binary_dataproperty, andAttributeFile.save()andAttributePicture.save()methods are both available to access and save the binary data. TheBinaryType.urlproperty is empty and returnsNone.
WARNING
parallelize should not be set to True when using long-running sessions authenticated via OIDC. See
OIDC and parallel operation for more details.
If include_binary_data is set to False:
BinaryType.binary_dataandBinaryType.save()raise aValueError.- Calling
AttributeTabular.enable_destructive_editing()on a tabular attribute value with unexported binary data emits aUserWarning. - Proceeding to make destructive changes on a tabular attribute which unexported binary data raises a
UnexportedBinaryDataErroron re-import. - Modifying the
LocalFileValue.file_nameorLocalFileValue.descriptionproperties for a cell with unexported binary without adding new binary data raises aValueErroron re-import.
Examples
The following code snippet shows how to include meta-attributes and pseudo-attributes in abulk_fetch
request:
bulk_fetch_all_record_versions(records, batch_size=100, parallelize=False, max_num_threads=6)
Fetches all record versions for all provided records. Populates theRecord.all_versions, Record.release_state, and Record.record_history
properties of the specified Record objects.
- Parameters:
- records (list[
Record]) – List of records to fetch versions for. - batch_size (int , default: 100) – Number of records to process in each batch.
- parallelize (bool , default: False) – Whether to parallelize the fetch operation.
- max_num_threads (int , default: 6) – Maximum number of threads to use when parallelizing.
- records (list[
WARNING
parallelize should not be set to True when using long-running sessions authenticated via OIDC. See
OIDC and parallel operation for more details.
SEE ALSO
Session.bulk_fetch_release_states()
: Fetches Record.release_state only.
Notes
Makes Service Layer calls to fetch record versions in batches. This operation performs multiple requests per batch. As a result, the batch size should be considered a relative scale factor to control performance vs load on the Granta MI server, and is not an exact statement of the number of records included in each request.bulk_fetch_associated_records(records, target_table, link_direction=‘Both’, attribute_path=None, batch_size=100, parallelize=False, max_num_threads=6)
Fetches records associated with the specifiedRecord objects from a target Table.
Returns a list of dictionaries containing the source record and associated records for each Record
provided.
You may specify link_direction to only follow tabular links in the specified direction, or provide a list of
AttributeDefinitionTabular objects in attribute_path to follow only those tabular links.
Versionchanged
Changed in version 4.2: Argumentparallelise was renamed to parallelize.
- Parameters:
- records (list[
Record]) – List of source records. - target_table (
Table) – Target table to fetch associated records from. - link_direction (str , default: “Both”) – Direction of links to follow:
Both,Forward, orReverse. - attribute_path (list[
AttributeDefinitionTabular], optional) – List of tabular attributes to follow. - batch_size (int , default: 100) – Number of records to process in each batch.
- parallelize (bool , default: False) – Whether to parallelize the fetch operation.
- max_num_threads (int , default: 6) – Maximum number of threads to use when parallelizing.
- records (list[
- Return type:
list[dict[str,
Record| list[Record]]] - Raises: InvalidRecordStateError – If one or more records have not been pushed to the server.
WARNING
parallelize should not be set to True when using long-running sessions authenticated via OIDC. See
OIDC and parallel operation for more details.
Notes
Makes Service Layer calls to fetch associated records in batches.bulk_fetch_data_revision_history(records, batch_size=100, parallelize=False, max_num_threads=6)
Fetches the data revision history for all attributes of the provided records. Populates theRecord.data_revision_history property.
Versionchanged
Changed in version 4.2: Argumentparallelise was renamed to parallelize.
- Parameters:
- records (list[
Record]) – List of records to fetch data revision history for. - batch_size (int , default: 100) – Number of records to process in each batch.
- parallelize (bool , default: False) – Whether to parallelize the fetch operation.
- max_num_threads (int , default: 6) – Maximum number of threads to use when parallelizing.
- records (list[
- Raises: InvalidRecordStateError – If one or more records have not been pushed to the server.
WARNING
parallelize should not be set to True when using long-running sessions authenticated via OIDC. See
OIDC and parallel operation for more details.
Notes
Makes Service Layer calls to fetch data revision history in batches.bulk_link_fetch(records, link_groups=None, batch_size=100, parallelize=False, max_num_threads=6, filter_subsets=True)
Fetches and populates record link groups for the specifiedRecord objects.
Versionchanged
Changed in version 4.2: Argumentparallelise was renamed to parallelize.
- Parameters:
- records (list[
Record]) – List of records to fetch links for. - link_groups (list [str ] , optional) – List of link group names to fetch. Set to
Noneto fetch all. - batch_size (int , default: 100) – Number of records to process in each batch.
- parallelize (bool , default: False) – Whether to parallelize the fetch operation.
- max_num_threads (int , default: 6) – Maximum number of threads to use when parallelizing.
- filter_subsets (bool , default: True) – Whether to filter by subsets. If
True, only linked records in the default subset of their table are returned. IfFalse, linked records are returned from all subsets.
- records (list[
- Raises: InvalidRecordStateError – If one or more records have not been pushed to the server.
WARNING
parallelize should not be set to True when using long-running sessions authenticated via OIDC. See
OIDC and parallel operation for more details.
Notes
Makes Service Layer calls to fetch links in batches.create_empty_attribute_value(definition)
Create an emptyAttributeValue instance for an attribute.
This can subsequently be assigned to a record for import.
- Parameters:
definition (
AttributeDefinition) – Attribute definition object. - Return type:
AttributeValue
create_record(name, parent=None, short_name=None, attributes=None, folder=False, subsets=None, release_record=False, color=RecordColor.InheritFromParent)
Creates a newRecord object in the Table.
The record will not exist in Granta MI or be assignable as a parent until it is pushed to the server.
- Parameters:
- name (str) – Long name of the record.
- parent (
RecordorTable, optional) – Parent record or table. - short_name (str , optional) – Short name of the record.
- attributes (dict[str,
AttributeValue], optional) – Dictionary of attribute values. - folder (bool , default: False) – If true, the record will be created as a folder.
- subsets (set [str ] , optional) – List of subsets the record will belong to. If not specified, record will be added to the currently active subset(s) on the table.
- release_record (bool , default: False) – Whether the record will be released when pushed to the server.
- color (
RecordColor, default: RecordColor.InheritFromParent) – Record color. If not specified, inherits from parent.
- Return type:
Record
get_attribute_definition(name=None, identity=None)
Returns theAttributeDefinition object specified by name or the identifier identity.
Meta-attributes are also returned if the identifier is provided.
- Parameters:
- name (str , optional) – Name of the
AttributeDefinitionobject. - identity (int , optional) – Attribute identifier.
- name (str , optional) – Name of the
- Return type:
AttributeDefinitionor list[AttributeDefinition]
get_available_exporters(package=None, model=None, applicability_tag=None)
Returns exporters available on the table filtered by package, model, and applicability tag value.- Parameters:
- package (str , optional) – The target FEA analysis package. For example: ‘NX 10.0’, ‘CATIA V5’.
- model (str , optional) – The material model type. For example, ‘Isotropic’, ‘Linear, temperature-independent, isotropic, thermal, plastic’.
- applicability_tag (str , optional) – A tag that identifies the applications for which an exporter is intended to be used. For example, ‘MIMaterialsGateway’, ‘MIViewer’.
- Return type:
list[
Exporter]
Notes
Makes a Service Layer call on first request for each applicability tag.get_record_by_id(history_identity=None, hguid=None, vguid=None, version_number=None)
Returns theRecord object with the following (sets of) references in priority order.
vguid(record version GUID): Uniquely identifies specific version of record.history_identity(record history identity): Uniquely identifies record only, and optionallyversion_number(record version number).hguid(record history GUID): Uniquely identifies record only.
vguid or version_number are not provided for version controlled records, this method will
return the latest available version of the record available to the user. The latest available version
is dependent on the user’s Granta MI permissions.
This method can return records outside the currently selected subset.
Notes
Makes a Service Layer call.get_record_by_lookup_value(attribute_name, lookup_value)
Returns aRecord object specified by attribute name and an exact match for a short text string.
Provided that:
-
The
lookup_valuematches exactly one record in the table. - The record is in the default subset of the table.
- Parameters:
-
Returns:
Record object or
Noneif not found. -
Return type:
RecordorNone
Notes
Makes a Service Layer call. In Granta MI 2025 R2 and later, if multiple matches are detected, no results are returned. In earlier Granta MI versions, an exception is raised.get_records_by_ids(record_identifiers)
Returns aRecord object for each identifier provided.
The returned list of records will have the same number of elements as the provided list of identifiers.
If no record corresponds to that identifier in this table then the corresponding item in the returned list
will be None.
Each element in the record_identifiers parameter should be a dictionary with one or more of the
following (sets of) references in priority order:
vguid(record version GUID): Uniquely identifies specific version of record.history_identity(record history identity): Uniquely identifies record only, and optionallyversion_number(record version number).hguid(record history GUID): Uniquely identifies record only.
vguid or version_number are not provided for version controlled records, this method will
return the latest available version of the record available to the user. The latest available version
is dependent on the user’s Granta MI permissions.
This method can return records outside the currently selected subset.
- Parameters: record_identifiers (Sequence [dict [str , str | int ] ]) – Sequence of dictionaries containing record identifiers.
- Return type:
list[
Record|None]
Notes
Makes multiple Service Layer calls depending on number of identifiers provided.get_records_from_path(starting_node, tree_path, use_short_names=False)
Return all records at the end of the provided path from a specified node.-
The starting node identifies the node immediately above the path. To start the path at the top of the tree,
set
starting_nodetoNone. To start the path under any other node in the tree, specify aRecordas thestarting_node. -
Specify the path as a list of record names e.g.
['Polymers', 'Plastics', 'Thermoplastics', ...]. -
You can include “wildcards” in the path by setting a node to
Nonee.g.['Thermoplastics', :obj:None, 'Unfilled', ...]. -
By default, the strings specified in the path list are assumed to be record full names; to specify the path
using record short names instead, set
use_short_namesto True. -
Parameters:
- starting_node (
RecordorNone) – Any Record in the table tree. To start the path at the root node of the table tree, set toNone. - tree_path (list[str or
None]) – A list of strings specifying the names of the records in the path. May includeNoneas a wildcard. - use_short_names (bool , default: False) – Whether the strings in the path are the record short names.
- starting_node (
-
Return type:
list[
Record] - Raises: InvalidRecordStateError – If the starting node has not been pushed to the server.
Notes
Makes multiple Service Layer calls.Examples
Example 1:recs = table.get_records_from_path(None, ['Record 1', None, 'Record 2'])
will return all records that are children of a record named Record 2, that also have Record 1 as a
great-grandparent. The grandparent is set as a wildcard, and so any is allowed.
Example 2:
recs = table.get_records_from_path(None, ['Record 1', 'Record 3', None])
will return all records that are grandchildren of records named Record 3 that also have a great-grandparent
called Record 1.
Both of these examples have assumed that Record 1 is a top-level record (and have a starting node as a table
object to reflect this), but the method does not require this. The starting node can be any record object in
the tree.
path_from(starting_node, tree_path, color=RecordColor.InheritFromParent)
Ensures that all the folders in a specified path are available, and creates any that do not already exist. In the case of a version-controlled table, folders are created in an unreleased state.- Parameters:
- starting_node (
RecordorNone) – Identifies the node under which the new path will start. Set toNoneto start the path at the root of the table. Set to an existing record/folder to create the path from the specified node. - tree_path (list [str ]) – The names of the folders in the path, e.g.
['Polymers', 'Plastics', 'Thermoplastics', ...]. Folders in the path will be created if they don’t already exist. Existing records on the path will be converted to generic records. - color (
RecordColor, default: RecordColor.InheritFromParent) – Sets the color of all folders and records in the path.
- starting_node (
- Returns: The Record object representing the last folder in the path.
- Return type:
Record - Raises: InvalidRecordStateError – If one or more start nodes has not been pushed to the server.
Notes
Makes a Service Layer call.paths_from(paths)
Create multiple paths between specified start and end nodes in the table tree. See description ofpath_from() for further details.
- Parameters:
paths (list[dict[str,
Record|None|RecordColor| list[str]]]) – List of path specifications. - Return type:
list[tuple[dict,
Record]] - Raises: InvalidRecordStateError – If one or more start nodes has not been pushed to the server.
Examples
Paths are specified as a list of dictionaries with the following structure:Notes
Makes a Service Layer call.refetch_children(filter_by_subset=True, subset_name=None)
Refreshes the list of direct children belonging to the table. Iffilter_by_subset is True then the operation will only return records that are in the subset given
in subset_name, if no value is provided then the subset specified on the table will be used.
If filter_by_subset is False then records will be returned from all subsets.
- Parameters:
- Raises:
ValueError – If more than one subset is applied to the table when
filter_by_subsetisTrueandsubset_nameis not provided.
Notes
Makes a Service Layer call.refresh_attributes()
Performs a Foundation APIBrowseService.get_attribute_details() request and creates a new set of
attributes.
This method only updates the details of existing attributes. To update the list of available attributes, use
Database.refresh_tables().
Notes
Makes a Service Layer call.refresh_subsets()
Fetches the list of subsets which can be applied to this table.Notes
Makes a Service Layer call.remove_subsets(values)
Removes single or multiple subsets from the list of subsets currently associated with theTable object.
reset_display_unit(attribute)
Resets the display unit for aPOIN or RNGE attribute back to the unit system default.
- Parameters:
attribute (str or
AttributeDefinitionPointorAttributeDefinitionRange) – Attribute name or attribute definition object.
search_for_records_by_name(name, filter_by_subset=True, subset_name=None)
Performs a search on record name within the table. Returns only theRecord objects whose short or long names are an exact match for name.
If filter_by_subset is True then the search will only return records that are in the subset given
in subset_name, if no value is provided then the subset specified on the table will be used.
If filter_by_subset is False then records will be returned from all subsets.
This method is case-insensitive.
- Parameters:
- Return type:
list[
Record] - Raises:
ValueError – If more than one subset is applied to the table when
filter_by_subsetisTrueandsubset_nameis not provided.
Notes
UseDatabase.search_for_records_by_name() to search across the whole database.
Makes a Service Layer call.
search_for_records_by_text(text, filter_by_subset=True, subset_name=None)
Performs a simple text search within the table for the specified string. Returns a list of matchingRecord objects.
If filter_by_subset is True then the search will only return records that are in the subset given in
subset_name, if no value is provided then the subset specified on the table will be used.
If filter_by_subset is False then records will be returned from all subsets.
- Parameters:
- Return type:
list[
Record] - Raises:
ValueError – If more than one subset is applied to the table when
filter_by_subsetisTrueandsubset_nameis not provided.
SEE ALSO
Database.search_for_records_by_text()
: Searches for records across the whole database.
Notes
Makes a Service Layer call.search_for_records_where(list_of_criteria, silent=False, filter_by_subset=True, subset_name=None)
Performs a search using criteria within the table. UseDatabase.search_for_records_where() to search across the whole database.
The provided list_of_criteria must only comprise criteria defined against attributes in this table or
criteria defined against pseudo-attributes. If it includes any criteria defined against attributes of another
table, a ValueError is raised.
If filter_by_subset is True then the search will only return records that are in the subset given in
subset_name, if no value is provided then the subset specified on the table will be used.
If filter_by_subset is False then records will be returned from all subsets.
- Parameters:
- list_of_criteria (list[
SearchCriterion]) – List of search criteria to apply. - silent (bool , default: False) – Whether to ignore errors caused by non-existent attributes.
- filter_by_subset (bool , default: True) – Whether to filter records by subset.
- subset_name (str , optional) – Name of the subset to use for filtering.
- list_of_criteria (list[
- Returns: A list of Record objects that match the provided criteria.
- Return type:
list[
Record] - Raises:
- ValueError – If more than one subset is applied to the table when
filter_by_subsetisTrueandsubset_nameis not provided. - KeyError – If the search criteria include an attribute that does not exist in the table and
silentisFalse.
- ValueError – If more than one subset is applied to the table when
Notes
Makes a Service Layer call. Tabular column criteria are aggregated by column name when processed server-side, effectively restricting results to records where a single row must meet all criteria on the same column. To perform a search with multiple tabular column criteria defined on the same column, and obtain results where the criteria can be met by individual different rows, perform individual searches for each criterion and compute the intersection of the resulting lists of records.set_display_unit(attribute, unit_symbol)
Sets the display unit forPOIN and RNGE attributes (not used for import or FEA exporters).
- Parameters:
- attribute (str or
AttributeDefinitionPointorAttributeDefinitionRange) – Attribute name or attribute definition object. - unit_symbol (str) – Unit symbol to set as the display unit.
- attribute (str or
Notes
Units that include a currency can only be set with the abstractcurrency unit. This will cause the
attribute to be returned with the Database Currency. For example instead of USD/kg use currency/kg.
property attributes : Dict[str, AttributeDefinition]
All attributes included in the table schema, indexed by name. Meta-attributes are accessible through themeta_attributes property of their parent attribute.
- Return type:
dict[str,
AttributeDefinition]
Notes
Makes a Service Layer call if the layouts have not already been fetched.property children : List[Record]
Return the children of the Table node. Analogous toRecord.children, this returns all the records one level from the Table root.
Records returned by this property may have been cached from previous calls to Table.refetch_children() or
Table.all_records(), which apply subset filtering. If the Table subset configuration has
since been updated, refresh the list of children via one of the methods listed.
If there is no cached list of children, children are dynamically fetched on property access via
refetch_children(). The default subset filtering behavior is applied.
- Return type:
list[
Record] - Raises:
ValueError – If more than one subset is applied to the
Table.
Notes
Makes a Service Layer call if the children have not already been fetched.property database : Database
Database in which the Table is defined.
- Returns: Database object.
- Return type:
Database
property db_key : str
Parent database key.- Return type: str
property default_layout : str | None
Name of default layout for thisTable.
- Return type:
str or
None
Notes
Makes a Service Layer call if the layouts have not already been fetched.property default_subset : str | None
The default subset for thisTable.
- Return type: str or None
property guid : str
GUID of the table.- Return type: str
property layouts : Dict[str, TableLayout]
Fetch and view the layouts available in this table.- Return type:
dict[str,
TableLayout]
Notes
Makes a Service Layer call if the layouts have not already been fetched.property mi : Session
MI Session that was used to create or access theTable object.
Used for any Service Layer calls made by the Table.
- Returns: Session object.
- Return type:
Session
property min_max_type : str
How table-wide minimum and maximum values of point, integer, range, and date-time attributes are calculated.None: Does not calculate values (can improve performance when loading tables)Approximate(default): Uses a fast, approximate algorithmExact: Takes account of current subset and permissions (can be slow on large tables)
- Return type: str
Notes
Makes a Service Layer call.property name : str
Name of the table.- Return type: str
property subsets : Set[str]
Subsets that are currently applied to theTable object.
Used for record creation, searching, and record fetching.
WARNING
If using any Table method which returns a list of records, such as a search method orTable.all_records(), you must ensure that only one subset is currently applied to the table.
Otherwise, a ValueError will be raised by that method.
property subsets_available : Set[str]
Subsets which can be applied to this table.Notes
Makes a Service Layer call if the subsets have not already been fetched.property unit_system : str
Unit system currently in use.- Return type: str