1 year ago
#359982
AvitanD
DTO of Typed Tuples
TL;DR - I would like to create a typed tuple DTO. to avoid an x y question, the reason for that requirement is that I want to minimize data that I'm sending to save data (using a cellular modem), and so I don't want to send dictionary keys etc. I have a device id. for each device, I have a list of indicator samples, each each has a time and value. Eventually, the data sent should look like:
[<device_id:str>, [<indicator_id:str> , <value:str> , <time:float (epoch)> ... ] ...]
I want to create a DTO class to achieve this. What I currently have is this:
class SampleContent(TypedDict):
value: str
time: float
class OutgoingSampleDto(TypedDict):
indicator_id: str
sample: SampleContent
class OutgoingSamplesBatchDto(TypedDict):
device_id: str
samples: List[OutgoingSampleDto]
To which I thought of adding something like :
def __repr__():
return str(list(self.values()))
But this feels to me like excess work, that will hurt my performance in high data rates (i.e. creating a typed dict and converting it each time to my needed representation). Is there any way that I'm missing to achieve my goal ? Or am I on the right path?
python
dto
typeddict
0 Answers
Your Answer