Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Conversation

@becurrie
Copy link

Added the ability to just coerce datetime objects directly into their __str__ output when being sent down the pipe through a web-socket.

The main use case for this (at least for my current usage of Eel) is as follows:

  • I'm using different models to store sets of data that flow between the frontend and backend.
  • One of the main pieces of functionality for my application is allowing real-time updates and the inclusion of counters and stopwatches (that start from, or countdown to) a datetime object.
  • Returning a dictionary that contains raw datetime objects currently just coerces them to a None type value or null when viewed in the JavaScript itself.

Now, I could just coerce my datetime objects into strings directly before sending them down the pipe to be sent through a web-socket, but this would then mean that I need to convert them back to datetime objects when I'm dealing with them back in Python.

I think it's more worthwhile to just convert datetimes into strings by default when they're encountered by the jsn.dumps functionality within Eel.

@samuelhwilliams
Copy link
Collaborator

Hi @becurrie,

Thanks for the PR - glad you're using Eel and want to contribute to its development. 🎉

I think it's a fair idea to allow more data types to be serialized. That said, I think we might want to consider the more general case for users transferring data/objects between the Python and JS sides. With that in mind, I think we might want to consider letting Eel take in custom JSONEncoder/Decoders, which are used instead of the default, so that developers can pass whatever they want between Python and JS - not just basic datatypes and, with your proposed change, datetimes.

Does that make sense? Do you want to take a shot at implementing this?

@becurrie
Copy link
Author

Hi @becurrie,

Thanks for the PR - glad you're using Eel and want to contribute to its development. 🎉

I think it's a fair idea to allow more data types to be serialized. That said, I think we might want to consider the more general case for users transferring data/objects between the Python and JS sides. With that in mind, I think we might want to consider letting Eel take in custom JSONEncoder/Decoders, which are used instead of the default, so that developers can pass whatever they want between Python and JS - not just basic datatypes and, with your proposed change, datetimes.

Does that make sense? Do you want to take a shot at implementing this?

Yeah that makes perfect sense and general is always better, I can take a shot at it when I get some more time over the next month or so :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants