🔍 Code Extractor

class Identity

Maturity: 48

The Identity class represents an identity of an actor (user, device, or application) in the Microsoft Office 365 API, storing display name and unique identifier information.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/permissions/identity.py
Lines:
4 - 21
Complexity:
simple

Purpose

This class serves as a data model for representing identity information in Office 365 contexts. It encapsulates the display name and unique identifier of an actor, providing a structured way to handle identity data when interacting with Office 365 services. The class inherits from ClientValue, making it compatible with the Office 365 SDK's serialization and API communication mechanisms.

Source Code

class Identity(ClientValue):
    """The Identity resource represents an identity of an actor. For example, an actor can be a user, device,
    or application."""

    def __init__(self, display_name=None, _id=None):
        """
        :param str display_name: The display name of the identity. Note that this might not always be available or up
            to date. For example, if a user changes their display name, the API might show the new value in a future
            response, but the items associated with the user won't show up as having changed when using delta.

        :param str _id: Unique identifier for the identity.
        """
        super(Identity, self).__init__()
        self.displayName = display_name
        self.id = _id

    def __repr__(self):
        return repr(self.to_json())

Parameters

Name Type Default Kind
bases ClientValue -

Parameter Details

display_name: Optional string parameter representing the display name of the identity. This value may not always be current as it can change over time (e.g., when a user updates their display name). The API may show updated values in future responses, but historical items won't retroactively reflect the change. Defaults to None if not provided.

_id: Optional string parameter representing the unique identifier for the identity. This is a stable, immutable identifier that uniquely identifies the actor across the system. Defaults to None if not provided.

Return Value

Instantiation returns an Identity object with displayName and id attributes set to the provided values (or None if not provided). The __repr__ method returns a JSON string representation of the object by calling to_json() (inherited from ClientValue).

Class Interface

Methods

__init__(self, display_name=None, _id=None)

Purpose: Initializes a new Identity instance with optional display name and unique identifier

Parameters:

  • display_name: Optional string for the display name of the identity
  • _id: Optional string for the unique identifier of the identity

Returns: None (constructor)

__repr__(self) -> str

Purpose: Returns a string representation of the Identity object in JSON format

Returns: String representation of the object's JSON serialization

Attributes

Name Type Description Scope
displayName str or None The display name of the identity. May not always be current or available. Can change over time without affecting historical references. instance
id str or None Unique identifier for the identity. Provides stable identification across the system. instance

Dependencies

  • office365

Required Imports

from office365.runtime.client_value import ClientValue

Usage Example

from office365.runtime.client_value import ClientValue
from office365.entity import Identity

# Create an identity with both display name and ID
user_identity = Identity(display_name='John Doe', _id='user-123-456')

# Create an identity with only display name
device_identity = Identity(display_name='Device-001')

# Create an empty identity
empty_identity = Identity()

# Access attributes
print(user_identity.displayName)  # Output: John Doe
print(user_identity.id)  # Output: user-123-456

# Get JSON representation
print(user_identity)  # Calls __repr__ which returns JSON representation

Best Practices

  • The display name may become stale over time as users update their profiles, so don't rely on it for critical identification - use the id field instead for stable references
  • Both parameters are optional, allowing flexible instantiation based on available data
  • The class uses snake_case for constructor parameters but camelCase for instance attributes to match Office 365 API conventions
  • This class is typically instantiated automatically by the Office 365 SDK when deserializing API responses rather than manually created
  • The id field provides stable identification across API calls and should be used for tracking and referencing identities
  • When using delta queries, be aware that display name changes won't trigger change notifications on associated items
  • The class inherits from ClientValue, which provides JSON serialization capabilities through the to_json() method

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class ObjectIdentity 77.3% similar

    Represents an identity used to sign in to a user account, encapsulating sign-in type, issuer, and issuer-assigned identifier information.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/identities/object_identity.py
  • class EmailIdentity 76.5% similar

    A class representing the email identity of a user, extending the base Identity class with email-specific attributes.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/permissions/email_identity.py
  • class IdentitySet 75.6% similar

    IdentitySet is a keyed collection class that represents a set of identity resources (application, device, user) associated with various events for an item, such as created by or last modified by actions.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/permissions/identity_set.py
  • class InsightIdentity 73.7% similar

    InsightIdentity is a data class that represents the identity properties of sharedInsight items in Microsoft Office 365 services.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/insights/identity.py
  • class Identity_v1 70.6% similar

    Identity is a client value class representing a Microsoft SharePoint Comments identity entity, inheriting from ClientValue base class.

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