create_resource()
Create a new resource with the given name and kind.
Usage
create_resource(
name,
kind="default",
)Initializes a resource and registers it in the internal registry. Uses validate_input() to check the name and ResourceManager for lifecycle management.
This replaces the deprecated make_resource function.
Parameters
name: str-
The name of the resource. Must be non-empty and contain only alphanumeric characters and hyphens.
kind: str = "default"-
The type of resource to create. One of
"default","premium", or"ephemeral". Defaults to"default".
Returns
dict-
A dictionary with the following keys:
"name"— the resource name (str)."kind"— the resource kind (str)."id"— the assigned resource ID (int).
Raises
ValueError-
If
nameis empty orkindis not recognized.
Notes
Resources created with kind="ephemeral" are automatically garbage-collected after 24 hours. The cleanup runs on a background timer managed by ResourceManager.
The resource ID is assigned sequentially using an atomic counter, so IDs are guaranteed to be unique within a single process.
Examples
Create a default resource:
>>> res = create_resource("my-item")
>>> res["kind"]
'default'Create a premium resource:
>>> res = create_resource("premium-item", kind="premium")
>>> res["name"]
'premium-item'See Also
- ResourceManager: Manages resource lifecycle.
- validate_input(): Validates resource names.