🔍 Code Extractor

class Extension

Maturity: 39

An abstract class representing an OData v4 open type extension (openTypeExtension), inheriting from Entity to support extensible data models.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/extensions/extension.py
Lines:
4 - 5
Complexity:
simple

Purpose

This class serves as a base type for implementing OData v4 open type extensions in Office 365 applications. It allows entities to be extended with additional properties dynamically without modifying the base schema. This is particularly useful for scenarios where custom data needs to be attached to Office 365 entities like users, groups, or events. The class inherits from Entity, providing the foundational OData entity capabilities while enabling the open type extension pattern.

Source Code

class Extension(Entity):
    """An abstract type to support the OData v4 open type openTypeExtension."""

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

__init__: The constructor parameters are inherited from the Entity base class. Typically includes context (ClientContext) for API communication and resource_path for identifying the entity in the OData service.

Return Value

Instantiation returns an Extension object that represents an OData v4 open type extension. Methods inherited from Entity will return various types depending on the operation (e.g., self for chainable operations, query results for data retrieval).

Class Interface

Methods

__init__(context: ClientContext, resource_path=None)

Purpose: Initializes an Extension instance, inherited from Entity base class

Parameters:

  • context: ClientContext object for API communication with Office 365 services
  • resource_path: Optional path to the resource in the OData service hierarchy

Returns: None (constructor)

Attributes

Name Type Description Scope
context ClientContext The client context used for API communication, inherited from Entity instance
resource_path ResourcePath The path to this resource in the OData service hierarchy, inherited from Entity instance
properties dict Dictionary containing the extension's properties and custom data, inherited from Entity instance

Dependencies

  • office365

Required Imports

from office365.entity import Entity
from office365.runtime.client_context import ClientContext

Usage Example

from office365.entity import Entity
from office365.runtime.client_context import ClientContext
from office365.extension import Extension

# Assuming you have a configured ClientContext
ctx = ClientContext.connect_with_credentials(site_url, username, password)

# Create an extension instance (typically done through entity methods)
extension = Extension(ctx)

# Extensions are usually accessed through parent entities
# For example, adding an extension to a user:
user = ctx.web.current_user
user.extensions.add({
    'extensionName': 'com.contoso.roamingSettings',
    'theme': 'dark',
    'language': 'en-US'
})
ctx.execute_query()

# Retrieve extensions
user_extensions = user.extensions.get().execute_query()
for ext in user_extensions:
    print(ext.properties)

Best Practices

  • This is an abstract base class and should typically not be instantiated directly; instead, use it as a parent class for specific extension types
  • Extensions are typically accessed through parent entities (users, groups, events) rather than created standalone
  • Always execute queries using ctx.execute_query() after modifying extensions to persist changes
  • Extension names should follow reverse domain notation (e.g., 'com.contoso.extensionName') to avoid conflicts
  • Be aware of extension size limits imposed by Office 365 (typically 2KB per extension)
  • Use appropriate permissions when accessing or modifying extensions on entities
  • Consider using schema extensions for strongly-typed scenarios and open extensions for dynamic data
  • Clean up unused extensions to avoid cluttering entity metadata

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class OpenTypeExtension 81.5% similar

    Represents an OpenType extension for Microsoft Graph resources, providing a way to add untyped properties to resources through open type data extensions.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/extensions/open_type.py
  • class SchemaExtension 69.9% similar

    SchemaExtension is a class representing Microsoft Graph schema extensions that allow adding strongly-typed custom data to resource types.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/extensions/schema.py
  • class ExtensionSchemaProperty 65.1% similar

    A data class representing a property definition within a Microsoft Graph API schema extension, containing a property name and its data type.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/extensions/schema_property.py
  • class MultiValueLegacyExtendedProperty 61.1% similar

    A class representing an extended property that contains a collection of string values, inheriting from Entity base class.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/extensions/extended_property.py
  • class ExtensionProperty 60.9% similar

    Represents a directory extension property that adds custom properties to Microsoft Graph directory objects (User, Group, Organization, Device, Application) without requiring an external data store.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/extensions/extension_property.py
← Back to Browse