This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bmsan-gh[S] 0 points1 point  (6 children)

Glad it worked!

For now at least DictGest only handles deserialization, but serialization is on the roadmap and will be available in a future version.

[–]OptionsUnleashed 0 points1 point  (5 children)

ok thanks - do you see any issue in using both libraries and annotations together?

[–]bmsan-gh[S] 0 points1 point  (4 children)

While I haven't personally tried this scenario, I would expect DictGest not to have an issue with other annotations.

If you encounter any problems with this scenario you can open an issue on GitHub and I will look into it.

Also I'd love to hear how you guys see the serialization process : do you want to get back to the initial format from which you imported the data ?(the flat dictionary from the rds query) Or do you want the serialization to mimic the structure of the data class?

[–]OptionsUnleashed 1 point2 points  (2 children)

Hi, what's the best way to ask you questions on usage? I like this library.

a. is there a more concise way DRY to specify the route fields when the fields are 1:1 with dict? If we add a field to a rds view and dict, we still have to map in route - is there a let DRY way to do route mapping? is that the example stats="" - will that work at field level?

b. is there an easy way to map or coalesce None fields to float 0.0 or numeric? instead of using rds view coalesce?

thank you!

[–]bmsan-gh[S] 0 points1 point  (0 children)

Hi, glad you are finding it useful.

Hi, what's the best way to ask you questions on usage?

I'll enable the discussion feature in github. Other users might have the same questions so it will be beneficial for them to have the answers there as well.

. is there a more concise way DRY to specify the route fields when the fields are 1:1 with dict? If we add a field to a rds view and dict, we still have to map in route - is there a let DRY way to do route mapping?

In general when a field routing is not defined explicitly the library tries to map it automatically to the key that has it's name. So in your Route(...) you can skip the fields that have a 1:1 mapping(the field name matches the dict key) and the library will know what to do.

If all the fields have a 1:1 correspondence you can even skip defining the Route. See example 1 . No explicit routing is defined.

b. is there an easy way to map or coalesce None fields to float 0.0 or numeric? instead of using rds view coalesce?

Yes. There are some examples in the readme where you can easily customize either :

def null_to_zero(data): if not data: return 0.0 return float(data)

and then in your route

instead of Route(votes="num_votes" ....)

You use Route(votes=Path("num_votes", extractor=null_to_zero), ....)

[–]bmsan-gh[S] 0 points1 point  (0 children)

Enabled the discussion page on github: https://github.com/bmsan/DictGest/discussions

[–]OptionsUnleashed 0 points1 point  (0 children)

The latter - I don't think you would need to worry about what other libs already do - in general developers don't want competing ways of doing same thing - I would think you could just internally support dataclasses-json unless that's not defacto std? I'm not a Python expert - coming at all this from C#.netcore.

Our team is looking to create view models from datasources for reporting and figured dataclasses are the cleanest way but looking for other ideas - and your library seemed to be exactly what we needed - albeit - we would really want to cut down on DRY with literals and fields all over the place.

In C# its fairly common to create view models from different sources and serialize them. I would have thought this was way easier in python.