Base
Base class for all Speckle objects.
The base object class is the foundation of all data being transferred with Speckle. Any custom data structure that you want to transfer via Speckle should inherit from it.
Objects in Speckle are immutable for storage purposes. When any property changes,
the object gets a new identity (hash). This hash is stored in the id property
after serialization.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Union[str, None]
|
Unique identifier (hash) for the object. This is typically |
applicationId |
Union[str, None]
|
Optional identifier for the application that created this object, can store the host application's native object ID. |
from specklepy.objects.base import Base
obj = Base(id="some-id", applicationId="my-app")
obj["custom_prop"] = 42 # Add a dynamic property
obj["@detached_prop"] = another_object # Add a detached property
of_type
classmethod
Get a plain Base object with a specified speckle_type.
The speckle_type is protected and cannot be overwritten on a class instance. This is to prevent problems with receiving in other platforms or connectors. However, if you really need a base with a different type, here is a helper to do that for you.
This is used in the deserialisation of unknown types so their speckle_type can be preserved.
Source code in src/specklepy/objects/base.py
update_forward_refs
classmethod
Attempts to populate the internal defined types dict for type checking sometime after defining the class. This is already done when defining the class, but can be called again if references to undefined types were included.
See objects.geometry for an example of how this is used with
the Brep class definitions.
Source code in src/specklepy/objects/base.py
validate_prop_name
classmethod
validate_prop_name(name: str) -> None
Validator for dynamic attribute names.
Source code in src/specklepy/objects/base.py
add_chunkable_attrs
add_chunkable_attrs(**kwargs: int) -> None
Mark defined attributes as chunkable for serialisation
Source code in src/specklepy/objects/base.py
add_detachable_attrs
Mark defined attributes as detachable for serialisation
Source code in src/specklepy/objects/base.py
get_member_names
Get all of the property names on this object, dynamic or not
Source code in src/specklepy/objects/base.py
get_serializable_attributes
get_typed_member_names
get_dynamic_member_names
Get all of the names of the dynamic properties of this object
get_children_count
get_children_count() -> int
get_id
Gets the id (a unique hash) of this object. ⚠️ This method fully serializes the object which, in the case of large objects (with many sub-objects), has a tangible cost. Avoid using it!
Note: the hash of a decomposed object differs from that of a non-decomposed object
Returns:
| Type | Description |
|---|---|
str
|
str -- the hash (id) of the fully serialized object |