Single Use

hivecore.decorator.single_use(seed: Any, key_param: str = 'key') Callable

A decorator that can be used to ensure that a function can only be called once with a specific key.

Parameters:
  • seed (Any) – A seed value used for generating unique keys.

  • key_param (str) – The name of the parameter that holds the key value.

Returns:

A decorator function that wraps the input function.

Return type:

Callable

Example

from hivecore.decorator import single_use
from hivecore.function import generate_key

unique_seed = 69

key = generate_key(seed=unique_seed)

@single_use(seed=unique_seed)
def fun(key=None):
    return "Hello World"

fun(key=key) #"Hello World"
fun(key=key) # ValueError

If your have a key paramater called something different from key, you can specify this using the unique_key parameter. Here is a small example of how to use it.

from hivecore.decorator import single_use
from hivecore.function import generate_key

@single_use(seed=unique_seed, key_param="my_key")
def fun(my_key=None):
    return "Hello World"