🔍 Code Extractor

class TaxonomyItem

Maturity: 52

TaxonomyItem is a base class representing an item in a SharePoint TermStore with a unique identifier, name, and metadata about creation and modification times.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/taxonomy/item.py
Lines:
7 - 38
Complexity:
moderate

Purpose

This class serves as a base class for taxonomy-related objects in SharePoint's TermStore system. It provides core functionality for managing taxonomy items including unique identification, naming, and resource path management. The class handles property synchronization and resource path updates when the item's identifier changes. It is designed to be inherited by more specific taxonomy classes and integrates with the Office365 REST API client framework.

Source Code

class TaxonomyItem(ClientObject):
    """The TaxonomyItem class is a base class that represents an item in the TermStore (section 3.1.5.23).
    A TaxonomyItem has a name and a unique identifier. It also contains date and time of when the item is created and
    when the item is last modified."""

    @property
    def id(self):
        # type: () -> Optional[str]
        """Gets the Id of the current TaxonomyItem"""
        return self.properties.get("id", None)

    @property
    def name(self):
        # type: () -> Optional[str]
        """Gets the name of the current TaxonomyItem object"""
        return self.properties.get("name", None)

    @property
    def property_ref_name(self):
        # type: () -> str
        return "id"

    def set_property(self, name, value, persist_changes=True):
        super(TaxonomyItem, self).set_property(name, value, persist_changes)
        if name == self.property_ref_name:
            if self._resource_path is None:
                self._resource_path = ResourcePath(
                    value, self.parent_collection.resource_path
                )
            else:
                self._resource_path.patch(value)
        return self

Parameters

Name Type Default Kind
bases ClientObject -

Parameter Details

name: The name parameter in set_property() specifies which property to set on the TaxonomyItem object

value: The value parameter in set_property() contains the new value to assign to the specified property

persist_changes: Boolean flag in set_property() that determines whether property changes should be persisted immediately (default: True)

Return Value

The class instantiation returns a TaxonomyItem object. The set_property() method returns self to enable method chaining. Properties like id and name return Optional[str] values that may be None if not yet set. The property_ref_name property returns the string 'id' which identifies the reference property name.

Class Interface

Methods

@property id(self) -> Optional[str] property

Purpose: Gets the unique identifier of the current TaxonomyItem

Returns: The ID as a string if set, otherwise None

@property name(self) -> Optional[str] property

Purpose: Gets the name of the current TaxonomyItem object

Returns: The name as a string if set, otherwise None

@property property_ref_name(self) -> str property

Purpose: Returns the name of the property used as the resource reference identifier

Returns: Always returns the string 'id' which identifies the reference property

set_property(self, name: str, value: Any, persist_changes: bool = True) -> TaxonomyItem

Purpose: Sets a property value on the TaxonomyItem and manages resource path updates when the id property changes

Parameters:

  • name: The name of the property to set
  • value: The value to assign to the property
  • persist_changes: Whether to persist the changes immediately (default: True)

Returns: Returns self to enable method chaining

Attributes

Name Type Description Scope
properties dict Dictionary storing the property values of the TaxonomyItem (inherited from ClientObject) instance
_resource_path Optional[ResourcePath] Internal resource path object that tracks the API endpoint path for this item, automatically updated when id changes instance
parent_collection ClientObject Reference to the parent collection that contains this TaxonomyItem (inherited from ClientObject) instance

Dependencies

  • office365
  • typing

Required Imports

from typing import Optional
from office365.runtime.client_object import ClientObject
from office365.runtime.paths.resource_path import ResourcePath

Usage Example

# Note: TaxonomyItem is typically not instantiated directly but through subclasses
# Example showing property access and modification:

# Assuming taxonomy_item is obtained from a TermStore query
taxonomy_item = term_store.get_term_by_id('some-guid')

# Access properties
item_id = taxonomy_item.id
item_name = taxonomy_item.name

# Set a property with persistence
taxonomy_item.set_property('name', 'New Term Name', persist_changes=True)

# Chain property updates
taxonomy_item.set_property('name', 'Updated Name').set_property('description', 'New description')

# Get the reference property name
ref_name = taxonomy_item.property_ref_name  # Returns 'id'

Best Practices

  • TaxonomyItem is a base class and should typically be used through inheritance rather than direct instantiation
  • The set_property() method automatically manages resource path updates when the 'id' property changes, ensuring path consistency
  • Use persist_changes=True (default) when you want changes to be immediately synchronized with the server
  • Always check if id and name properties are None before using them, as they return Optional[str]
  • The class maintains internal state through _resource_path which is automatically managed when the id property is set
  • Method chaining is supported through set_property() which returns self
  • The property_ref_name is used internally to identify which property serves as the resource identifier
  • This class inherits from ClientObject, so it participates in the Office365 client object lifecycle including lazy loading and change tracking

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class TaxonomyItemCollection 74.6% similar

    TaxonomyItemCollection is a generic collection class for managing taxonomy items in Office 365, inheriting from ClientObjectCollection with type parameter T.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/taxonomy/item_collection.py
  • class Term 74.1% similar

    Represents a Term or Keyword in a managed metadata hierarchy within SharePoint's taxonomy system, providing access to term properties, labels, and hierarchical relationships.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/taxonomy/terms/term.py
  • class TaxonomyField 67.5% similar

    Represents a SharePoint taxonomy field that allows tagging content with terms from a managed metadata term set, supporting both single and multiple value selections.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/taxonomy/field.py
  • class TaxonomyMetadata 66.5% similar

    A client value class representing taxonomy metadata for SharePoint Publishing, specifically storing an anchor ID reference.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/taxonomy/metadata.py
  • class TaxonomyService 64.7% similar

    TaxonomyService is a client runtime context class that provides access to SharePoint taxonomy/term store functionality for a given site.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/taxonomy/service.py
← Back to Browse