Automatic DateTime Serialization Support in aiokafka #1064
Replies: 7 comments
-
|
Beta Was this translation helpful? Give feedback.
-
Should it be deprecated though ? The type annotations could be resolved with a type parameter on the consumer/producer class. On my own usage of aiokafka:
|
Beta Was this translation helpful? Give feedback.
-
This makes consumer and producer classes generic of 2 parameters, the types accepted by serializer/returned from deserializer for key and value. This doesn't look like a good design. But we need to find a better alternative first, so any ideas are welcome. |
Beta Was this translation helpful? Give feedback.
-
Yeah that could be a lot. In my company, we have built our own "kafka streams" based on aiokafka, and we do have things like this
It is also a bit similar in the java client (streams or regular)
In python, the type parameter is kind of verbose but on declaration only. On usage, we do have type checking without additional verbosity (the checker can "guess" the type according to the thing that are passed into the constructor for example) So we could have something like this
that would automatically infer the type of message.value from the deserializer method passed to the consumer constructor (but yeah, in the |
Beta Was this translation helpful? Give feedback.
-
Right now, when passing consumer (and similar for producer) around, you can declare it as |
Beta Was this translation helpful? Give feedback.
-
I guess then "wrapper" classes could be a solution ?
Not sure then what would be the benefit of having such class part of aiokafka directly |
Beta Was this translation helpful? Give feedback.
-
Right, it's one of the possible solution. Another one could be to make generic methods that accept (de)serializers instead of making generic whole class. As for me, I prefer to apply (de)serialization explicitly to each message: this way you it's clear how handle (de)serialization errors properly. |
Beta Was this translation helpful? Give feedback.
-
Describe the solution you’d like
I would like to request a feature that introduces automatic serialization and deserialization support for datetime objects in aiokafka. Currently, developers manually handle the conversion of datetime data to a string or timestamp format before sending it to Kafka. It would be great if aiokafka could natively support datetime objects by automatically serializing them into a standard format (e.g., ISO 8601 or timestamp) during message production, and deserializing them upon message consumption.
This feature would greatly reduce the manual overhead for handling date and time data, and also help ensure consistency in how datetime objects are represented across various Kafka topics and consumers.
Additional context
Other Python Kafka library examples:
The confluent-kafka-python library has a native support for date/time-based schemas when using Avro serialization.
The kafka-python library allows integration with custom serializers, which can be extended to support datetime objects, though it’s not automatic.
Thank you for considering this request, and please feel free to reach out if any further clarification or details are needed.
Beta Was this translation helpful? Give feedback.
All reactions