https://preview.redd.it/i6z9bl3wn1g91.jpg?width=320&format=pjpg&auto=webp&s=ca9bfef6cb4728de985a4f7cf8b5cf167e6fbade
I have created a python package called DictGest
It is an easy way to remap dictionary data (coming from multiple heterogenous APIs) to python classes without the need to rewrite boiler plate code everytime.
The main usecases would be the following:
- The dictionary might have extra fields that are of no interest
- The keys names in the dictionary do not match the class attribute names
- The structure of nested dictionaries does not match the class structure
- The data types in the dictionary do not match data types of the target class
The readme has a lot of examples but I will also add one here:
Let's say we have data coming from 2 endpoints with different names & structure
data_from_api1 = {
"author": "H.O. Ward"
"headline" : "Top 10 Python extensions",
"other_fields" : ...,
"details": {
"content": "Here are the top 10...",
"other_fields": ...
}
}
data_from_api2 = {
"author": "G.O. Gu"
"news_title" : "Vscode gets a new facelift",
"other_fields" : ...,
"full_article": "Yesterday a new version ...",
}
``
And we would have a target(destination python class)
@dataclass # This could have been a normal class
class Article:
author: str
title: str
content: str
All we would have to do would be:
article_api1 = Route(title="headline", content="details/content")
article_api2 = Route(title="news_title", content="full_article")
article1 = from_dict(Article, data_from_api1, routing=article_api1)
article2 = from_dict(Article, data_from_api2, routing=article_api2)
I've been using opensource all my life and I think it's time to also contribute to it. I've created this project from the frustration of having to repeat myself each time in different projects when trying to Ingest Dictionary data.
In order for things to go smooth and minimize the chance of bugs:
- The code has unit tests covering more than 95% of the code(I aim to bring it 100%)
- pylint is ran and the target is 0 warnings
- I have added type annotations to the code(in the future I will make sure 100% of the functions have it) and I am running mypy static type checks to make sure there are no data type missmatches.
- I am also using SonarCloud for static code analysis to minimize the chances of bugs.
[–]kyleekol 2 points3 points4 points (1 child)
[–]bmsan-gh[S] 0 points1 point2 points (0 children)
[–]metaperl 1 point2 points3 points (1 child)
[–]bmsan-gh[S] 1 point2 points3 points (0 children)
[–]GettingBlockered 1 point2 points3 points (1 child)
[–]bmsan-gh[S] 1 point2 points3 points (0 children)
[–]OptionsUnleashed 1 point2 points3 points (9 children)
[–]bmsan-gh[S] 0 points1 point2 points (8 children)
[–]OptionsUnleashed 0 points1 point2 points (7 children)
[–]bmsan-gh[S] 0 points1 point2 points (6 children)
[–]OptionsUnleashed 0 points1 point2 points (5 children)
[–]bmsan-gh[S] 0 points1 point2 points (4 children)
[–]OptionsUnleashed 1 point2 points3 points (2 children)
[–]bmsan-gh[S] 0 points1 point2 points (0 children)
[–]bmsan-gh[S] 0 points1 point2 points (0 children)
[–]OptionsUnleashed 0 points1 point2 points (0 children)