Comments (3)
Hmmm, that's certainly possible to do.
A few questions:
- Do your messages contain a mix of naive and aware datetimes? Or are you only using naive datetimes?
- How do you plan on treating naive datetimes? UTC? Local timezone? Something else?
- Do you plan on serializing datetimes in a different format than RFC3339 (what msgspec currently uses)?
from msgspec.
- Do your messages contain a mix of naive and aware datetimes? Or are you only using naive datetimes?
I am dealing with poorly structured data from MongoDB, so I am never sure what kind of datetime I will encounter.
- How do you plan on treating naive datetimes? UTC? Local timezone? Something else?
I attempted to convert them to UTC in enc_hook.
- Do you plan on serializing datetimes in a different format than RFC3339 (what msgspec currently uses)?
I did not have any such plan. RFC3339 is space efficient enough for me, but if I had such a problem, I'd look at Temporenc, although their reference implementation in pure Python may be too slow.
(P.S.: I am using msgpack encoding. Does it also serialize to RFC3339?)
I have already solved my immediate problem by fixing the data before feeding to msgspec, but I still think a hook could be useful here.
from msgspec.
Makes sense, we can definitely add this feature. I'll try to get it in before the next release.
(P.S.: I am using msgpack encoding. Does it also serialize to RFC3339?)
Ah, my mistake, I assumed you were using JSON. Msgpack has a timestamp extension type that provides a builtin efficient representation.
from msgspec.
Related Issues (20)
- Typed encoding HOT 1
- Validation on serialization HOT 5
- Make msgspec more aware of large data and other serialization protocols
- Recommendation for Efficiently Decoding BSON from PyMongo with msgspec
- leading underscores and `"camel"` rename strategy HOT 2
- Constraint check for typing.Optional field HOT 1
- Automatically support `functools.cached_property` without requiring setting `dict=True` HOT 2
- UnboundLocalError for `new_scope` HOT 3
- Sign release tags when making future releases? HOT 4
- How can I do data normalization on a frozen instance in `__post_init__`? HOT 1
- Cannot convert with `from_attributes` when using a rename convention HOT 3
- Cannot set `gc=False` on Generic structs? HOT 5
- Support types.MappingProxyType HOT 3
- Add either `init_omit_defaults` or `omit_none` HOT 5
- Consider making `DecodeError` and `ValidationError` inherit from `ValueError` HOT 1
- Docs page on testing
- json schema generation - differences between pydantic and msgspec HOT 3
- Allow conversion to collection from generator HOT 2
- Porting guide for users coming from `orjson`
- Converting dicts into list with key-reuse HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msgspec.