Skip to main content

class Database

Represents an MI database, and provides access to its tables, unit systems, and record link groups.

Notes

Do not create instances of this class; it represents a pre-existing database structure. Use Session.get_db() to access an instance of this class.

dimensionally_equivalent_units(unit)

Returns all units which are dimensionally equivalent to the specified unit, with conversion factor and offset.
  • Parameters: unit (str) – The unit to find equivalent units for.
  • Returns: Dictionary mapping unit symbols to their conversion factors and offsets.
  • Return type: dict[str, dict[str, float]]

Notes

Makes a single call to the Service Layer and caches the results.

Examples

get_record_by_id(hguid=None, vguid=None, history_identity=None, version_number=None)

Returns the Record object with the following (sets of) references in priority order.
  1. vguid (record version GUID): Uniquely identifies specific version of record.
  2. history_identity (record history identity): Uniquely identifies record only, and optionally version_number (record version number).
  3. hguid (record history GUID): Uniquely identifies record only.
If 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.
  • Parameters:
    • hguid (str , optional) – Record history GUID: uniquely identifies record.
    • vguid (str , optional) – Record version GUID: uniquely identifies record version.
    • history_identity (int , optional) – Record history identity.
    • version_number (int , optional) – Record version number.
  • Returns: Record object with the specified ID.
  • Return type: Record

Notes

Makes a Service Layer call.

get_records_by_ids(record_identifiers)

Returns a Record object for each identifier provided. Each element in the record_identifiers parameter should be a dictionary with one or more of the following (sets of) references in priority order:
  1. vguid (record version GUID): Uniquely identifies specific version of record.
  2. history_identity (record history identity): Uniquely identifies record only, and optionally version_number (record version number).
  3. hguid (record history GUID): Uniquely identifies record only.
If 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. 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 then the corresponding item in the returned list will be None.
  • 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_table(name)

Returns the Table object with the specified name. Case-insensitive.
  • Parameters: name (str) – Name of the table.
  • Return type: Table
  • Raises: KeyError – If no table with the specified name exists in the database.

get_table_by_guid(guid)

Returns the Table object with the specified GUID. Case-insensitive.
  • Parameters: guid (str) – GUID of the table.
  • Return type: Table
  • Raises: KeyError – If no table with the specified GUID exists in the database.

refetch_unit_systems()

Fetches the unit systems associated with the database.

Notes

Makes a Service Layer call.

refresh_tables()

Performs a Foundation API BrowseService.get_tables() request and creates a new list of tables. Also updates the attributes in each table.

Notes

Makes a Service Layer call.

search_for_records_by_name(name)

Performs a search on record name across the database. Returns only the Record objects whose short or long names are an exact match for name. Case-insensitive. This method searches in the currently active subsets for each table, and will raise an exception if a table has more than one active subset.
  • Parameters: name (str) – Name to search for.
  • Return type: list[Record]

Notes

Makes a Service Layer call for each table in the database.

SEE ALSO

Table.search_for_records_by_name() : Searches within a single table.

search_for_records_by_text(text)

Performs a simple text search across the database for the string provided. Returns a list of matching Record objects. This method does not apply any subset filtering.
  • Parameters: text (str) – Text to search for.
  • Return type: list[Record]

Notes

Makes a Service Layer call for each table in the database.

SEE ALSO

Table.search_for_records_by_text() : Searches within a single table.

search_for_records_where(list_of_criteria, silent=True)

Performs a search using criteria within tables across the database. Use Table.search_for_records_where() to narrow your search to a single table. Criteria searches can be performed at the database level only if the provided list_of_criteria is not table specific, i.e. all criterion apply to pseudo-attributes. If any criterion is specific to an attribute, then the criterion is table specific and the search will be performed on the table.
  • Parameters:
    • list_of_criteria (list[SearchCriterion]) – List of search criteria.
    • silent (bool , default: True) – Whether to ignore errors caused by non-existent attributes.
  • Returns: A list of Record objects that match the provided criteria.
  • Return type: list[Record]
  • Raises:
    • ValueError – If the list_of_criteria comprise criteria in multiple tables.
    • KeyError – If the search criteria include an attribute that does not exist in the database and silent is False.

Notes

Makes a Service Layer call for each table in the database. 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.

property absolute_temperatures : bool

Whether the Database uses absolute temperature units (Kelvin/Rankine) or not (Celsius/Fahrenheit). Default value is False.

property currency : str

Database currency code.
  • Return type: str

property db_key : str

Database key.
  • Return type: str

property guid : str

GUID of the database.
  • Return type: str

property mi : Session

Granta MI Session used to create or access the Database object. Used for any Service Layer calls made by the Database.
  • Returns: The session object.
  • Return type: Session

property name : str

Name of the database.
  • Return type: str

property parameters : Dict[str, DatabaseParameter]

Parameters associated with the database, indexed by name. All record link groups in the database.

property tables : List[Table]

Tables associated with the database.
  • Return type: list[Table]

property tables_by_guid : Dict[str, Table]

Tables in the database, as dictionary keyed by GUID.
  • Return type: dict[str, Table]

property tables_by_name : Dict[str, Table]

Tables in the database, as dictionary keyed by name.
  • Return type: dict[str, Table]

property unit_system : str

Currently selected unit system (default is DATABASE_UNIT_SYSTEM).
  • Return type: str

property unit_systems_available : List[str]

Names of unit systems associated with the database.

property version_guid : str

Version GUID of the database.
  • Return type: str