This is an automated email from the ASF dual-hosted git repository. bossenti pushed a commit to branch chore/introduce-function-definition in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 1043b393326a23637c6aee62edc7532bc3154c5a Author: bossenti <[email protected]> AuthorDate: Sun Jan 22 15:41:39 2023 +0100 extend resource definition by dict conversion method Signed-off-by: bossenti <[email protected]> --- .../streampipes_client/model/resource/resource.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/streampipes-client-python/streampipes_client/model/resource/resource.py b/streampipes-client-python/streampipes_client/model/resource/resource.py index 5cb2d354d..1fcf7d2b6 100644 --- a/streampipes-client-python/streampipes_client/model/resource/resource.py +++ b/streampipes-client-python/streampipes_client/model/resource/resource.py @@ -31,6 +31,7 @@ __all__ = [ class Resource(ABC, BasicModel): """General and abstract implementation for a resource. + A resource defines the data model used by a resource container (`model.container.resourceContainer`). It inherits from Pydantic's BaseModel to get all its superpowers, which are used to parse, validate the API response and to easily switch between @@ -41,3 +42,20 @@ class Resource(ABC, BasicModel): def convert_to_pandas_representation(self) -> Dict: """Returns a dictionary representation to be used when creating a pandas Dataframe.""" raise NotImplementedError # pragma: no cover + + def to_dict(self, use_source_names=True): + """Returns the resource in dictionary representation. + + Parameters + ---------- + use_source_names: bool + Indicates if the dictionary keys are in python representation or + equally named to the StreamPipes backend + + Returns + ------ + resource: Dict[str, Any] + The resource as dictionary representation + + """ + return self.dict(by_alias=use_source_names)
