models.Property

class Property(json, **kwargs)[source]

A virtual object representing a KE-chain property.

Variables
  • bulk_update – flag to postpone update of properties until manually requested

  • type – The property type of the property. One of the types described in pykechain.enums.PropertyType

  • category – The category of the property, either Category.MODEL of Category.INSTANCE

  • description – description of the property

  • unit – unit of measure of the property

  • model – the id of the model (not the model object)

  • output – a boolean if the value is configured as an output (in an activity)

  • part – The (parent) part in which this property is available

  • value – the property value, can be set as well as property

  • validators – the list of validators that are available in the property

  • is_valid – if the property conforms to the validators

  • is_invalid – if the property does not conform to the validator

Construct a Property from a json object.

refresh(json: Optional[Dict] = None, url: Optional[str] = None, extra_params: Optional = None) None[source]

Refresh the object in place.

has_value() bool[source]

Predicate to indicate if the property has a value set.

This predicate determines if the property has a value set. It will not make a call to KE-chain API (in case of reference properties). So it is a tiny fraction ‘cheaper’ in terms of processing time than checking the Property.value itself.

It will return True if the property_type is a Boolean and set to a value of False.

Returns

True if the property has a value set, otherwise (also when value is None) returns False

Return type

Bool

property use_bulk_update

Set or get the toggle to asynchronously update property values.

classmethod set_bulk_update(value)[source]

Set global class attribute to toggle the use of bulk-updates of properties.

property value: Any

Retrieve the data value of a property.

Setting this value will immediately update the property in KE-chain.

Returns

the value

classmethod update_values(client: Client, use_bulk_update: bool = False) None[source]

Perform the bulk update of property values using the stored values in the Property class.

Parameters
  • client (Client) – Client object

  • use_bulk_update (bool) – set the class attribute, defaults to False.

Returns

None

serialize_value(value: [T]) T[source]

Serialize the value to be set on the property.

Parameters

value (Any) – non-serialized value

Returns

serialized value

property part: Part

Retrieve the part that holds this Property.

Returns

The Part associated to this property

Raises

APIError – if the Part is not found

model() AnyProperty[source]

Model object of the property if the property is an instance otherwise itself.

Will cache the model object in order to not generate too many API calls. Otherwise will make an API call to the backend to retrieve its model object.

Returns

Property model object if the current Property is an instance.

Return type

pykechain.models.AnyProperty

property validators

Provide list of Validator objects.

Returns

list of PropertyValidator objects

Return type

list(PropertyValidator)

property is_valid: Optional[bool]

Determine if the value in the property is valid.

If the value of the property is validated as ‘valid’, than returns a True, otherwise a False. When no validators are configured, returns a None. It checks against all configured validators and returns a single boolean outcome.

Returns

True when the value is valid

Return type

bool or None

property is_invalid: Optional[bool]

Determine if the value in the property is invalid.

If the value of the property is validated as ‘invalid’, than returns a True, otherwise a False. When no validators are configured, returns a None. It checks against all configured validators and returns a single boolean outcome.

Returns

True when the value is invalid

Return type

bool

validate(reason: bool = True) List[Union[bool, Tuple]][source]

Return the validation results and include an (optional) reason.

If reason keyword is true, the validation is returned for each validation the [(<result: bool>, <reason:str>), …]. If reason is False, only a single list of validation results for each configured validator is returned.

Parameters

reason (bool) – (optional) switch to indicate if the reason of the validation should be provided

Returns

list of validation results [bool, bool, …] or a list of validation results, reasons [(bool, str), …]

Return type

list(bool) or list((bool, str))

Raises

Exception – for incorrect validators or incompatible values

property representations

Get and set the property representations.

classmethod create(json: dict, **kwargs) AnyProperty[source]

Create a property based on the json data.

This method will attach the right class to a property, enabling the use of type-specific methods.

It does not create a property object in KE-chain. But a pseudo Property object.

Parameters

json (dict) – the json from which the Property object to create

Returns

a Property object

edit(name: ~typing.Optional[str] = <pykechain.utils.Empty object>, description: ~typing.Optional[str] = <pykechain.utils.Empty object>, unit: ~typing.Optional[str] = <pykechain.utils.Empty object>, options: ~typing.Optional[~typing.Dict] = <pykechain.utils.Empty object>, **kwargs) None[source]

Edit the details of a property (model).

Setting an input to None will clear out the value (exception being name).

Parameters
  • name (basestring or None or Empty) – (optional) new name of the property to edit. Cannot be cleared.

  • description (basestring or None or Empty) – (optional) new description of the property. Can be cleared.

  • unit (basestring or None or Empty) – (optional) new unit of the property. Can be cleared.

  • options (dict or None or Empty) – (options) new options of the property. Can be cleared.

  • kwargs – (optional) additional kwargs to be edited

Returns

None

Raises

Examples

>>> front_fork = project.part('Front Fork')
>>> color_property = front_fork.property(name='Color')
>>> color_property.edit(name='Shade',description='Could also be called tint, depending on mixture',unit='RGB')
>>> wheel_property_reference = self.project.model('Bike').property('Reference wheel')
>>> wheel_model = self.project.model('Wheel')
>>> diameter_property = wheel_model.property('Diameter')
>>> spokes_property = wheel_model.property('Spokes')
>>> prefilters = {'property_value': diameter_property.id + ":{}:lte".format(15)}
>>> propmodels_excl = [spokes_property.id]
>>> options = dict()
>>> options['prefilters'] = prefilters
>>> options['propmodels_excl'] = propmodels_excl
>>> wheel_property_reference.edit(options=options)

Not mentioning an input parameter in the function will leave it unchanged. Setting a parameter as None will clear its value (where that is possible). The example below will clear the description, but leave everything else unchanged.

>>> wheel_property.edit(description=None)
delete() None[source]

Delete this property.

Returns

None

Raises

APIError – if delete was not successful

copy(target_part: Part, name: Optional[str] = None) Property[source]

Copy a property model or instance.

Parameters
  • target_part (Part) – Part object under which the desired Property is copied

  • name (basestring) – how the copied Property should be called

Returns

copied Property model.

Raises

IllegalArgumentError – if property and target_part have different Category

Example

>>> property_to_copy = client.property(name='Diameter')
>>> bike = client.model('Bike')
>>> property_to_copy.copy(target_part=bike, name='Bike diameter?')
move(target_part: Part, name: Optional[str] = None) Property[source]

Move a property model or instance.

Parameters
  • target_part (Part) – Part object under which the desired Property is moved

  • name (basestring) – how the moved Property should be called

Returns

copied Property model.

Raises

IllegalArgumentError – if property and target_part have different Category

Example

>>> property_to_move = client.property(name='Diameter')
>>> bike = client.model('Bike')
>>> property_to_move.move(target_part=bike, name='Bike diameter?')

pykechain Property Types

class AttachmentProperty(json, **kwargs)[source]

A virtual object representing a KE-chain attachment property.

Construct a Property from a json object.

property value

Retrieve the data value of this attachment.

Will show the filename of the attachment if there is an attachment available otherwise None Use save_as in order to download as a file.

Example

>>> file_attachment_property = project.part('Bike').property('file_attachment')
>>> if file_attachment_property.value:
...     file_attachment_property.save_as('file.ext')
... else:
...     print('file attachment not set, its value is None')
clear() None[source]

Clear the attachment from the attachment field.

Raises

APIError – if unable to remove the attachment

property filename: Optional[str]

Filename of the attachment, without the full ‘attachment’ path.

json_load()[source]

Download the data from the attachment and deserialise the contained json.

Returns

deserialised json data as dict

Raises
  • APIError – When unable to retrieve the json from KE-chain

  • JSONDecodeError – When there was a problem in deserialising the json

Example

Ensure that the attachment is valid json data

>>> json_attachment = project.part('Bike').property('json_attachment')
>>> deserialised_json = json_attachment.json_load()
upload(data: Any, **kwargs: Any) None[source]

Upload a file to the attachment property.

When providing a matplotlib.figure.Figure object as data, the figure is uploaded as PNG. For this, matplotlib should be installed.

Parameters

data (basestring) – File path

Raises
  • APIError – When unable to upload the file to KE-chain

  • OSError – When the path to the file is incorrect or file could not be found

save_as(filename: Optional[str] = None, **kwargs) None[source]

Download the attachment to a file.

Parameters

filename (basestring or None) – (optional) File path. If not provided, will be saved to current working dir with self.filename.

One can pass the size parameter as kwargs. See more in Enum:ImageSize or alternatively customize the desired image size like this (width_value, height_value)

Raises
  • APIError – When unable to download the data

  • OSError – When unable to save the data to disk

class SelectListProperty(json, **kwargs)[source]

A virtual object representing a KE-chain single-select list property.

Construct a Property from a json object.

class DatetimeProperty(json, **kwargs)[source]

A virtual object representing a KE-chain datetime property.

Construct a Property from a json object.

to_datetime() Union[None, datetime][source]

Retrieve the datetime as a datetime.datetime value.

Returns

the value

static to_iso_format(date_time: datetime) str[source]

Convert a datetime object to isoformat.

serialize_value(value) str[source]

Serialize the value to be set on the property by checking for formatted strings or datetime objects.

Parameters

value (Any) – non-serialized value

Returns

serialized value

pykechain References Property Types

class MultiReferenceProperty(json, **kwargs)[source]

A virtual object representing a KE-chain multi-references property.

New in version 1.14.

Construct a ReferenceProperty from a json object.

REFERENCED_CLASS

alias of Part

choices() List[Part][source]

Retrieve the parts that you can reference for this MultiReferenceProperty.

This method makes 2 API calls: 1) to retrieve the referenced model, and 2) to retrieve the instances of that model.

Returns

the Part’s that can be referenced as a PartSet.

Raises

APIError – When unable to load and provide the choices

Example

>>> reference_property = project.part('Bike').property('a_multi_reference_property')
>>> referenced_part_choices = reference_property.choices()
set_prefilters(property_models: List[Union[AnyProperty, str]] = None, values: List[Any] = None, filters_type: List[FilterType] = None, prefilters: List[PropertyValueFilter] = None, overwrite: Optional[bool] = False, clear: Optional[bool] = False, validate: Optional[Union[bool, Part]] = True) None[source]

Set the pre-filters on a MultiReferenceProperty.

Parameters
  • property_models (list) – list of Property models (or their IDs) to set pre-filters on

  • values (list) – list of values to pre-filter on, value has to match the property type.

  • filters_type (list) – list of filter types per pre-filter, one of enums.FilterType, defaults to FilterType.CONTAINS

  • prefilters (list) – list of PropertyValueFilter objects

  • overwrite (bool) – whether existing pre-filters should be overwritten, if new filters to the same property are provided as input. Does not remove non-conflicting prefilters. (default = False)

  • clear (bool) – whether all existing pre-filters should be cleared. (default = False)

  • validate (bool) – whether the pre-filters are validated to the referenced model, which can be provided as well

Raises

IllegalArgumentError – when the type of the input is provided incorrect.

get_prefilters(as_lists: Optional[bool] = False) Union[List[PropertyValueFilter], Tuple[List[str]]][source]

Retrieve the pre-filters applied to the reference property.

Parameters

as_lists – (O) (default = False) If True, the pre-filters are returned as three lists of property model UUIDs, values and filter types.

Returns

prefilters

set_excluded_propmodels(property_models: List[Union[AnyProperty, str]], overwrite: Optional[bool] = False, validate: Optional[Union[bool, Part]] = True) None[source]

Exclude a list of properties from being visible in the part-shop and modal (pop-up) of the reference property.

Parameters
  • property_models (list) – list of Property models (or their IDs) to exclude.

  • overwrite – flag whether to overwrite existing (True) or append (False, default) to existing filter(s).

:type overwrite bool :param validate: whether the pre-filters are validated to the referenced model, which can be provided as well :type validate: bool

:raises IllegalArgumentError

get_excluded_propmodel_ids() List[str][source]

Retrieve a list of property model UUIDs which are not visible.

Returns

list of UUIDs

:rtype list

class ActivityReferencesProperty(json, **kwargs)[source]

A virtual object representing a KE-chain Activity References property.

New in version 3.7.

Construct a ReferenceProperty from a json object.

REFERENCED_CLASS

alias of Activity

class ScopeReferencesProperty(json, **kwargs)[source]

A virtual object representing a KE-chain Scope References property.

Construct a ReferenceProperty from a json object.

REFERENCED_CLASS

alias of Scope

set_prefilters(prefilters: Optional[List[ScopeFilter]] = None, clear: Optional[bool] = False) None[source]

Set pre-filters on the scope reference property.

Parameters
  • prefilters (list) – list of Scope Filter objects

  • clear (bool) – whether all existing pre-filters should be cleared. (default = False)

Returns

None

get_prefilters() List[ScopeFilter][source]

Return a list of ScopeFilter objects currently configured on the property.

Returns

list of ScopeFilter objects

:rtype list

class UserReferencesProperty(json, **kwargs)[source]

A virtual object representing a KE-chain User References property.

Construct a ReferenceProperty from a json object.

REFERENCED_CLASS

alias of User

value_ids() Optional[List[int]][source]

Retrieve the referenced object UUIDs only.

Returns

list of UUIDs

:rtype list

class FormReferencesProperty(json, **kwargs)[source]

A virtual object representing a KE-chain Form References property.

New in version 3.7.

Construct a ReferenceProperty from a json object.

class ContextReferencesProperty(json, **kwargs)[source]

A virtual object representing a KE-chain Context References property.

New in version 3.7.

Construct a ReferenceProperty from a json object.

class StatusReferencesProperty(json, **kwargs)[source]

A virtual object representing a KE-chain Context References property.

New in version 3.19.

Construct a ReferenceProperty from a json object.