class Notebook
Represents a OneNote notebook entity with access to its sections and section groups, providing a hierarchical structure for organizing OneNote content.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/notebooks/notebook.py
9 - 48
moderate
Purpose
The Notebook class models a OneNote notebook within the Microsoft Graph API hierarchy. It extends OnenoteEntityHierarchyModel to provide access to the notebook's sections and section groups through lazy-loaded entity collections. This class serves as a container for organizing OneNote content and enables navigation through the notebook's hierarchical structure. It is designed to work within the office365 SDK framework for interacting with Microsoft OneNote services.
Source Code
class Notebook(OnenoteEntityHierarchyModel):
"""A OneNote notebook."""
@property
def sections(self):
# type: () -> EntityCollection[OnenoteSection]
"""
Retrieve a list of onenoteSection objects from the specified notebook.
"""
return self.properties.get(
"sections",
EntityCollection(
self.context,
OnenoteSection,
ResourcePath("sections", self.resource_path),
),
)
@property
def section_groups(self):
"""
Retrieve a list of onenoteSection objects from the specified notebook.
"""
from office365.onenote.sectiongroups.section_group import SectionGroup
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 = {"sectionGroups": self.section_groups}
default_value = property_mapping.get(name, None)
return super(Notebook, self).get_property(name, default_value)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
OnenoteEntityHierarchyModel | - |
Parameter Details
context: The client context object required for making API calls to Microsoft Graph. Inherited from parent class and used to initialize entity collections.
resource_path: The resource path identifying this notebook in the API hierarchy. Inherited from parent class and used to construct paths for child resources like sections and section groups.
Return Value
Instantiation returns a Notebook object representing a OneNote notebook. The sections property returns an EntityCollection[OnenoteSection] containing all sections in the notebook. The section_groups property returns an EntityCollection[SectionGroup] containing all section groups. The get_property method returns the requested property value or the provided default_value if not found.
Class Interface
Methods
@property sections(self) -> EntityCollection[OnenoteSection]
property
Purpose: Retrieves a lazy-loaded collection of OnenoteSection objects from the notebook
Returns: EntityCollection[OnenoteSection] - A collection of sections contained in this notebook
@property section_groups(self) -> EntityCollection[SectionGroup]
property
Purpose: Retrieves a lazy-loaded collection of SectionGroup objects from the notebook
Returns: EntityCollection[SectionGroup] - A collection of section groups contained in this notebook
get_property(self, name: str, default_value=None) -> Any
Purpose: Retrieves a property value by name with support for custom default values and property mapping
Parameters:
name: The name of the property to retrieve (e.g., 'sectionGroups', 'sections')default_value: Optional default value to return if property is not found. If None, uses internal property mapping for special properties like 'sectionGroups'
Returns: The property value if found, otherwise the default_value or mapped default from property_mapping
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | The client context used for API communication, inherited from parent class | instance |
resource_path |
ResourcePath | The resource path identifying this notebook in the API hierarchy, inherited from parent class | instance |
properties |
dict | Internal dictionary storing cached property values including sections and section_groups collections, inherited from parent class | instance |
Dependencies
office365typing
Required Imports
from office365.onenote.notebooks.notebook import Notebook
from office365.entity_collection import EntityCollection
from office365.onenote.entity_hierarchy_model import OnenoteEntityHierarchyModel
from office365.onenote.sections.section import OnenoteSection
from office365.runtime.paths.resource_path import ResourcePath
Conditional/Optional Imports
These imports are only needed under specific conditions:
from office365.onenote.sectiongroups.section_group import SectionGroup
Condition: only when accessing the section_groups property
Required (conditional)Usage Example
from office365.graph_client import GraphClient
from office365.onenote.notebooks.notebook import Notebook
# Authenticate and create client context
client = GraphClient.with_token(lambda: 'your_access_token')
# Get a specific notebook
notebook = client.me.onenote.notebooks.get_by_id('notebook_id')
# Access sections in the notebook
sections = notebook.sections
for section in sections:
print(section.display_name)
# Access section groups
section_groups = notebook.section_groups
for group in section_groups:
print(group.display_name)
# Use get_property to retrieve properties
section_groups_alt = notebook.get_property('sectionGroups')
Best Practices
- The Notebook class uses lazy loading for sections and section_groups properties - they are only instantiated when first accessed
- Always ensure the context object is properly authenticated before accessing notebook properties
- The sections and section_groups properties return EntityCollection objects that may require additional API calls to load data
- Use get_property method when you need to access properties with custom default values or when working with dynamic property names
- The class inherits from OnenoteEntityHierarchyModel, so all parent class methods and properties are available
- Section groups are imported lazily within the section_groups property to avoid circular import issues
- Properties are cached in the internal properties dictionary after first access for performance
- When iterating over sections or section_groups, be aware that this may trigger API calls to Microsoft Graph
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class Onenote 83.5% similar
-
class SectionGroup 82.6% similar
-
class OnenoteEntityHierarchyModel 80.0% similar
-
class NotebookCollection 79.2% similar
-
class OnenoteEntityBaseModel 77.3% similar