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.
Files changed (28) hide show
  1. pxwebpy-0.3.2/.github/workflows/ci.yml +62 -0
  2. pxwebpy-0.3.2/.github/workflows/release.yml +31 -0
  3. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/PKG-INFO +7 -5
  4. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/README.md +2 -2
  5. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/pyproject.toml +6 -11
  6. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/src/pxwebpy/table.py +48 -40
  7. pxwebpy-0.3.2/uv.lock +945 -0
  8. pxwebpy-0.3.1/.github/workflows/ci.yml +0 -39
  9. pxwebpy-0.3.1/.github/workflows/release.yml +0 -28
  10. pxwebpy-0.3.1/.python-version +0 -1
  11. pxwebpy-0.3.1/requirements-dev.lock +0 -108
  12. pxwebpy-0.3.1/requirements.lock +0 -22
  13. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/.gitignore +0 -0
  14. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/LICENSE +0 -0
  15. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/examples/example.py +0 -0
  16. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/examples/example_query.json +0 -0
  17. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/src/pxwebpy/__init__.py +0 -0
  18. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/invalid_query.json +0 -0
  19. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/response_fi.json +0 -0
  20. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/response_gl.json +0 -0
  21. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/response_no.json +0 -0
  22. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/response_table_variables.json +0 -0
  23. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/result_fi.json +0 -0
  24. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/result_gl.json +0 -0
  25. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/mock/result_no.json +0 -0
  26. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/queries.json +0 -0
  27. {pxwebpy-0.3.1 → pxwebpy-0.3.2}/tests/test_table.py +0 -0
  28. {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.1
3
+ Version: 0.3.2
4
4
  Summary: Get data from PxWeb API easily.
5
- Project-URL: Issue tracker, https://github.com/stefur/pxwebpy/issues
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.11
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
  [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/stefur/pxwebpy/ci.yml?style=flat-square&label=ci)](https://github.com/stefur/pxwebpy/actions/workflows/ci.yml)
22
24
  ![PyPI - Version](https://img.shields.io/pypi/v/pxwebpy?style=flat-square)
23
25
  ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pxwebpy?style=flat-square)
24
- [![Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/mitsuhiko/rye/main/artwork/badge.json&style=flat-square)](https://rye-up.com)
25
- [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=flat-square)](https://github.com/astral-sh/ruff)
26
+ [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json&style=flat-square)](https://github.com/astral-sh/uv)
27
+ [![ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=flat-square)](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
  [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/stefur/pxwebpy/ci.yml?style=flat-square&label=ci)](https://github.com/stefur/pxwebpy/actions/workflows/ci.yml)
3
3
  ![PyPI - Version](https://img.shields.io/pypi/v/pxwebpy?style=flat-square)
4
4
  ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pxwebpy?style=flat-square)
5
- [![Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/mitsuhiko/rye/main/artwork/badge.json&style=flat-square)](https://rye-up.com)
6
- [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=flat-square)](https://github.com/astral-sh/ruff)
5
+ [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json&style=flat-square)](https://github.com/astral-sh/uv)
6
+ [![ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=flat-square)](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.1"
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.11"
23
+ requires-python = ">= 3.9"
22
24
 
23
25
  [project.urls]
24
- "Issue tracker" = "https://github.com/stefur/pxwebpy/issues"
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.rye]
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 | None = url
76
- self.query: dict | None = query
77
- self.dataset: list[dict] | None = None
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 | None = None
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
- match json_data["dimension"][dim]["extension"]["show"]:
129
- case "code_value":
130
- values = [
131
- str(k) + " " + str(v)
132
- for k, v in json_data["dimension"][dim]["category"][
133
- "label"
134
- ].items()
135
- ]
136
-
137
- case "code":
138
- values = [
139
- str(k)
140
- for k in json_data["dimension"][dim]["category"][
141
- "label"
142
- ].keys()
143
- ]
144
-
145
- case "value":
146
- values = [
147
- str(v)
148
- for v in json_data["dimension"][dim]["category"][
149
- "label"
150
- ].values()
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
- case _:
155
- raise ValueError(
156
- f"""Unexpected show value. Expected "code", "value" or "code_value", got: {json_data["dimension"][dim]["extension"]["show"]}"""
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 Exception:
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(self, query: str | dict | None) -> None:
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 | dict | None):
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 Exception as err:
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 Exception(
244
+ raise RuntimeError(
237
245
  f"Failed to {context.value}: {response.status_code}: {response.reason}"
238
- ) from None
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 | None:
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
  """