class SectionGroup
Represents a section group in a OneNote notebook that can contain both sections and nested section groups, providing hierarchical organization of OneNote content.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/sectiongroups/section_group.py
10 - 69
moderate
Purpose
The SectionGroup class models a OneNote section group entity, which is a container for organizing OneNote sections and other section groups in a hierarchical structure. It extends OnenoteEntityHierarchyModel to provide access to parent notebooks, child sections, and nested section groups through navigation properties. This class is part of the Microsoft Graph API integration for OneNote and enables traversal and management of the OneNote notebook hierarchy.
Source Code
class SectionGroup(OnenoteEntityHierarchyModel):
"""A section group in a OneNote notebook. Section groups can contain sections and section groups."""
@property
def section_groups_url(self):
# type: () -> Optional[str]
"""
The URL for the sectionGroups navigation property, which returns all the section groups in the section group.
"""
return self.properties.get("sectionGroupsUrl", None)
@property
def sections_url(self):
# type: () -> Optional[str]
"""The URL for the sections navigation property, which returns all the sections in the section group."""
return self.properties.get("sectionsUrl", None)
@property
def parent_notebook(self):
# type: () -> Notebook
"""The notebook that contains the section group. Read-only."""
return self.properties.get(
"parentNotebook",
Notebook(self.context, ResourcePath("parentNotebook", self.resource_path)),
)
@property
def sections(self):
# type: () -> EntityCollection[OnenoteSection]
"""The sections in the section group. Read-only. Nullable."""
return self.properties.get(
"sections",
EntityCollection(
self.context,
OnenoteSection,
ResourcePath("sections", self.resource_path),
),
)
@property
def section_groups(self):
# type: () -> EntityCollection[SectionGroup]
"""Retrieve a list of onenoteSection objects from the specified notebook."""
return self.properties.get(
"sectionGroups",
EntityCollection(
self.context,
SectionGroup,
ResourcePath("sectionGroups", self.resource_path),
),
)
def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"parentNotebook": self.parent_notebook,
"sectionGroups": self.section_groups,
}
default_value = property_mapping.get(name, None)
return super(SectionGroup, self).get_property(name, default_value)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
OnenoteEntityHierarchyModel | - |
Parameter Details
context: The client context object used for making API requests to Microsoft Graph. This is inherited from the base class and required for all API operations.
resource_path: The ResourcePath object representing the API endpoint path for this section group entity. Used to construct URLs for navigation properties and API calls.
Return Value
Instantiation returns a SectionGroup object that represents a OneNote section group entity. The object provides access to navigation properties (parent_notebook, sections, section_groups) and URLs for related resources. Properties return either primitive types (strings for URLs), Notebook objects, or EntityCollection objects containing OnenoteSection or SectionGroup items.
Class Interface
Methods
section_groups_url() -> Optional[str]
property
Purpose: Returns the URL for the sectionGroups navigation property to access all section groups within this section group
Returns: Optional string containing the URL for the sectionGroups navigation property, or None if not available
sections_url() -> Optional[str]
property
Purpose: Returns the URL for the sections navigation property to access all sections within this section group
Returns: Optional string containing the URL for the sections navigation property, or None if not available
parent_notebook() -> Notebook
property
Purpose: Provides access to the parent notebook that contains this section group (read-only)
Returns: Notebook object representing the parent notebook containing this section group
sections() -> EntityCollection[OnenoteSection]
property
Purpose: Returns a collection of all sections contained within this section group (read-only, nullable)
Returns: EntityCollection of OnenoteSection objects representing all sections in this section group
section_groups() -> EntityCollection[SectionGroup]
property
Purpose: Returns a collection of nested section groups contained within this section group
Returns: EntityCollection of SectionGroup objects representing all nested section groups
get_property(name: str, default_value=None) -> Any
Purpose: Retrieves a property value by name with optional default value, providing special handling for navigation properties
Parameters:
name: The name of the property to retrieve (e.g., 'parentNotebook', 'sectionGroups')default_value: Optional default value to return if property is not found. If None, uses internal property mapping for navigation properties
Returns: The property value if found, otherwise the default_value or mapped navigation property object
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | The client context used for API operations, inherited from base class | instance |
resource_path |
ResourcePath | The resource path representing the API endpoint for this section group entity, inherited from base class | instance |
properties |
dict | Dictionary storing the entity properties retrieved from the API, inherited from base class | instance |
Dependencies
office365typing
Required Imports
from office365.onenote.entity_hierarchy_model import OnenoteEntityHierarchyModel
from office365.entity_collection import EntityCollection
from office365.onenote.notebooks.notebook import Notebook
from office365.onenote.sections.section import OnenoteSection
from office365.runtime.paths.resource_path import ResourcePath
from typing import Optional
Usage Example
from office365.graph_client import GraphClient
from office365.onenote.section_groups.section_group import SectionGroup
# Authenticate and create client context
client = GraphClient(lambda: ('your_access_token',))
# Get a specific section group by ID
section_group = client.me.onenote.section_groups.get_by_id('section_group_id')
section_group.get().execute_query()
# Access properties
print(f"Section Groups URL: {section_group.section_groups_url}")
print(f"Sections URL: {section_group.sections_url}")
# Access parent notebook
parent = section_group.parent_notebook
parent.get().execute_query()
print(f"Parent Notebook: {parent.display_name}")
# Get all sections in this section group
sections = section_group.sections
sections.get().execute_query()
for section in sections:
print(f"Section: {section.display_name}")
# Get nested section groups
nested_groups = section_group.section_groups
nested_groups.get().execute_query()
for group in nested_groups:
print(f"Nested Group: {group.display_name}")
Best Practices
- Always call execute_query() after get() operations to fetch data from the API
- Use lazy loading pattern - navigation properties are only loaded when accessed and queried
- Cache the client context to avoid repeated authentication
- Handle API rate limits and implement retry logic for production use
- Check for None values when accessing optional properties like section_groups_url and sections_url
- Use the get_property() method for dynamic property access with default values
- Be aware that parent_notebook, sections, and section_groups are read-only properties
- The sections property is nullable, so check for empty collections before iteration
- Section groups can be nested, so implement recursive traversal carefully to avoid infinite loops
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class Notebook 82.6% similar
-
class OnenoteSection 70.5% similar
-
class OnenoteEntityHierarchyModel 70.0% similar
-
class Onenote 67.6% similar
-
class OnenoteEntityBaseModel 63.9% similar