🔍 Code Extractor

class DeltaCollection

Maturity: 38

A specialized collection class for handling delta queries in Microsoft Graph API, allowing retrieval of newly created, updated, or deleted entities (changes) with filtering capabilities.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/delta_collection.py
Lines:
14 - 39
Complexity:
moderate

Purpose

DeltaCollection extends EntityCollection to provide delta query functionality for Microsoft Graph API resources. It enables tracking changes (creates, updates, deletes) to entities over time by leveraging the delta query pattern. This class is particularly useful for synchronization scenarios where applications need to efficiently track changes to resources without fetching the entire dataset. It supports filtering changes by type (created, updated, deleted) and maintains a delta link for subsequent queries.

Source Code

class DeltaCollection(EntityCollection[T]):
    def __init__(self, context, item_type, resource_path=None, parent=None):
        # type: (GraphClient, Type[T], Optional[ResourcePath], Optional[Entity]) -> None
        super(DeltaCollection, self).__init__(context, item_type, resource_path, parent)

    def change_type(self, type_name):
        """
        Specifies a custom query option to filter the delta response based on the type of change.

        :param str type_name: Supported values are created, updated or deleted.
        """
        self.query_options.custom["changeType"] = type_name
        return self

    @property
    def delta(self):
        # type: () -> DeltaCollection[T]
        """
        Get newly created, updated, or deleted entities (changes)
        """
        return self.properties.get(
            "delta",
            DeltaCollection(
                self.context, self._item_type, DeltaPath(self.resource_path)
            ),
        )

Parameters

Name Type Default Kind
bases EntityCollection[T] -

Parameter Details

context: A GraphClient instance that provides the authentication context and HTTP client for making API requests to Microsoft Graph. This is required for all API operations.

item_type: A Type[T] representing the class type of items in the collection (e.g., User, Group). This generic type parameter determines what kind of entities the collection will contain and is used for type safety and deserialization.

resource_path: An optional ResourcePath object that specifies the API endpoint path for this collection. If None, the path may be derived from the parent or set later. This defines where the collection's data is located in the Graph API hierarchy.

parent: An optional Entity object representing the parent entity that owns this collection. Used for establishing hierarchical relationships in the Graph API object model and for constructing proper resource paths.

Return Value

Instantiation returns a DeltaCollection[T] object that can be used to query for changes to entities. The change_type() method returns self for method chaining. The delta property returns a new DeltaCollection instance configured with a DeltaPath for executing delta queries against the Microsoft Graph API.

Class Interface

Methods

__init__(self, context: GraphClient, item_type: Type[T], resource_path: Optional[ResourcePath] = None, parent: Optional[Entity] = None) -> None

Purpose: Initializes a new DeltaCollection instance with the specified context, item type, resource path, and parent entity

Parameters:

  • context: GraphClient instance for API communication
  • item_type: Type of entities in the collection (generic type T)
  • resource_path: Optional path to the API resource
  • parent: Optional parent entity in the object hierarchy

Returns: None - constructor initializes the instance

change_type(self, type_name: str) -> DeltaCollection[T]

Purpose: Filters the delta response based on the type of change by adding a custom query option

Parameters:

  • type_name: The type of change to filter for. Supported values are 'created', 'updated', or 'deleted'

Returns: Returns self to enable method chaining

@property delta(self) -> DeltaCollection[T] property

Purpose: Returns a DeltaCollection configured with a DeltaPath for retrieving newly created, updated, or deleted entities

Returns: A new DeltaCollection instance with DeltaPath configured for executing delta queries

Attributes

Name Type Description Scope
context GraphClient The Graph API client context inherited from EntityCollection, used for making API requests instance
_item_type Type[T] The type of items in the collection, inherited from EntityCollection, used for deserialization instance
resource_path Optional[ResourcePath] The API endpoint path for this collection, inherited from EntityCollection instance
query_options QueryOptions Query options object inherited from EntityCollection that stores custom query parameters like changeType filter instance
properties dict Dictionary storing cached properties including the delta collection instance, inherited from EntityCollection instance

Dependencies

  • typing
  • office365.delta_path
  • office365.entity
  • office365.entity_collection
  • office365.runtime.paths.resource_path
  • office365.graph_client

Required Imports

from office365.delta_collection import DeltaCollection
from office365.graph_client import GraphClient
from typing import Type

Usage Example

from office365.graph_client import GraphClient
from office365.delta_collection import DeltaCollection
from office365.directory.users.user import User

# Initialize Graph client with credentials
client = GraphClient.with_token(lambda: 'your_access_token')

# Create a delta collection for users
users_delta = DeltaCollection(client, User, resource_path=None, parent=None)

# Filter for only created users
users_delta.change_type('created')

# Execute delta query to get changes
changes = users_delta.delta.get().execute_query()

# Process the changes
for user in changes:
    print(f'Changed user: {user.display_name}')

# Alternative: Chain methods for filtering
deleted_users = DeltaCollection(client, User).change_type('deleted').delta.get().execute_query()

Best Practices

  • Always initialize with a valid GraphClient context that has appropriate authentication and permissions for the resource type being queried
  • Use the change_type() method to filter delta results by change type (created, updated, deleted) before executing queries to reduce payload size
  • The delta property creates a new DeltaCollection with DeltaPath, so access it when ready to execute the delta query
  • Delta queries maintain state through delta links - store and reuse delta tokens for subsequent queries to get only new changes
  • Method chaining is supported: use change_type() before accessing the delta property for cleaner code
  • The class is generic (DeltaCollection[T]) - always specify the correct item_type to ensure proper type safety and deserialization
  • Delta collections inherit from EntityCollection, so all EntityCollection methods and properties are available
  • For initial sync, use the delta property without filters; for subsequent syncs, use the delta link from previous responses

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class GroupCollection 70.5% similar

    A collection class for managing Microsoft Graph API Group resources, providing methods to create, retrieve, and manage groups including Microsoft 365 groups and Security groups.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/groups/collection.py
  • class UserCollection 68.5% similar

    UserCollection is a specialized collection class for managing User objects in Microsoft 365/Office 365 directory services, providing methods to retrieve, create, and manage users with delta query support.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/users/collection.py
  • class TodoTaskListCollection 68.2% similar

    A collection class for managing Microsoft To-Do task lists, providing methods to retrieve and create task list objects with delta query support.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/todo/tasks/list_collection.py
  • class ApplicationCollection 66.8% similar

    A collection class for managing Application objects in a directory, providing methods to retrieve and manage applications with delta query support.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/applications/collection.py
  • class DeltaPath 65.4% similar

    DeltaPath is a specialized path class that represents a 'delta' entity path in the Office365 SDK, inheriting from EntityPath.

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