jsonstat-validator 0.1.0__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 (59) hide show
  1. jsonstat_validator-0.1.0/LICENSE +21 -0
  2. jsonstat_validator-0.1.0/MANIFEST.in +6 -0
  3. jsonstat_validator-0.1.0/PKG-INFO +196 -0
  4. jsonstat_validator-0.1.0/README.md +141 -0
  5. jsonstat_validator-0.1.0/jsonstat_validator/__init__.py +34 -0
  6. jsonstat_validator-0.1.0/jsonstat_validator/tests/__init__.py +1 -0
  7. jsonstat_validator-0.1.0/jsonstat_validator/tests/conftest.py +10 -0
  8. jsonstat_validator-0.1.0/jsonstat_validator/tests/custom_tests.py +411 -0
  9. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/areas/canada.json +16 -0
  10. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/areas/galicia.json +16 -0
  11. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/areas/index.json +31 -0
  12. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/areas/oecd.json +16 -0
  13. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/areas/us.json +26 -0
  14. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/canada.json +131 -0
  15. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/datasets/index.json +51 -0
  16. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/galicia.json +124 -0
  17. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/hierarchy.json +200 -0
  18. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/index.json +36 -0
  19. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/gdp/gsp.json +16 -0
  20. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/gdp/gsppc.json +16 -0
  21. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/gdp/gspw.json +16 -0
  22. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/gdp/index.json +26 -0
  23. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/index.json +26 -0
  24. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/lfs/employed.json +16 -0
  25. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/lfs/index.json +31 -0
  26. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/lfs/lf.json +16 -0
  27. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/lfs/unemployed.json +16 -0
  28. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/lfs/unr.json +21 -0
  29. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/pop/index.json +21 -0
  30. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/pop/pop.json +26 -0
  31. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/metrics/pop/popw.json +16 -0
  32. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/oecd.json +170 -0
  33. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/order.json +38 -0
  34. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/sources/bls.json +21 -0
  35. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/sources/ige.json +16 -0
  36. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/sources/index.json +41 -0
  37. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/sources/jsonstat.json +21 -0
  38. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/sources/oecd.json +16 -0
  39. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/sources/statcan.json +16 -0
  40. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/sources/wikipedia.json +16 -0
  41. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/topics/accounts.json +16 -0
  42. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/topics/demos.json +21 -0
  43. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/topics/index.json +31 -0
  44. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/topics/labor.json +26 -0
  45. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/topics/population.json +26 -0
  46. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/us-gsp.json +230 -0
  47. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/us-labor.json +6509 -0
  48. jsonstat_validator-0.1.0/jsonstat_validator/tests/samples/us-unr.json +3269 -0
  49. jsonstat_validator-0.1.0/jsonstat_validator/tests/test_official_samples.py +51 -0
  50. jsonstat_validator-0.1.0/jsonstat_validator/validator.py +608 -0
  51. jsonstat_validator-0.1.0/jsonstat_validator.egg-info/PKG-INFO +196 -0
  52. jsonstat_validator-0.1.0/jsonstat_validator.egg-info/SOURCES.txt +57 -0
  53. jsonstat_validator-0.1.0/jsonstat_validator.egg-info/dependency_links.txt +1 -0
  54. jsonstat_validator-0.1.0/jsonstat_validator.egg-info/requires.txt +6 -0
  55. jsonstat_validator-0.1.0/jsonstat_validator.egg-info/top_level.txt +1 -0
  56. jsonstat_validator-0.1.0/pyproject.toml +50 -0
  57. jsonstat_validator-0.1.0/requirements.txt +1 -0
  58. jsonstat_validator-0.1.0/setup.cfg +4 -0
  59. jsonstat_validator-0.1.0/setup.py +43 -0
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2025 JSON-stat Validator Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ include LICENSE
2
+ include README.md
3
+ include requirements.txt
4
+ include pyproject.toml
5
+ recursive-include jsonstat_validator/tests *.py
6
+ recursive-include jsonstat_validator/tests/samples *.json
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.2
2
+ Name: jsonstat-validator
3
+ Version: 0.1.0
4
+ Summary: A Python validator for the JSON-stat 2.0 standard format, based on Pydantic.
5
+ Home-page: https://github.com/ahmed-hassan19/jsonstat-validator
6
+ Author: Ahmed Hassan
7
+ Author-email: Ahmed Hassan <ahmedhassan.ahmed@fao.org>
8
+ License: # MIT License
9
+
10
+ Copyright (c) 2025 JSON-stat Validator Contributors
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+
30
+ Project-URL: Homepage, https://github.com/ahmed-hassan19/jsonstat-validator
31
+ Project-URL: Bug Tracker, https://github.com/ahmed-hassan19/jsonstat-validator/issues
32
+ Project-URL: Documentation, https://github.com/ahmed-hassan19/jsonstat-validator#readme
33
+ Keywords: json-stat,validator,json,data-engineering,pydantic,python,fao
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3.8
36
+ Classifier: Programming Language :: Python :: 3.9
37
+ Classifier: Programming Language :: Python :: 3.10
38
+ Classifier: Programming Language :: Python :: 3.11
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: License :: OSI Approved :: MIT License
41
+ Classifier: Operating System :: OS Independent
42
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
43
+ Classifier: Topic :: Software Development :: Quality Assurance
44
+ Requires-Python: >=3.8
45
+ Description-Content-Type: text/markdown
46
+ License-File: LICENSE
47
+ Requires-Dist: pydantic<3.0.0,>=2.0.0
48
+ Provides-Extra: dev
49
+ Requires-Dist: pytest>=8.1.1; extra == "dev"
50
+ Requires-Dist: build>=1.0.0; extra == "dev"
51
+ Requires-Dist: twine>=4.0.0; extra == "dev"
52
+ Dynamic: author
53
+ Dynamic: home-page
54
+ Dynamic: requires-python
55
+
56
+ # JSON-stat Validator
57
+
58
+ [![PyPI version](https://badge.fury.io/py/jsonstat-validator.svg)](https://badge.fury.io/py/jsonstat-validator)
59
+ [![Python Version](https://img.shields.io/pypi/pyversions/jsonstat-validator.svg)](https://pypi.org/project/jsonstat-validator/)
60
+ [![License](https://img.shields.io/github/license/ahmed-hassan19/jsonstat-validator.svg)](https://github.com/ahmed-hassan19/jsonstat-validator/blob/main/LICENSE)
61
+
62
+ A Python validator for the JSON-stat 2.0 standard format, based on Pydantic.
63
+
64
+ JSON-stat is a simple lightweight format for data interchange. It is a JSON format for data dissemination that allows the representation of statistical data in a way that is both simple and convenient for data processing. With this validator, you can ensure your data conforms to the official [JSON-stat 2.0 specification](https://json-stat.org/full/).
65
+
66
+ ## Installation
67
+
68
+ ```bash
69
+ pip install jsonstat-validator
70
+ ```
71
+
72
+ ## Usage
73
+
74
+ ### Basic Validation
75
+
76
+ ```python
77
+ import json
78
+ from jsonstat_validator import validate_jsonstat
79
+
80
+ # Load your JSON-stat data
81
+ with open("data.json", "r") as f:
82
+ data = json.load(f)
83
+
84
+ # Validate the data
85
+ try:
86
+ result = validate_jsonstat(data)
87
+ print("Validation successful!")
88
+ except ValueError as e:
89
+ print(f"Validation failed: {e}")
90
+ ```
91
+
92
+ ### Example JSON-stat Dataset
93
+
94
+ Here's a simplified example of a JSON-stat dataset representing unemployment data:
95
+
96
+ ```json
97
+ {
98
+ "version": "2.0",
99
+ "class": "dataset",
100
+ "label": "Unemployment rate sample",
101
+ "source": "Sample data",
102
+ "updated": "2023-01-15",
103
+ "id": ["indicator", "area", "year"],
104
+ "size": [1, 3, 2],
105
+ "value": [5.8, 6.2, 7.1, 7.5, 4.2, 4.9],
106
+ "role": {
107
+ "time": ["year"],
108
+ "geo": ["area"],
109
+ "metric": ["indicator"]
110
+ },
111
+ "dimension": {
112
+ "indicator": {
113
+ "label": "Economic indicator",
114
+ "category": {
115
+ "label": {
116
+ "UNR": "unemployment rate"
117
+ },
118
+ "unit": {
119
+ "UNR": {
120
+ "symbol": "%",
121
+ "decimals": 1
122
+ }
123
+ }
124
+ }
125
+ },
126
+ "year": {
127
+ "label": "Year",
128
+ "category": {
129
+ "index": ["2020", "2021"]
130
+ }
131
+ },
132
+ "area": {
133
+ "label": "Country",
134
+ "category": {
135
+ "index": ["US", "JP", "EU"],
136
+ "label": {
137
+ "US": "United States",
138
+ "JP": "Japan",
139
+ "EU": "European Union"
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ ## Features
148
+
149
+ - Validates JSON-stat data against the [full 2.0 specification](https://json-stat.org/full).
150
+ - Provides models for all major JSON-stat responses: **Dataset**, **Dimension**, **Collection**.
151
+ - Built on Pydantic for robust type validation and error messages.
152
+ - Provides tests against the [official JSON-stat samples](https://json-stat.org/samples/collection.json) as well as custom fine-grained tests.
153
+
154
+ ## Testing
155
+
156
+ The validator has been thoroughly tested with all official JSON-stat samples from the [JSON-stat website](https://json-stat.org/samples/).
157
+
158
+ To run tests:
159
+
160
+ First, install the development dependencies:
161
+
162
+ ```bash
163
+ pip install jsonstat-validator[dev]
164
+ ```
165
+
166
+ Then run the tests:
167
+
168
+ ```bash
169
+ pytest
170
+ ```
171
+
172
+ To run a specific test file (e.g. test official samples only):
173
+
174
+ ```bash
175
+ pytest tests/test_official_samples.py
176
+ ```
177
+
178
+ ## License
179
+
180
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
181
+
182
+ ## Contributing
183
+
184
+ Contributions are welcome! Please feel free to submit a Pull Request.
185
+
186
+ 1. Fork the repository
187
+ 2. Create your feature branch (`git checkout -b feature/new-feature`)
188
+ 3. Commit your changes (`git commit -m 'Add some new feature'`)
189
+ 4. Push to the branch (`git push origin feature/new-feature`)
190
+ 5. Open a Pull Request
191
+
192
+ ## Credits
193
+
194
+ This package is maintained by Ahmed Hassan ([@ahmed-hassan19](https://github.com/ahmed-hassan19)) and was created for use at the Food and Agriculture Organization (FAO) of the United Nations.
195
+
196
+ The JSON-stat format was created by [Xavier Badosa](https://www.linkedin.com/in/badosa).
@@ -0,0 +1,141 @@
1
+ # JSON-stat Validator
2
+
3
+ [![PyPI version](https://badge.fury.io/py/jsonstat-validator.svg)](https://badge.fury.io/py/jsonstat-validator)
4
+ [![Python Version](https://img.shields.io/pypi/pyversions/jsonstat-validator.svg)](https://pypi.org/project/jsonstat-validator/)
5
+ [![License](https://img.shields.io/github/license/ahmed-hassan19/jsonstat-validator.svg)](https://github.com/ahmed-hassan19/jsonstat-validator/blob/main/LICENSE)
6
+
7
+ A Python validator for the JSON-stat 2.0 standard format, based on Pydantic.
8
+
9
+ JSON-stat is a simple lightweight format for data interchange. It is a JSON format for data dissemination that allows the representation of statistical data in a way that is both simple and convenient for data processing. With this validator, you can ensure your data conforms to the official [JSON-stat 2.0 specification](https://json-stat.org/full/).
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install jsonstat-validator
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Basic Validation
20
+
21
+ ```python
22
+ import json
23
+ from jsonstat_validator import validate_jsonstat
24
+
25
+ # Load your JSON-stat data
26
+ with open("data.json", "r") as f:
27
+ data = json.load(f)
28
+
29
+ # Validate the data
30
+ try:
31
+ result = validate_jsonstat(data)
32
+ print("Validation successful!")
33
+ except ValueError as e:
34
+ print(f"Validation failed: {e}")
35
+ ```
36
+
37
+ ### Example JSON-stat Dataset
38
+
39
+ Here's a simplified example of a JSON-stat dataset representing unemployment data:
40
+
41
+ ```json
42
+ {
43
+ "version": "2.0",
44
+ "class": "dataset",
45
+ "label": "Unemployment rate sample",
46
+ "source": "Sample data",
47
+ "updated": "2023-01-15",
48
+ "id": ["indicator", "area", "year"],
49
+ "size": [1, 3, 2],
50
+ "value": [5.8, 6.2, 7.1, 7.5, 4.2, 4.9],
51
+ "role": {
52
+ "time": ["year"],
53
+ "geo": ["area"],
54
+ "metric": ["indicator"]
55
+ },
56
+ "dimension": {
57
+ "indicator": {
58
+ "label": "Economic indicator",
59
+ "category": {
60
+ "label": {
61
+ "UNR": "unemployment rate"
62
+ },
63
+ "unit": {
64
+ "UNR": {
65
+ "symbol": "%",
66
+ "decimals": 1
67
+ }
68
+ }
69
+ }
70
+ },
71
+ "year": {
72
+ "label": "Year",
73
+ "category": {
74
+ "index": ["2020", "2021"]
75
+ }
76
+ },
77
+ "area": {
78
+ "label": "Country",
79
+ "category": {
80
+ "index": ["US", "JP", "EU"],
81
+ "label": {
82
+ "US": "United States",
83
+ "JP": "Japan",
84
+ "EU": "European Union"
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ ## Features
93
+
94
+ - Validates JSON-stat data against the [full 2.0 specification](https://json-stat.org/full).
95
+ - Provides models for all major JSON-stat responses: **Dataset**, **Dimension**, **Collection**.
96
+ - Built on Pydantic for robust type validation and error messages.
97
+ - Provides tests against the [official JSON-stat samples](https://json-stat.org/samples/collection.json) as well as custom fine-grained tests.
98
+
99
+ ## Testing
100
+
101
+ The validator has been thoroughly tested with all official JSON-stat samples from the [JSON-stat website](https://json-stat.org/samples/).
102
+
103
+ To run tests:
104
+
105
+ First, install the development dependencies:
106
+
107
+ ```bash
108
+ pip install jsonstat-validator[dev]
109
+ ```
110
+
111
+ Then run the tests:
112
+
113
+ ```bash
114
+ pytest
115
+ ```
116
+
117
+ To run a specific test file (e.g. test official samples only):
118
+
119
+ ```bash
120
+ pytest tests/test_official_samples.py
121
+ ```
122
+
123
+ ## License
124
+
125
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
126
+
127
+ ## Contributing
128
+
129
+ Contributions are welcome! Please feel free to submit a Pull Request.
130
+
131
+ 1. Fork the repository
132
+ 2. Create your feature branch (`git checkout -b feature/new-feature`)
133
+ 3. Commit your changes (`git commit -m 'Add some new feature'`)
134
+ 4. Push to the branch (`git push origin feature/new-feature`)
135
+ 5. Open a Pull Request
136
+
137
+ ## Credits
138
+
139
+ This package is maintained by Ahmed Hassan ([@ahmed-hassan19](https://github.com/ahmed-hassan19)) and was created for use at the Food and Agriculture Organization (FAO) of the United Nations.
140
+
141
+ The JSON-stat format was created by [Xavier Badosa](https://www.linkedin.com/in/badosa).
@@ -0,0 +1,34 @@
1
+ """
2
+ JSON-stat validator.
3
+
4
+ A validator for the JSON-stat 2.0 format, a simple lightweight format for data
5
+ interchange. It provides a way to exchange data associated to dimensions,
6
+ following the cube model that is so common in statistical offices.
7
+
8
+ For more information on JSON-stat, see: https://json-stat.org/
9
+ """
10
+
11
+ from jsonstat_validator.validator import (
12
+ Category,
13
+ Collection,
14
+ Dataset,
15
+ DatasetRole,
16
+ Dimension,
17
+ JSONStatSchema,
18
+ Link,
19
+ Unit,
20
+ validate_jsonstat,
21
+ )
22
+
23
+ __version__ = "0.1.0"
24
+ __all__ = [
25
+ "Dataset",
26
+ "Dimension",
27
+ "Collection",
28
+ "Link",
29
+ "Unit",
30
+ "Category",
31
+ "DatasetRole",
32
+ "JSONStatSchema",
33
+ "validate_jsonstat",
34
+ ]
@@ -0,0 +1 @@
1
+ """Test package for JSON-stat validator."""
@@ -0,0 +1,10 @@
1
+ """Configuration file for pytest."""
2
+
3
+ import pytest
4
+
5
+
6
+ def pytest_collection_modifyitems(items):
7
+ """Add custom markers to test items."""
8
+ for item in items:
9
+ if "samples" in item.nodeid:
10
+ item.add_marker(pytest.mark.samples)