How to pass a single dynamic (dict) parameter to an activity

Hi there,

following the activity parameters documentation that states:

Activity parameters are the function parameters of the function decorated with @activity.defn. These can be any data type Temporal can convert, including dataclasses when properly type-annotated. Technically this can be multiple parameters, but Temporal strongly encourages a single dataclass parameter containing all input fields.

I will have hundreds of activities called from dozen for different workflows. I don’t want to define a specific parameter class for each individual activity like in the python-sdk examples:

@dataclass
class ComposeGreetingInput:
greeting: str
name: str

@activity.defn
def compose_greeting(input: ComposeGreetingInput) → str:
activity.logger.info(“Running activity with parameter %s” % input)
return f"{input.greeting}, {input.name}!"

I would like to use a generic unique parameter that would be used by all activities. I wanted to use a simple dict() but my custom dataclass that would be passed as values are deserialized to dict() themselve and I’m loosing the whole class in the workflow to activity serialization process (same on for the return value). The (de)serialization rely on the activity signature to make the conversion. If @dataclass object are inside a dynamic structure, it’s not converted back to the original class and remains a dict.

how could I do achieve such a thing (if possible) ?

what would be the curlpit of using multiple parameters ?

Thanks a lot

Could consider passing this param to activities when you register with worker, for example see https://github.com/temporalio/samples-python/blob/main/hello/hello_activity_method.py

Thank for the idea but it would make the code more complex.

I’d rather go into the way of making my own data converter