Skip to content

Commit a23b0c6

Browse files
authored
Use format=None to return raw Python data structure (#467)
2 parents 9bee5f8 + c354641 commit a23b0c6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/pypistats/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _clear_cache() -> None:
8585
def pypi_stats_api(
8686
endpoint: str,
8787
params: str | None = None,
88-
format: str = "pretty",
88+
format: str | None = "pretty",
8989
start_date: str | None = None,
9090
end_date: str | None = None,
9191
sort: bool = True,
@@ -173,6 +173,9 @@ def pypi_stats_api(
173173
data = _percent(data)
174174
data = _grand_total(data)
175175

176+
if format is None:
177+
return data
178+
176179
if color != "no" and format in ("markdown", "pretty", "rst", "tsv"):
177180
data = _colourify(data)
178181

tests/test_pypistats.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,25 @@ def test_format_pandas(self) -> None:
748748
assert isinstance(output, pandas.DataFrame)
749749
assert str(output).strip() == expected_output.strip()
750750

751+
@respx.mock
752+
def test_format_none(self) -> None:
753+
# Arrange
754+
package = "pip"
755+
mocked_url = "https://pypistats.org/api/packages/pip/overall"
756+
mocked_response = SAMPLE_RESPONSE_OVERALL
757+
expected_output = {
758+
"category": "with_mirrors",
759+
"downloads": 3587357,
760+
"percent": "100.00%",
761+
}
762+
763+
# Act
764+
respx.get(mocked_url).respond(content=mocked_response)
765+
output = pypistats.overall(package, format=None)
766+
767+
# Assert
768+
assert output[0] == expected_output
769+
751770
@respx.mock
752771
def test_package_not_exist(self) -> None:
753772
# Arrange

0 commit comments

Comments
 (0)