class WebInformationCollection
A collection class that manages WebInformation objects containing metadata about SharePoint sites, providing methods to retrieve and manage site information.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/webs/information_collection.py
6 - 22
simple
Purpose
WebInformationCollection serves as a container and manager for WebInformation objects in SharePoint. It extends EntityCollection to provide specialized functionality for working with collections of site metadata. The primary use case is to retrieve information about SharePoint sites by their identifiers, enabling programmatic access to site properties and metadata within the Office365 SharePoint API.
Source Code
class WebInformationCollection(EntityCollection):
"""Specifies a collection of objects containing metadata about a site"""
def __init__(self, context, resource_path=None):
super(WebInformationCollection, self).__init__(
context, WebInformation, resource_path
)
def get_by_id(self, _id):
"""Returns an SP.WebInformation (section 3.2.5.192) object that contains metadata about a site (2) specified
by the identifier of the site
:param str _id: Specifies the identifier of site
"""
return WebInformation(
self.context, ServiceOperationPath("GetById", [_id], self.resource_path)
)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
EntityCollection | - |
Parameter Details
context: The client context object that provides the connection and authentication information for SharePoint operations. This is required for all API calls and maintains the session state.
resource_path: Optional parameter specifying the resource path (URL path) to the collection endpoint in SharePoint. If None, a default path will be used. This allows for custom endpoint targeting when needed.
Return Value
Instantiation returns a WebInformationCollection object that can be used to access and manage WebInformation objects. The get_by_id method returns a WebInformation object representing a specific site identified by the provided ID.
Class Interface
Methods
__init__(self, context, resource_path=None)
Purpose: Initializes a new WebInformationCollection instance with the provided context and optional resource path
Parameters:
context: The client context object for SharePoint operationsresource_path: Optional resource path to the collection endpoint (defaults to None)
Returns: None (constructor)
get_by_id(self, _id: str) -> WebInformation
Purpose: Retrieves a WebInformation object containing metadata about a specific SharePoint site identified by its ID
Parameters:
_id: String identifier (GUID) of the SharePoint site to retrieve information for
Returns: WebInformation object containing metadata about the specified site. The object needs to be loaded via context.load() and context.execute_query() to populate its properties.
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | The SharePoint client context inherited from EntityCollection, used for all API operations | instance |
resource_path |
ResourcePath or None | The resource path to the collection endpoint, inherited from EntityCollection | instance |
Dependencies
office365.runtime.paths.service_operationoffice365.sharepoint.entity_collectionoffice365.sharepoint.webs.information
Required Imports
from office365.runtime.paths.service_operation import ServiceOperationPath
from office365.sharepoint.entity_collection import EntityCollection
from office365.sharepoint.webs.information import WebInformation
Usage Example
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.webs.information_collection import WebInformationCollection
# Authenticate and create context
ctx = ClientContext('https://yourtenant.sharepoint.com/sites/yoursite').with_credentials(credentials)
# Create a WebInformationCollection instance
web_info_collection = WebInformationCollection(ctx)
# Get information about a specific site by ID
site_id = 'your-site-guid-here'
web_info = web_info_collection.get_by_id(site_id)
# Load and execute the query to retrieve data
ctx.load(web_info)
ctx.execute_query()
# Access site information
print(web_info.properties)
Best Practices
- Always ensure the context object is properly authenticated before creating a WebInformationCollection instance
- Use get_by_id() to retrieve specific site information rather than iterating through the entire collection when possible
- Remember to call ctx.load() and ctx.execute_query() after retrieving WebInformation objects to actually fetch the data from SharePoint
- Handle exceptions for invalid site IDs or permission issues when calling get_by_id()
- The collection inherits from EntityCollection, so standard collection operations (iteration, filtering) are available
- Reuse the same context object for multiple operations to maintain session efficiency
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class WebInformation 82.3% similar
-
class WebCollection 77.9% similar
-
class SitePageMetadataCollection 73.2% similar
-
class WebPartDefinitionCollection 69.2% similar
-
class SitePropertiesCollection 68.0% similar