pypistats
pypistats copied to clipboard
Add the ability to retrieve stats as a deserialized/unformatted `dict`
When I use this library, I don't want it to give me a formatted string; I want the actual stats instead. Currently, I achieve this by doing json.loads(pypistats.recent(package, format="json")), but it would be more convenient if pypistats had a built-in way to get the unformatted stats.
Something like this?
diff --git a/src/pypistats/__init__.py b/src/pypistats/__init__.py
index 3bd7ac4..7395288 100644
--- a/src/pypistats/__init__.py
+++ b/src/pypistats/__init__.py
@@ -169,6 +169,9 @@ def pypi_stats_api(
data = _percent(data)
data = _grand_total(data)
+ if format == "dict":
+ return data
+
if color != "no" and format in ("markdown", "pretty", "rst", "tsv"):
data = _colourify(data)
And then call pypi_stats_api(format="dict")
@hugovk Yes, that would work.