Alibaba Cloud Darabonba Map SDK
The `alibabacloud-darabonba-map` library provides the `Map` data structure for Python, which extends the built-in `dict` type with additional methods common in Alibaba Cloud's Darabonba SDK ecosystem. It is primarily used to represent request and response bodies, often generated by Darabonba's code generation tools. The current version is `0.0.1`, indicating it's in a very early development phase with potential for frequent updates.
Common errors
-
ModuleNotFoundError: No module named 'darabonba_map'
cause The package name for installation (`alibabacloud-darabonba-map`) does not directly match the top-level import path (`alibabacloud_darabonba_map`).fixEnsure your import statement uses the full path: `from alibabacloud_darabonba_map.map import Map`. -
AttributeError: 'dict' object has no attribute 'from_map'
cause You are attempting to call the `from_map` class method on a standard Python dictionary instance or a `dict` variable, instead of the `alibabacloud_darabonba_map.map.Map` class itself.fixCall `from_map` on the `Map` class directly: `my_map = Map.from_map(my_dict)`. -
TypeError: 'Map' object is not callable
cause This error can occur if you mistakenly try to 'call' a `Map` instance as if it were a function (e.g., `my_map()`) instead of accessing its contents (e.g., `my_map['key']`) or calling its methods.fixAccess `Map` objects using dictionary-like syntax (e.g., `my_map['key']`, `my_map.get('key')`) or call its specific methods (e.g., `my_map.to_map()`).
Warnings
- breaking As of version `0.0.1`, the library is in a very early stage. Future minor or patch versions may introduce breaking changes without strict adherence to semantic versioning until a stable `1.0.0` release. Always pin to an exact version or test thoroughly after updates.
- gotcha The `Map.from_map()` method performs a shallow copy of the input dictionary's contents. If your input dictionary contains nested dictionaries, these nested dictionaries will remain standard `dict` objects, not automatically converted to `Map` objects.
- gotcha While `Map` inherits from `dict`, it is primarily intended for use within the Darabonba ecosystem for type consistency and schema validation, often in auto-generated SDK code. For generic dictionary operations where no specific Darabonba-related behavior is needed, using a standard Python `dict` might be simpler and more performant.
Install
-
pip install alibabacloud-darabonba-map
Imports
- Map
from alibabacloud_darabonba_map.map import Map
Quickstart
from alibabacloud_darabonba_map.map import Map
# Create a Map object, similar to a dictionary
my_map = Map({
'serviceName': 'ecs',
'action': 'DescribeInstances',
'parameters': {
'RegionId': 'cn-hangzhou',
'InstanceIds': ['i-bp1abcdefg123456789'],
}
})
print(f"Created Map: {my_map}")
print(f"Accessing 'serviceName': {my_map.get('serviceName')}")
# Convert a standard dictionary to a Map object
another_dict = {'status': 'success', 'code': 200}
new_map = Map.from_map(another_dict)
print(f"Map from dict: {new_map}")
# Map objects behave like dictionaries
my_map['new_key'] = 'new_value'
print(f"Map after modification: {my_map}")