🔍 Code Extractor

class OfficeGraphInsights

Maturity: 51

A class representing Office Graph Insights that provides access to calculated relationships for documents shared, trending, or used by a user through advanced analytics and machine learning.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/insights/office_graph.py
Lines:
9 - 58
Complexity:
moderate

Purpose

OfficeGraphInsights serves as an entity wrapper for accessing Microsoft Graph insights data. It provides three main types of insights: shared documents (files shared with or by the user), trending documents (content popular within the user's network), and used documents (recently viewed or modified files). This class is part of the Microsoft Graph API integration and enables applications to discover and surface relevant content to users based on their activity and network.

Source Code

class OfficeGraphInsights(Entity):
    """
    Insights are relationships calculated using advanced analytics and machine learning techniques.
    You can, for example, identify OneDrive for Business documents trending around users.
    """

    @property
    def shared(self):
        # type: () -> EntityCollection[SharedInsight]
        """
        Calculated relationship identifying documents shared with or by the user. This includes URLs, file attachments,
        and reference attachments to OneDrive for Business and SharePoint files found in Outlook messages and meetings.
        This also includes URLs and reference attachments to Teams conversations. Ordered by recency of share.
        """
        return self.properties.get(
            "shared",
            EntityCollection(
                self.context, SharedInsight, ResourcePath("shared", self.resource_path)
            ),
        )

    @property
    def trending(self):
        # type: () -> EntityCollection[Trending]
        """
        Calculated relationship identifying documents trending around a user.
        Trending documents are calculated based on activity of the user's closest network of people and include
        files stored in OneDrive for Business and SharePoint. Trending insights help the user to discover
        potentially useful content that the user has access to, but has never viewed before.
        """
        return self.properties.get(
            "trending",
            EntityCollection(
                self.context, Trending, ResourcePath("trending", self.resource_path)
            ),
        )

    @property
    def used(self):
        # type: () -> EntityCollection[UsedInsight]
        """
        Calculated relationship identifying the latest documents viewed or modified by a user,
        including OneDrive for Business and SharePoint documents, ranked by recency of use.
        """
        return self.properties.get(
            "used",
            EntityCollection(
                self.context, UsedInsight, ResourcePath("used", self.resource_path)
            ),
        )

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

Entity_base_class: Inherits from Entity base class which provides core functionality for Microsoft Graph entities including context management, resource paths, and property handling. The constructor parameters are inherited from Entity and typically include context (API client context) and resource_path (the API endpoint path for this entity).

Return Value

Instantiation returns an OfficeGraphInsights object that provides access to three property collections: 'shared' returns EntityCollection[SharedInsight] containing shared document insights, 'trending' returns EntityCollection[Trending] with trending document insights, and 'used' returns EntityCollection[UsedInsight] with recently used document insights. Each property is lazily loaded and cached in the properties dictionary.

Class Interface

Methods

@property shared(self) -> EntityCollection[SharedInsight] property

Purpose: Provides access to documents shared with or by the user, including URLs, file attachments, and references from Outlook and Teams

Returns: EntityCollection[SharedInsight] containing shared document insights ordered by recency of share

@property trending(self) -> EntityCollection[Trending] property

Purpose: Provides access to documents trending around the user based on their network's activity

Returns: EntityCollection[Trending] containing trending documents from OneDrive and SharePoint that the user has access to but may not have viewed

@property used(self) -> EntityCollection[UsedInsight] property

Purpose: Provides access to the latest documents viewed or modified by the user

Returns: EntityCollection[UsedInsight] containing recently used documents from OneDrive and SharePoint, ranked by recency of use

Attributes

Name Type Description Scope
context ClientContext Inherited from Entity - stores the API client context used for making requests to Microsoft Graph instance
resource_path ResourcePath Inherited from Entity - stores the API endpoint path for this insights entity instance
properties dict Inherited from Entity - dictionary that caches loaded properties including the EntityCollection objects for shared, trending, and used insights instance

Dependencies

  • office365

Required Imports

from office365.directory.insights.shared import SharedInsight
from office365.directory.insights.trending import Trending
from office365.directory.insights.used import UsedInsight
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.runtime.paths.resource_path import ResourcePath

Usage Example

# Assuming you have a configured Microsoft Graph context
from office365.graph_client import GraphClient
from office365.directory.insights.insights import OfficeGraphInsights

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

# Get insights for current user
insights = client.me.insights

# Access shared documents
shared_docs = insights.shared
for shared in shared_docs:
    print(f"Shared: {shared.resource_reference.web_url}")

# Access trending documents
trending_docs = insights.trending
for trend in trending_docs:
    print(f"Trending: {trend.resource_reference.web_url}")

# Access recently used documents
used_docs = insights.used
for used in used_docs:
    print(f"Used: {used.resource_reference.web_url}")

# Execute query to load data
client.execute_query()

Best Practices

  • Always ensure proper authentication and API permissions are configured before accessing insights
  • Properties are lazily loaded - they create EntityCollection objects on first access and cache them
  • Use execute_query() on the context to actually fetch data from the API after accessing properties
  • The insights data is calculated by Microsoft Graph and may not be immediately available for new users or accounts
  • Each property returns an EntityCollection which can be iterated or filtered using OData query parameters
  • Consider the privacy implications when accessing user insights - ensure compliance with organizational policies
  • The class maintains state through the inherited properties dictionary - avoid direct manipulation
  • Resource paths are automatically constructed relative to the parent entity's path

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class UsedInsight 79.3% similar

    A class representing insights about documents used by a specific user, tracking the most relevant documents viewed or modified in OneDrive for Business and SharePoint.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/insights/used.py
  • class SharedInsight 76.2% similar

    A class representing insights about files shared with or by a specific user in Microsoft 365, including email attachments, OneDrive for Business, and SharePoint files.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/insights/shared.py
  • class Trending 70.7% similar

    A class representing a rich relationship between a user and documents that are trending around them, specifically for OneDrive and SharePoint files.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/insights/trending.py
  • class InsightIdentity 68.8% 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 TopFilesSharingInsights 65.2% similar

    A SharePoint entity class representing insights about the most shared files in a tenant, providing access to file sharing analytics data.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/tenant/administration/insights/top_files_sharing.py
← Back to Browse