Skip to content

utils ¤

gen_id ¤

gen_id(length: int = 5) -> str

Generate a unique ID that can be associated with a Node

Source code in src/django_components/utils.py
def gen_id(length: int = 5) -> str:
    """Generate a unique ID that can be associated with a Node"""
    # Global counter to avoid conflicts
    global _id
    _id += 1

    # Pad the ID with `0`s up to 4 digits, e.g. `0007`
    return f"{_id:04}"