Giacomo Chiarella
10/18/2024, 12:38 PMdef fcn(**kwargs)
. Is it possible?Nate
10/18/2024, 3:17 PMGiacomo Chiarella
10/18/2024, 3:19 PMGiacomo Chiarella
10/18/2024, 3:20 PMGiacomo Chiarella
10/18/2024, 3:20 PMNate
10/18/2024, 3:22 PM@flow
def f(data: dict[str, Any]):
Giacomo Chiarella
10/18/2024, 3:24 PMfrom typing import Any
?Nate
10/18/2024, 3:25 PMAny
isnt exactly true bc the values would need to be JSON serializable
I'd be inclined to do this
from pydantic import BaseModel
from prefect import flow
class Inputs(BaseModel):
a: int
b: str
c: bool
d: dict[str, str | dict[str, str]]
@flow
def something(data: Inputs):
print(data)
something({"a": 1, "b": "2", "c": True, "d": {"e": "f", "g": {"h": "i"}}})
because you'd be free to change the impl of Inputs
as needed, without changing the signature of your functions that use it, and then you get the nice formGiacomo Chiarella
10/18/2024, 3:28 PM{"a": {"b": {"c": 0, "d": 1}}}
Nate
10/18/2024, 3:31 PMfrom pydantic import BaseModel, Field
from prefect import flow
class Inputs(BaseModel):
a: int
b: str
c: bool
d: dict[str, str | dict[str, str]] = Field(default_factory=dict)
@flow
def something(data: Inputs):
print(data)
something({"a": 1, "b": "2", "c": True})
or if you want to allow arbitrary extras, you can
from pydantic import BaseModel
from prefect import flow
class Inputs(BaseModel, extra="allow"):
a: int
@flow
def something(data: Inputs):
print(data)
something({"a": 1, "b": "2", "c": True})
https://docs.pydantic.dev/latest/concepts/models/Giacomo Chiarella
10/18/2024, 3:32 PMNate
10/18/2024, 3:32 PMGiacomo Chiarella
10/18/2024, 3:33 PMNate
10/18/2024, 3:33 PM