class Onenote
The Onenote class serves as the entry point for accessing Microsoft OneNote resources through the Microsoft Graph API, providing access to notebooks, pages, sections, and other OneNote entities.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/onenote.py
12 - 90
moderate
Purpose
This class acts as a facade for interacting with OneNote resources in Microsoft 365. It inherits from Entity and provides property-based access to various OneNote collections including notebooks, pages, sections, section groups, operations, and resources. The class uses lazy initialization for its collections, creating them only when accessed. It's designed to work within the Office365 SDK framework and manages the resource paths and context for API calls.
Source Code
class Onenote(Entity):
"""The entry point for OneNote resources."""
@property
def notebooks(self):
# type: () -> NotebookCollection
"""Retrieve a list of notebook objects."""
return self.properties.get(
"notebooks",
NotebookCollection(
self.context, ResourcePath("notebooks", self.resource_path)
),
)
@property
def operations(self):
"""Retrieve a list of OneNote operations."""
return self.properties.get(
"operations",
EntityCollection(
self.context,
OnenoteOperation,
ResourcePath("operations", self.resource_path),
),
)
@property
def pages(self):
# type: () -> OnenotePageCollection
"""Retrieve a list of page objects."""
return self.properties.get(
"pages",
OnenotePageCollection(
self.context, ResourcePath("pages", self.resource_path)
),
)
@property
def resources(self):
"""Retrieve a list of Resources objects from the specified notebook."""
return self.properties.get(
"resources",
EntityCollection(
self.context,
OnenoteResource,
ResourcePath("resources", self.resource_path),
),
)
@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."""
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(Onenote, self).get_property(name, default_value)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
context: The API context object that manages authentication, HTTP requests, and connection to Microsoft Graph API. Inherited from Entity base class.
resource_path: The ResourcePath object that defines the API endpoint path for this OneNote instance. Inherited from Entity base class.
Return Value
Instantiation returns a Onenote object that provides access to OneNote resources. The class properties return various collection types: NotebookCollection for notebooks, OnenotePageCollection for pages, and EntityCollection instances for operations, resources, sections, and section groups. The get_property method returns the requested property value or a default value if not found.
Class Interface
Methods
@property notebooks() -> NotebookCollection
property
Purpose: Provides access to the collection of OneNote notebooks
Returns: NotebookCollection object containing all notebooks accessible to the authenticated user
@property operations() -> EntityCollection[OnenoteOperation]
property
Purpose: Provides access to the collection of OneNote operations
Returns: EntityCollection of OnenoteOperation objects representing OneNote API operations
@property pages() -> OnenotePageCollection
property
Purpose: Provides access to the collection of OneNote pages
Returns: OnenotePageCollection object containing all pages across all notebooks
@property resources() -> EntityCollection[OnenoteResource]
property
Purpose: Provides access to the collection of OneNote resources (attachments, images, etc.)
Returns: EntityCollection of OnenoteResource objects representing resources from notebooks
@property sections() -> EntityCollection[OnenoteSection]
property
Purpose: Provides access to the collection of OneNote sections
Returns: EntityCollection of OnenoteSection objects representing sections from notebooks
@property section_groups() -> EntityCollection[SectionGroup]
property
Purpose: Provides access to the collection of OneNote section groups
Returns: EntityCollection of SectionGroup objects representing section groups from notebooks
get_property(name: str, default_value=None) -> Any
Purpose: Retrieves a property value by name with optional default value, with special handling for sectionGroups mapping
Parameters:
name: The name of the property to retrievedefault_value: Optional default value to return if property is not found. If None, checks property_mapping for special cases
Returns: The property value if found, otherwise the default_value or mapped property from property_mapping
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | The API context object inherited from Entity that manages authentication and HTTP requests to Microsoft Graph API | instance |
resource_path |
ResourcePath | The resource path object inherited from Entity that defines the API endpoint path for this OneNote instance | instance |
properties |
dict | Dictionary inherited from Entity that stores cached property values including lazy-initialized collections | instance |
Dependencies
office365
Required Imports
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.onenote.notebooks.collection import NotebookCollection
from office365.onenote.operations.onenote import OnenoteOperation
from office365.onenote.pages.collection import OnenotePageCollection
from office365.onenote.resources.resource import OnenoteResource
from office365.onenote.sectiongroups.section_group import SectionGroup
from office365.onenote.sections.section import OnenoteSection
from office365.runtime.paths.resource_path import ResourcePath
Usage Example
from office365.graph_client import GraphClient
from office365.onenote.onenote import Onenote
# Initialize Graph client with credentials
client = GraphClient.with_client_secret(tenant_id, client_id, client_secret)
# Access OneNote through the client
onenote = client.me.onenote
# Access notebooks collection
notebooks = onenote.notebooks
for notebook in notebooks:
print(notebook.display_name)
# Access pages collection
pages = onenote.pages
for page in pages:
print(page.title)
# Access sections
sections = onenote.sections
for section in sections:
print(section.display_name)
# Access section groups
section_groups = onenote.section_groups
for group in section_groups:
print(group.display_name)
Best Practices
- Always ensure the parent context object is properly authenticated before accessing OneNote resources
- Collections are lazily initialized - they are created only when first accessed, which optimizes performance
- Use the property accessors (notebooks, pages, sections, etc.) rather than directly accessing the properties dictionary
- The class maintains state through the inherited properties dictionary from Entity base class
- When extending functionality, override get_property to add custom property mappings as demonstrated with sectionGroups
- All collections share the same context, ensuring consistent authentication and API access across resources
- Resource paths are automatically constructed relative to the parent OneNote resource path
- The class follows the repository pattern, providing collection-based access to different OneNote entity types
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class Notebook 83.5% similar
-
class OnenoteEntityBaseModel 76.8% similar
-
class OnenotePageCollection 75.8% similar
-
class NotebookCollection 73.5% similar
-
class OnenoteEntityHierarchyModel 71.4% similar