class ExternalLink
A simple data class that represents a URL link to a OneNote page or notebook, inheriting from ClientValue.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/pages/external_link.py
4 - 14
simple
Purpose
This class encapsulates a URL (href) that points to a OneNote resource. It serves as a value object in the Office 365 SDK for representing external links to OneNote content. The class provides a simple wrapper around a URL string with a custom string representation.
Source Code
class ExternalLink(ClientValue):
"""Represents a URL that opens a OneNote page or notebook."""
def __init__(self, href=None):
"""
:param str href: The URL of the link.
"""
self.href = href
def __repr__(self):
return self.href
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
ClientValue | - |
Parameter Details
href: The URL string of the link pointing to a OneNote page or notebook. This parameter is optional and defaults to None if not provided. It should be a valid URL string when specified.
Return Value
Instantiation returns an ExternalLink object that wraps a URL. The __repr__ method returns the href string directly, making the object's string representation equal to its URL value.
Class Interface
Methods
__init__(self, href=None) -> None
Purpose: Constructor that initializes an ExternalLink instance with an optional URL
Parameters:
href: Optional string parameter representing the URL of the OneNote link. Defaults to None if not provided.
Returns: None (constructor)
__repr__(self) -> str
Purpose: Returns the string representation of the ExternalLink object, which is the href value itself
Returns: The href attribute value as a string. Returns 'None' if href is None.
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
href |
str or None | The URL string pointing to a OneNote page or notebook. Can be None if not set during initialization. | instance |
Dependencies
office365
Required Imports
from office365.runtime.client_value import ClientValue
Usage Example
from office365.runtime.client_value import ClientValue
class ExternalLink(ClientValue):
def __init__(self, href=None):
self.href = href
def __repr__(self):
return self.href
# Create an ExternalLink instance
link = ExternalLink(href='https://www.onenote.com/notebooks/12345')
# Access the href attribute
print(link.href) # Output: https://www.onenote.com/notebooks/12345
# String representation
print(link) # Output: https://www.onenote.com/notebooks/12345
print(repr(link)) # Output: https://www.onenote.com/notebooks/12345
# Create with no href
empty_link = ExternalLink()
print(empty_link.href) # Output: None
Best Practices
- This is a simple value object with minimal state. It should be instantiated with a valid URL string for the href parameter.
- The class inherits from ClientValue, which likely provides serialization/deserialization capabilities for the Office 365 SDK.
- The href attribute can be None, so consumers should handle this case when accessing the attribute.
- The __repr__ method returns the href directly, which means repr() on an instance with href=None will return 'None' as a string representation.
- This class is immutable by convention - the href should be set during initialization and not modified afterward.
- Use this class when working with OneNote API responses or requests that include external links to notebooks or pages.
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class PageLinks 82.0% similar
-
class RecentNotebookLinks 80.8% similar
-
class OnenotePagePreviewLinks 71.9% similar
-
class SocialLink 66.0% similar
-
class RecentNotebook 62.0% similar