class EntityPath
EntityPath is a specialized ResourcePath subclass that represents a path for addressing a single entity using a key, formatting the path segment with appropriate syntax based on the key type.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/paths/v3/entity.py
4 - 17
simple
Purpose
EntityPath provides a way to construct and represent paths to individual entities in a resource hierarchy, typically used in REST API or OData-style URL construction. It handles different key types (integer, string, or None) and formats them appropriately with parentheses notation. The class is designed to work within the Office365 SDK's path resolution system for accessing specific entities by their unique identifiers.
Source Code
class EntityPath(ResourcePath):
"""Path for addressing a single entity by key"""
@property
def segment(self):
if self._key is None:
return "(<key>)"
elif isinstance(self._key, int):
return "({0})".format(self._key)
return "('{0}')".format(self._key)
@property
def delimiter(self):
return None
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
ResourcePath | - |
Parameter Details
__init__: Inherits constructor from ResourcePath base class. The exact parameters depend on the parent class implementation, but typically includes a key parameter (_key) that identifies the specific entity being addressed.
Return Value
Instantiation returns an EntityPath object that can generate formatted path segments. The segment property returns a string representation of the entity key in parentheses format: '(<key>)' for None, '(123)' for integers, or '('value')' for strings. The delimiter property returns None, indicating no delimiter is used after this path segment.
Class Interface
Methods
@property segment(self) -> str
property
Purpose: Returns a formatted string representation of the entity key enclosed in parentheses, with appropriate formatting based on key type
Returns: A string in the format '(<key>)' if _key is None, '(123)' if _key is an integer, or '('value')' if _key is a string
@property delimiter(self) -> None
property
Purpose: Returns the delimiter used after this path segment, which is None for EntityPath indicating no delimiter is needed
Returns: None, indicating no delimiter is used after this path segment
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
_key |
int | str | None | The key identifier for the entity. Can be an integer for numeric IDs, a string for named entities, or None for placeholder representation. Inherited from parent class. | instance |
Dependencies
office365
Required Imports
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.paths.entity_path import EntityPath
Usage Example
from office365.runtime.paths.entity_path import EntityPath
from office365.runtime.paths.resource_path import ResourcePath
# Create an EntityPath with an integer key
entity_path_int = EntityPath()
entity_path_int._key = 123
print(entity_path_int.segment) # Output: (123)
# Create an EntityPath with a string key
entity_path_str = EntityPath()
entity_path_str._key = 'user123'
print(entity_path_str.segment) # Output: ('user123')
# Create an EntityPath with no key
entity_path_none = EntityPath()
entity_path_none._key = None
print(entity_path_none.segment) # Output: (<key>)
# Check delimiter
print(entity_path_int.delimiter) # Output: None
Best Practices
- EntityPath is designed to be used as part of a larger path construction system, typically chained with other ResourcePath objects
- The _key attribute should be set after instantiation or passed through the parent class constructor
- Use integer keys for numeric entity identifiers and string keys for named entities
- The segment property is read-only and automatically formats the key appropriately
- This class is typically not instantiated directly by end users but rather created internally by the Office365 SDK when building entity references
- The delimiter property returning None indicates this is a terminal path segment or uses a different concatenation strategy than typical path delimiters
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class EntityPath_v1 88.2% similar
-
class ItemPath 76.4% similar
-
class MePath 67.9% similar
-
class DeltaPath 65.9% similar
-
class WebPath 65.1% similar