Part compliance#

Query definition#

class PartComplianceQuery#

Evaluates compliance for Granta MI part records against a number of indicators.

If the parts are associated with materials, parts, specifications, or substances, these are also evaluated and returned.

All methods used to add parts and indicators to this query return the query itself so that they can be chained together as required. Records can be added using a combination of any of the available methods.

Once the query is fully constructed, use the cxn. run() method to return a result of type PartComplianceQueryResult.

Examples

>>> cxn = Connection("http://my_mi_server/mi_servicelayer").with_autologon().connect()
>>> indicator = WatchListIndicator(
...     name="Prop 65",
...     legislation_ids=["Prop65"]
... )
>>> query = (
...     PartComplianceQuery()
...     .with_part_numbers(['DRILL', 'FLRY34'])
...     .with_indicators([indicator])
... )
>>> cxn.run(query)
<PartComplianceQueryResult: 2 PartWithCompliance results>
with_indicators(indicators)#

Add a list or set of WatchListIndicator or RoHSIndicator objects to evaluate compliance against.

Parameters:
indicatorslist[WatchListIndicator | RoHSIndicator]

List of indicators.

Returns:
Query

Current query object.

Raises:
TypeError

Error to raise if the method is called with values that do not match the types described above.

Examples

>>> indicator = WatchListIndicator(
...     name="Prop 65",
...     legislation_ids=["Prop65"]
... )
>>> MaterialComplianceQuery().with_indicators([indicator])
<MaterialCompliance: 0 materials, batch size = 100, 1 indicators>
with_part_numbers(part_numbers)#

Add a list or set of parts to a part query, referenced by part number.

Parameters:
part_numberslist[str] | set[str]

List or set of part numbers.

Returns:
Query

Current query object.

Raises:
TypeError

Error to raise if the method is called with values that do not match the types described earlier.

Examples

>>> query = PartComplianceQuery().with_part_numbers(['DRILL', 'FLRY34'])
<PartCompliance: 2 parts, batch size = 10, 0 indicators>
with_record_guids(record_guids)#

Add a list or set of record GUIDs to a query.

Parameters:
record_guidslist[str] | set[str]

List or set of record GUIDs.

Returns:
Query

Current query object.

Raises:
TypeError

Error to raise if the method is called with values that do not match the types described earlier.

Examples

>>> query = MaterialComplianceQuery()
>>> query = query.with_record_guids(['bdb0b880-e6ee-4f1a-bebd-af76959ae3c8',
>>>                                  'a98cf4b3-f96a-4714-9f79-afe443982c69'])
<MaterialCompliance: 2 materials, batch size = 100, 0 indicators>
with_record_history_guids(record_history_guids)#

Add a list or set of record history GUIDs to a query.

Parameters:
record_history_guidslist[str] | set[str]

List or set of record history GUIDs.

Returns:
Query

Current query object.

Raises:
TypeError

Error to raise if the method is called with values that do not match the types described earlier.

Examples

>>> query = MaterialComplianceQuery()
>>> query.with_record_history_guids(['41e20a88-d496-4735-a177-6266fac9b4e2',
>>>                                  'd117d9ad-e6a9-4ba9-8ad8-9a20b6d0b5e2'])
<MaterialCompliance: 2 materials, batch size = 100, 0 indicators>
with_record_history_ids(record_history_identities)#

Add a list or set of record history identities to a query.

Parameters:
record_history_identitieslist[int] | set[int]

List or set of record history identities.

Returns:
Query

Current query object.

Raises:
TypeError

Error to raise if the method is called with values that do not match the types described earlier.

Examples

>>> MaterialComplianceQuery().with_record_history_ids([15321, 17542, 942])
<MaterialCompliance: 3 materials, batch size = 50, 0 indicators>
with_batch_size(batch_size)#

Set the number of records to include in a single request for this query.

Default values are set based on typical usage of the Restricted Substances database. This value can be changed to optimize performance on a query-by-query basis if required. For example, you can change it if certain records contain particularly large or small numbers of associated records.

Parameters:
batch_sizeint

Number of records to include in a single request to Granta MI.

Returns:
Query

Current query object.

Raises:
ValueError

Error to raise if the batch size is set to a number less than 1.

TypeError

Error to raise if a value of any type other than int is specified.

Notes

The Restricted Substances database makes extensive use of tabular data and associated records to store the complex hierarchical relationships that define compliance of products, assemblies, parts, specifications, and materials. As a result, it is impossible to determine the complexity of a particular query without knowing precisely how many records are related to the record included in the query.

The default batch sizes are set for each record type and represent appropriate numbers of those records to be included in the same request assuming typical numbers of associated records.

Even if the records are queried in multiple batches, the results are assembled into a single result object.

Examples

>>> MaterialComplianceQuery().with_batch_size(50)
<MaterialCompliance: 0 materials, batch size = 50, 0 indicators>

Query result#

class PartComplianceQueryResult(results, indicator_definitions, messages)#

Retrieves the result of running the PartComplianceQuery class.

This class describes the compliance status of parts against one or more indicators.

compliance_by_indicator#

Compliance status for each indicator in the original query. The indicator name is used as the dictionary key.

The result for each indicator is determined by taking the worst result for that indicator across all items included in the query.

Returns:
dict[str, WatchListIndicator | RoHSIndicator]

Examples

>>> compliance_result: MaterialComplianceQueryResult
>>> compliance_result.compliance_by_indicator
{'Prop 65': <WatchListIndicator,
        name: Prop 65,
        flag: WatchListFlag.WatchListAboveThreshold>
}
compliance_by_part_and_indicator#

Compliance status for each part specified in the original query.

Returns:
list[PartWithComplianceResult]

Examples

>>> result: PartComplianceQueryResult
>>> result.compliance_by_part_and_indicator
[<PartWithComplianceResult({PartNumber: DRILL}), 1 indicators>,...]
messages#

Messages generated by Granta MI when running the query. The presence of one or more messages means that something unexpected happened when running the query but that the query could still be completed.

Messages are sorted in order of decreasing severity and are available in the Service Layer log file.

Messages are also logged using the Python logging module to the ansys.grantami.bomanalytics logger. By default, messages with a severity of "warning" or higher are printed on stderr.

Part result#

class PartWithComplianceResult(**kwargs)#

Retrieves an individual part included as part of a compliance query result. This object includes three categories of attributes:

  • The reference to the part in Granta MI (if the part references a record)

  • The compliance status of this part, stored in a dictionary of one or more indicator objects

  • Any part, specification, material, or substance objects which are a child of this part object

property record_history_identity: int | None#

Record history identity.

property record_history_guid: str | None#

Record history GUID.

property record_guid: str | None#

Record GUID.

property part_number: str | None#

Part number.

property identity: str | None#

Item unique identifier.

This property is only populated on BoM query results and is equal to the id attribute of the corresponding input BoM item. If no id has been defined on the BoM item, a unique auto-generated value is assigned during analysis.

property external_identity: str | None#

Item external identity.

This property is only populated on BoM query results and is equal to the <ExternalIdentity> element of the corresponding input BoM item.

property name: str | None#

Item name.

This property is only populated on BoM query results and is equal to the <Name> element of the corresponding input BoM item.

property input_part_number: str | None#

Input part number.

This property is only populated on BoM query results and is equal to the <PartNumber> element of the corresponding input BoM item.

property indicators: Dict[str, WatchListIndicator | RoHSIndicator]#

Compliance status of this item for each indicator included in the original query.

property parts: List[PartWithComplianceResult]#

Part compliance result objects that are direct children of this part in the BoM.

property specifications: List[SpecificationWithComplianceResult]#

Specification compliance result objects that are direct children of this item in the BoM.

property materials: List[MaterialWithComplianceResult]#

Material compliance result objects that are direct children of this part or specification in the BoM.

property substances: List[SubstanceWithComplianceResult]#

Substance compliance result objects that are direct children of this item in the BoM.