Based on the usage data.set('database.username', 'Jack'), where data is clearly an object holding or representing the nested data structure itself, my preferred name from your list would be:
DotData
Here's why:
DotData:
- Clarity: This name directly communicates the core functionality: it's about Data that is accessed or manipulated using Dot notation.
- Usage Fit: The example
data.set(...) implies that data is the data structure (or an enhanced representation of it), and you're calling methods on this data object. DotData perfectly describes this role. It suggests an object that wraps or provides dot-notation access to underlying data.
- Common Pattern: Libraries like
dotmap and Box use similar naming conventions (DotMap, Box) for objects that provide attribute-style access to dictionaries. DotData aligns with this established pattern.
Let's look at the other options:
-
PathData:
- Pros: It's also a decent name, suggesting data that is structured or accessed via paths.
- Cons: It's slightly less specific than
DotData. "Path" could refer to various path types (like filesystem paths), whereas "Dot" specifically points to the dot notation convention used for nested data structures. DotData is more precise about the mechanism of access.
-
DotPath:
- Pros: Highlights the "dot path" aspect.
- Cons: This name is generally more suited for a class that represents a path string itself (e.g.,
my_path = DotPath('database.username')), rather than the data structure that the path operates on. If data were a DotPath object, the usage would likely be different, perhaps my_path.get(data_structure) or data_structure.get(my_path). The example data.set(...) implies data is the container for the data.
-
DotPathData:
- Pros: Combines both aspects.
- Cons: It feels a bit redundant.
DotData already implies that the data is handled via dot paths. Adding "Path" makes the name longer without adding significant new meaning.
Therefore, DotData is my strongest preference. It's concise, descriptive, and accurately reflects the apparent purpose of a class that enables data.set() operations using dot notation.
If the library were structured to have a separate component for managing path strings distinctly from the data itself, then a name like DotPath might be appropriate for that specific component, but not for the primary object holding the data.
For data = ???, you would instantiate your chosen class, likely passing in some initial data or having it manage its own internal state:
# Assuming your library is named z_dot_path_lib
from z_dot_path_lib import DotData
# Example 1: Initialize with existing data
initial_config = {
'database': {
'username': 'Jack',
'port': 5432
},
'api': {
'key': 'abc123'
}
}
data = DotData(initial_config)
# Example 2: Initialize an empty object and set values
# data = DotData()
# data.set('database.username', 'Jack')
# data.set('database.port', 5432)
# data.set('api.key', 'abc123')
# You could then access it like:
print(data.database.username) # Output: Jack
print(data.api.key) # Output: abc123
# Or modify it
data.set('database.port', 5433)
print(data.database.port) # Output: 5433