pxwebpy 0.3.1__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pxwebpy-0.3.2/.github/workflows/ci.yml +62 -0
- pxwebpy-0.3.2/.github/workflows/release.yml +31 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/PKG-INFO +7 -5
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/README.md +2 -2
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/pyproject.toml +6 -11
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/src/pxwebpy/table.py +48 -40
- pxwebpy-0.3.2/uv.lock +945 -0
- pxwebpy-0.3.1/.github/workflows/ci.yml +0 -39
- pxwebpy-0.3.1/.github/workflows/release.yml +0 -28
- pxwebpy-0.3.1/.python-version +0 -1
- pxwebpy-0.3.1/requirements-dev.lock +0 -108
- pxwebpy-0.3.1/requirements.lock +0 -22
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/.gitignore +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/LICENSE +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/examples/example.py +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/examples/example_query.json +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/src/pxwebpy/__init__.py +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/invalid_query.json +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/response_fi.json +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/response_gl.json +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/response_no.json +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/response_table_variables.json +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/result_fi.json +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/result_gl.json +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/result_no.json +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/queries.json +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/test_table.py +0 -0
- {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/valid_query.json +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
|
|
3
|
+
env:
|
|
4
|
+
UV_VERSION: "0.4.9"
|
|
5
|
+
UV_CACHE_DIR: /tmp/.uv-cache
|
|
6
|
+
UV_LINK_MODE: copy
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
push:
|
|
10
|
+
branches: [ "main" ]
|
|
11
|
+
pull_request:
|
|
12
|
+
branches: [ "main" ]
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
build:
|
|
16
|
+
name: python-${{ matrix.os }}
|
|
17
|
+
|
|
18
|
+
strategy:
|
|
19
|
+
matrix:
|
|
20
|
+
os:
|
|
21
|
+
- ubuntu-latest
|
|
22
|
+
- windows-latest
|
|
23
|
+
- macos-latest
|
|
24
|
+
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
|
25
|
+
fail-fast: false
|
|
26
|
+
|
|
27
|
+
runs-on: ${{ matrix.os }}
|
|
28
|
+
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@v4
|
|
31
|
+
|
|
32
|
+
- name: Set up uv ${{ env.UV_VERSION }}
|
|
33
|
+
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }}
|
|
34
|
+
run: curl -LsSf https://astral.sh/uv/${{ env.UV_VERSION }}/install.sh | sh
|
|
35
|
+
|
|
36
|
+
- name: Set up uv ${{ env.UV_VERSION }}
|
|
37
|
+
if: ${{ matrix.os == 'windows-latest' }}
|
|
38
|
+
run: irm https://astral.sh/uv/${{ env.UV_VERSION }}/install.ps1 | iex
|
|
39
|
+
shell: powershell
|
|
40
|
+
|
|
41
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
42
|
+
run: uv python install ${{ matrix.python-version }}
|
|
43
|
+
|
|
44
|
+
- name: Restore uv cache
|
|
45
|
+
uses: actions/cache@v4
|
|
46
|
+
with:
|
|
47
|
+
path: ${{ env.UV_CACHE_DIR }}
|
|
48
|
+
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
|
|
49
|
+
restore-keys: |
|
|
50
|
+
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
|
|
51
|
+
uv-${{ runner.os }}
|
|
52
|
+
|
|
53
|
+
- name: Install
|
|
54
|
+
run: uv sync --extra ci --no-dev --locked
|
|
55
|
+
|
|
56
|
+
- name: Run tests & build
|
|
57
|
+
run: |
|
|
58
|
+
uv run pytest tests
|
|
59
|
+
uv build
|
|
60
|
+
|
|
61
|
+
- name: Minimize uv cache
|
|
62
|
+
run: uv cache prune --ci
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: release
|
|
2
|
+
|
|
3
|
+
env:
|
|
4
|
+
UV_VERSION: "0.4.9"
|
|
5
|
+
UV_LINK_MODE: copy
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
release:
|
|
9
|
+
types: [published]
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build-release:
|
|
13
|
+
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
environment: release
|
|
16
|
+
permissions:
|
|
17
|
+
id-token: write
|
|
18
|
+
strategy:
|
|
19
|
+
fail-fast: false
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: Set up uv ${{ env.UV_VERSION }}
|
|
25
|
+
run: curl -LsSf https://astral.sh/uv/${{ env.UV_VERSION }}/install.sh | sh
|
|
26
|
+
|
|
27
|
+
- name: Build for distribution
|
|
28
|
+
run: uv build
|
|
29
|
+
|
|
30
|
+
- name: Publish to PyPI
|
|
31
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: pxwebpy
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Get data from PxWeb API easily.
|
|
5
|
-
Project-URL:
|
|
5
|
+
Project-URL: Repository, https://github.com/stefur/pxwebpy
|
|
6
6
|
Author-email: stefur <stefan@furne.net>
|
|
7
7
|
License-Expression: MIT
|
|
8
8
|
License-File: LICENSE
|
|
9
9
|
Keywords: dataframes,pandas,polars,pxweb,statistics
|
|
10
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
11
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Requires-Python: >=3.
|
|
16
|
+
Requires-Python: >=3.9
|
|
15
17
|
Requires-Dist: requests>=2.31.0
|
|
16
18
|
Provides-Extra: ci
|
|
17
19
|
Requires-Dist: pytest>=8.2.0; extra == 'ci'
|
|
@@ -21,8 +23,8 @@ Description-Content-Type: text/markdown
|
|
|
21
23
|
[](https://github.com/stefur/pxwebpy/actions/workflows/ci.yml)
|
|
22
24
|

|
|
23
25
|

|
|
24
|
-
[](https://github.com/astral-sh/uv)
|
|
27
|
+
[](https://github.com/astral-sh/ruff)
|
|
26
28
|
Easily get data from the PxWeb API and into either a polars or pandas dataframe.
|
|
27
29
|
|
|
28
30
|
Pxwebpy parses the PxWeb table data as well as metadata using the json-stat2 response format.
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
[](https://github.com/stefur/pxwebpy/actions/workflows/ci.yml)
|
|
3
3
|

|
|
4
4
|

|
|
5
|
-
[](https://github.com/astral-sh/uv)
|
|
6
|
+
[](https://github.com/astral-sh/ruff)
|
|
7
7
|
Easily get data from the PxWeb API and into either a polars or pandas dataframe.
|
|
8
8
|
|
|
9
9
|
Pxwebpy parses the PxWeb table data as well as metadata using the json-stat2 response format.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pxwebpy"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.2"
|
|
4
4
|
description = "Get data from PxWeb API easily."
|
|
5
5
|
license = "MIT"
|
|
6
6
|
repository = "https://github.com/stefur/pxwebpy/"
|
|
@@ -8,6 +8,8 @@ keywords = ["pxweb", "statistics", "dataframes", "pandas", "polars"]
|
|
|
8
8
|
classifiers = [
|
|
9
9
|
"License :: OSI Approved :: MIT License",
|
|
10
10
|
"Programming Language :: Python :: 3 :: Only",
|
|
11
|
+
"Programming Language :: Python :: 3.9",
|
|
12
|
+
"Programming Language :: Python :: 3.10",
|
|
11
13
|
"Programming Language :: Python :: 3.11",
|
|
12
14
|
"Programming Language :: Python :: 3.12",
|
|
13
15
|
]
|
|
@@ -18,10 +20,10 @@ dependencies = [
|
|
|
18
20
|
"requests>=2.31.0",
|
|
19
21
|
]
|
|
20
22
|
readme = "README.md"
|
|
21
|
-
requires-python = ">= 3.
|
|
23
|
+
requires-python = ">= 3.9"
|
|
22
24
|
|
|
23
25
|
[project.urls]
|
|
24
|
-
|
|
26
|
+
Repository = "https://github.com/stefur/pxwebpy"
|
|
25
27
|
|
|
26
28
|
[project.optional-dependencies]
|
|
27
29
|
ci = [
|
|
@@ -32,8 +34,7 @@ ci = [
|
|
|
32
34
|
requires = ["hatchling"]
|
|
33
35
|
build-backend = "hatchling.build"
|
|
34
36
|
|
|
35
|
-
[tool.
|
|
36
|
-
managed = true
|
|
37
|
+
[tool.uv]
|
|
37
38
|
dev-dependencies = [
|
|
38
39
|
"types-requests>=2.32.0.20240602",
|
|
39
40
|
"polars>=0.20.7",
|
|
@@ -42,9 +43,3 @@ dev-dependencies = [
|
|
|
42
43
|
"pytest>=8.2.0",
|
|
43
44
|
"ipykernel>=6.29.4",
|
|
44
45
|
]
|
|
45
|
-
|
|
46
|
-
[tool.hatch.metadata]
|
|
47
|
-
allow-direct-references = true
|
|
48
|
-
|
|
49
|
-
[tool.hatch.build.targets.wheel]
|
|
50
|
-
packages = ["src/pxwebpy"]
|
|
@@ -5,6 +5,7 @@ import json
|
|
|
5
5
|
from datetime import datetime
|
|
6
6
|
from enum import Enum
|
|
7
7
|
from pathlib import Path
|
|
8
|
+
from typing import Optional, Union
|
|
8
9
|
|
|
9
10
|
import requests
|
|
10
11
|
|
|
@@ -72,13 +73,13 @@ class PxTable:
|
|
|
72
73
|
"""
|
|
73
74
|
|
|
74
75
|
def __init__(self, url=None, query=None) -> None:
|
|
75
|
-
self.url: str
|
|
76
|
-
self.query: dict
|
|
77
|
-
self.dataset: list[dict]
|
|
76
|
+
self.url: Optional[str] = url
|
|
77
|
+
self.query: Optional[dict] = query
|
|
78
|
+
self.dataset: Optional[list[dict]] = None
|
|
78
79
|
self.metadata: dict = {
|
|
79
80
|
key: None for key in ["label", "note", "source", "updated"]
|
|
80
81
|
}
|
|
81
|
-
self.fetched: datetime
|
|
82
|
+
self.fetched: Optional[datetime] = None
|
|
82
83
|
|
|
83
84
|
if query:
|
|
84
85
|
try:
|
|
@@ -125,36 +126,35 @@ class PxTable:
|
|
|
125
126
|
# If the dimension has extension data along with a key for show, use
|
|
126
127
|
# that to determine the values shown in the output
|
|
127
128
|
try:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
]
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
]
|
|
152
|
-
|
|
129
|
+
show_value = json_data["dimension"][dim]["extension"]["show"]
|
|
130
|
+
|
|
131
|
+
if show_value == "code_value":
|
|
132
|
+
values = [
|
|
133
|
+
str(k) + " " + str(v)
|
|
134
|
+
for k, v in json_data["dimension"][dim]["category"][
|
|
135
|
+
"label"
|
|
136
|
+
].items()
|
|
137
|
+
]
|
|
138
|
+
|
|
139
|
+
elif show_value == "code":
|
|
140
|
+
values = [
|
|
141
|
+
str(k)
|
|
142
|
+
for k in json_data["dimension"][dim]["category"]["label"].keys()
|
|
143
|
+
]
|
|
144
|
+
|
|
145
|
+
elif show_value == "value":
|
|
146
|
+
values = [
|
|
147
|
+
str(v)
|
|
148
|
+
for v in json_data["dimension"][dim]["category"][
|
|
149
|
+
"label"
|
|
150
|
+
].values()
|
|
151
|
+
]
|
|
153
152
|
# Raise an error if we hit some value in the show key that we don't know how to handle
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
153
|
+
|
|
154
|
+
else:
|
|
155
|
+
raise ValueError(
|
|
156
|
+
f"""Unexpected show value. Expected "code", "value" or "code_value", got: {show_value}"""
|
|
157
|
+
)
|
|
158
158
|
|
|
159
159
|
# If there's no show key at all we default to using the label values
|
|
160
160
|
except KeyError:
|
|
@@ -182,7 +182,7 @@ class PxTable:
|
|
|
182
182
|
try:
|
|
183
183
|
path = Path(query)
|
|
184
184
|
return path.exists()
|
|
185
|
-
except
|
|
185
|
+
except OSError:
|
|
186
186
|
return False
|
|
187
187
|
|
|
188
188
|
@property
|
|
@@ -193,12 +193,20 @@ class PxTable:
|
|
|
193
193
|
return self.__query
|
|
194
194
|
|
|
195
195
|
@query.setter
|
|
196
|
-
def query(
|
|
196
|
+
def query(
|
|
197
|
+
self,
|
|
198
|
+
query: Optional[
|
|
199
|
+
Union[
|
|
200
|
+
str,
|
|
201
|
+
dict,
|
|
202
|
+
]
|
|
203
|
+
],
|
|
204
|
+
) -> None:
|
|
197
205
|
"""
|
|
198
206
|
Set the JSON query from a string representing a path or a JSON structure that is either a string or a dict.
|
|
199
207
|
"""
|
|
200
208
|
|
|
201
|
-
if not isinstance(query, str
|
|
209
|
+
if not isinstance(query, (str, dict, type(None))):
|
|
202
210
|
raise TypeError(
|
|
203
211
|
f"""Invalid input for `query`.
|
|
204
212
|
Expected `str`, `dict` or `None`, got {type(query)!r}."""
|
|
@@ -211,7 +219,7 @@ class PxTable:
|
|
|
211
219
|
else:
|
|
212
220
|
try:
|
|
213
221
|
self.__query = json.loads(query)
|
|
214
|
-
except
|
|
222
|
+
except json.JSONDecodeError as err:
|
|
215
223
|
raise ValueError(
|
|
216
224
|
"Provided value could not be decoded as JSON."
|
|
217
225
|
) from err
|
|
@@ -233,9 +241,9 @@ class PxTable:
|
|
|
233
241
|
try:
|
|
234
242
|
response.raise_for_status()
|
|
235
243
|
except requests.exceptions.HTTPError:
|
|
236
|
-
raise
|
|
244
|
+
raise RuntimeError(
|
|
237
245
|
f"Failed to {context.value}: {response.status_code}: {response.reason}"
|
|
238
|
-
)
|
|
246
|
+
)
|
|
239
247
|
|
|
240
248
|
return response.json()
|
|
241
249
|
|
|
@@ -309,7 +317,7 @@ class PxTable:
|
|
|
309
317
|
)
|
|
310
318
|
self.query = {"query": conversion, "response": {"format": "json-stat2"}}
|
|
311
319
|
|
|
312
|
-
def get_table_variables(self) -> dict
|
|
320
|
+
def get_table_variables(self) -> Union[dict, None]:
|
|
313
321
|
"""
|
|
314
322
|
Returns a dict of variables and the respective values from the table.
|
|
315
323
|
"""
|