ssb-klass-python 1.0.3__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 (26) hide show
  1. ssb_klass_python-1.0.3/LICENSE +21 -0
  2. ssb_klass_python-1.0.3/PKG-INFO +142 -0
  3. ssb_klass_python-1.0.3/README.md +114 -0
  4. ssb_klass_python-1.0.3/pyproject.toml +172 -0
  5. ssb_klass_python-1.0.3/src/klass/__init__.py +97 -0
  6. ssb_klass_python-1.0.3/src/klass/classes/__init__.py +9 -0
  7. ssb_klass_python-1.0.3/src/klass/classes/classification.py +389 -0
  8. ssb_klass_python-1.0.3/src/klass/classes/codes.py +236 -0
  9. ssb_klass_python-1.0.3/src/klass/classes/correspondence.py +252 -0
  10. ssb_klass_python-1.0.3/src/klass/classes/family.py +74 -0
  11. ssb_klass_python-1.0.3/src/klass/classes/search.py +256 -0
  12. ssb_klass_python-1.0.3/src/klass/classes/variant.py +282 -0
  13. ssb_klass_python-1.0.3/src/klass/classes/version.py +444 -0
  14. ssb_klass_python-1.0.3/src/klass/config.py +6 -0
  15. ssb_klass_python-1.0.3/src/klass/py.typed +0 -0
  16. ssb_klass_python-1.0.3/src/klass/requests/__init__.py +5 -0
  17. ssb_klass_python-1.0.3/src/klass/requests/klass_requests.py +438 -0
  18. ssb_klass_python-1.0.3/src/klass/requests/klass_types.py +234 -0
  19. ssb_klass_python-1.0.3/src/klass/requests/sections.py +22 -0
  20. ssb_klass_python-1.0.3/src/klass/requests/validate.py +161 -0
  21. ssb_klass_python-1.0.3/src/klass/utility/classification.py +6 -0
  22. ssb_klass_python-1.0.3/src/klass/utility/cleanup.py +19 -0
  23. ssb_klass_python-1.0.3/src/klass/utility/codes.py +12 -0
  24. ssb_klass_python-1.0.3/src/klass/utility/naming.py +44 -0
  25. ssb_klass_python-1.0.3/src/klass/widgets/__init__.py +5 -0
  26. ssb_klass_python-1.0.3/src/klass/widgets/search_ipywidget.py +119 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright © 2023 Statistics Norway
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,142 @@
1
+ Metadata-Version: 2.4
2
+ Name: ssb-klass-python
3
+ Version: 1.0.3
4
+ Summary: A Python package built on top of KLASS's API for retrieving classifications, codes, correspondences etc.
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Author: Carl Corneil
8
+ Author-email: ssb-pythonistas <ssb-pythonistas@ssb.no>
9
+ Requires-Python: >=3.11,<4
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Requires-Dist: ipython (<9)
17
+ Requires-Dist: ipywidgets (>=8.0.6)
18
+ Requires-Dist: pandas (>=1.5.3)
19
+ Requires-Dist: python-dateutil (>=2.8.2)
20
+ Requires-Dist: requests (>=2.31.0)
21
+ Requires-Dist: toml (>=0.10.2)
22
+ Requires-Dist: typing-extensions (>=4.12.2)
23
+ Project-URL: Documentation, https://statisticsnorway.github.io/ssb-klass-python
24
+ Project-URL: Homepage, https://github.com/statisticsnorway/ssb-klass-python
25
+ Project-URL: Repository, https://github.com/statisticsnorway/ssb-klass-python
26
+ Description-Content-Type: text/markdown
27
+
28
+ # ssb-klass-python / KLASS
29
+ [![PyPI](https://img.shields.io/pypi/v/ssb-klass-python.svg)][pypi status]
30
+ [![Status](https://img.shields.io/pypi/status/ssb-klass-python.svg)][pypi status]
31
+ [![Python Version](https://img.shields.io/pypi/pyversions/ssb-klass-python)][pypi status]
32
+ [![License](https://img.shields.io/pypi/l/ssb-klass-python)][license]
33
+
34
+ [![Documentation](https://github.com/statisticsnorway/ssb-klass-python/actions/workflows/docs.yml/badge.svg)][documentation]
35
+ [![Tests](https://github.com/statisticsnorway/ssb-klass-python/actions/workflows/tests.yml/badge.svg)][tests]
36
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=statisticsnorway_ssb-klass-python&metric=coverage)][sonarcov]
37
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=statisticsnorway_ssb-klass-python&metric=alert_status)][sonarquality]
38
+
39
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)][pre-commit]
40
+ [![Black](https://img.shields.io/badge/code%20style-black-000000.svg)][black]
41
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
42
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)][poetry]
43
+
44
+ [pypi status]: https://pypi.org/project/ssb-klass-python/
45
+ [documentation]: https://statisticsnorway.github.io/ssb-klass-python
46
+ [tests]: https://github.com/statisticsnorway/ssb-klass-python/actions?workflow=Tests
47
+
48
+ [sonarcov]: https://sonarcloud.io/summary/overall?id=statisticsnorway_ssb-klass-python
49
+ [sonarquality]: https://sonarcloud.io/summary/overall?id=statisticsnorway_ssb-klass-python
50
+ [pre-commit]: https://github.com/pre-commit/pre-commit
51
+ [black]: https://github.com/psf/black
52
+ [poetry]: https://python-poetry.org/
53
+ A Python package built on top of Statistics Norway's code- and classification-system "KLASS". \
54
+ The package aims to make Klass's API for retrieving data easier to use by re-representing Klass's internal hierarchy as python-classes. Containing methods for easier traversal down, search classes and widgets, reasonable defaults to parameters etc.
55
+ Where data is possible to fit into pandas DataFrames, this will be preferred, but hiererachical data / objects containing metadata will be kept as json / dict structure.
56
+
57
+
58
+ ## Installing
59
+ The package is available on Pypi, and can be installed by for example poetry like this:
60
+ ```bash
61
+ poetry add ssb-klass-python
62
+ ```
63
+
64
+
65
+ ## Example usages
66
+
67
+
68
+ ### Getting started
69
+ ```python
70
+ from klass import search_classification
71
+ # Opens a ipywidget in notebooks for searching for classifications and copying code, to get started
72
+ search_classification(no_dupes=True)
73
+ ```
74
+ ![The GUI available through the search_classification function](GUI.png)
75
+
76
+
77
+
78
+ ### Getting a classification directly
79
+ ```python
80
+ from klass import get_classification # Import the utility-function
81
+ nus = get_classification(36)
82
+ ```
83
+
84
+ ```python
85
+ # Does the same as the code above, but does not shy away from using the class directly
86
+ from klass import KlassClassification # Import the class for KlassClassifications
87
+ nus = KlassClassification(36) # Use ID for classification
88
+ ```
89
+
90
+ When you have the classification stored in an object, you can "dig into" the API from there.
91
+ ```python
92
+ codes = nus.get_codes() # codes from current date
93
+ print(codes)
94
+ codes.data # Pandas dataframe available under the .data attribute
95
+ ```
96
+
97
+
98
+ From searching through "families", down to a specific codelist
99
+ ```python
100
+ from klass import KlassSearchFamilies
101
+ search = KlassSearchFamilies(360)
102
+ print(search)
103
+ >>> "Family ID: 20 - Utdanning - Number of classifications: 5"
104
+ utdanning = search.get_family(20)
105
+ print(utdanning)
106
+ >>> "The Klass Family "Utdanning" has id 20."
107
+ >>> "And contains the following classifications:"
108
+ >>> "36: Standard for utdanningsgruppering (NUS)"
109
+ nus = utdanning.get_classification(36)
110
+ print(nus)
111
+ >>> "Classification 36: Standard for utdanningsgruppering (NUS)..."
112
+ nus_codes = nus.get_codes("2023-01-01")
113
+ print(nus_codes)
114
+ >>> "Codelist for classification: 36"
115
+ >>> " From date: 2023-01-01"
116
+ nus_codes.data # A pandas dataframe
117
+ ```
118
+
119
+
120
+ For more examples check out the demo-notebooks in the demo/ folder in the repo.
121
+
122
+
123
+
124
+ ## Technical notes
125
+ Documentation for the [endpoints we are using can be found on Statistics Norways pages.](https://data.ssb.no/api/klass/v1/api-guide.html)
126
+
127
+ Technical architecture of the API we are interacting with is detailed in [Statistics Norway's **internal** wiki](https://wiki.ssb.no/display/KP/Teknisk+arkitektur#Tekniskarkitektur-GSIM).
128
+
129
+ This project has been migrated to follow the [SSB PyPI Template] from [Statistics Norway].
130
+
131
+ [statistics norway]: https://www.ssb.no/en
132
+ [pypi]: https://pypi.org/
133
+ [ssb pypi template]: https://github.com/statisticsnorway/ssb-pypitemplate
134
+ [file an issue]: https://github.com/statisticsnorway/ssb-klass-python/issues
135
+ [pip]: https://pip.pypa.io/
136
+
137
+ <!-- github-only -->
138
+
139
+ [license]: https://github.com/statisticsnorway/ssb-klass-python/blob/main/LICENSE
140
+ [contributor guide]: https://github.com/statisticsnorway/ssb-klass-python/blob/main/CONTRIBUTING.md
141
+ [reference guide]: https://statisticsnorway.github.io/ssb-klass-python/reference.html
142
+
@@ -0,0 +1,114 @@
1
+ # ssb-klass-python / KLASS
2
+ [![PyPI](https://img.shields.io/pypi/v/ssb-klass-python.svg)][pypi status]
3
+ [![Status](https://img.shields.io/pypi/status/ssb-klass-python.svg)][pypi status]
4
+ [![Python Version](https://img.shields.io/pypi/pyversions/ssb-klass-python)][pypi status]
5
+ [![License](https://img.shields.io/pypi/l/ssb-klass-python)][license]
6
+
7
+ [![Documentation](https://github.com/statisticsnorway/ssb-klass-python/actions/workflows/docs.yml/badge.svg)][documentation]
8
+ [![Tests](https://github.com/statisticsnorway/ssb-klass-python/actions/workflows/tests.yml/badge.svg)][tests]
9
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=statisticsnorway_ssb-klass-python&metric=coverage)][sonarcov]
10
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=statisticsnorway_ssb-klass-python&metric=alert_status)][sonarquality]
11
+
12
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)][pre-commit]
13
+ [![Black](https://img.shields.io/badge/code%20style-black-000000.svg)][black]
14
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
15
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)][poetry]
16
+
17
+ [pypi status]: https://pypi.org/project/ssb-klass-python/
18
+ [documentation]: https://statisticsnorway.github.io/ssb-klass-python
19
+ [tests]: https://github.com/statisticsnorway/ssb-klass-python/actions?workflow=Tests
20
+
21
+ [sonarcov]: https://sonarcloud.io/summary/overall?id=statisticsnorway_ssb-klass-python
22
+ [sonarquality]: https://sonarcloud.io/summary/overall?id=statisticsnorway_ssb-klass-python
23
+ [pre-commit]: https://github.com/pre-commit/pre-commit
24
+ [black]: https://github.com/psf/black
25
+ [poetry]: https://python-poetry.org/
26
+ A Python package built on top of Statistics Norway's code- and classification-system "KLASS". \
27
+ The package aims to make Klass's API for retrieving data easier to use by re-representing Klass's internal hierarchy as python-classes. Containing methods for easier traversal down, search classes and widgets, reasonable defaults to parameters etc.
28
+ Where data is possible to fit into pandas DataFrames, this will be preferred, but hiererachical data / objects containing metadata will be kept as json / dict structure.
29
+
30
+
31
+ ## Installing
32
+ The package is available on Pypi, and can be installed by for example poetry like this:
33
+ ```bash
34
+ poetry add ssb-klass-python
35
+ ```
36
+
37
+
38
+ ## Example usages
39
+
40
+
41
+ ### Getting started
42
+ ```python
43
+ from klass import search_classification
44
+ # Opens a ipywidget in notebooks for searching for classifications and copying code, to get started
45
+ search_classification(no_dupes=True)
46
+ ```
47
+ ![The GUI available through the search_classification function](GUI.png)
48
+
49
+
50
+
51
+ ### Getting a classification directly
52
+ ```python
53
+ from klass import get_classification # Import the utility-function
54
+ nus = get_classification(36)
55
+ ```
56
+
57
+ ```python
58
+ # Does the same as the code above, but does not shy away from using the class directly
59
+ from klass import KlassClassification # Import the class for KlassClassifications
60
+ nus = KlassClassification(36) # Use ID for classification
61
+ ```
62
+
63
+ When you have the classification stored in an object, you can "dig into" the API from there.
64
+ ```python
65
+ codes = nus.get_codes() # codes from current date
66
+ print(codes)
67
+ codes.data # Pandas dataframe available under the .data attribute
68
+ ```
69
+
70
+
71
+ From searching through "families", down to a specific codelist
72
+ ```python
73
+ from klass import KlassSearchFamilies
74
+ search = KlassSearchFamilies(360)
75
+ print(search)
76
+ >>> "Family ID: 20 - Utdanning - Number of classifications: 5"
77
+ utdanning = search.get_family(20)
78
+ print(utdanning)
79
+ >>> "The Klass Family "Utdanning" has id 20."
80
+ >>> "And contains the following classifications:"
81
+ >>> "36: Standard for utdanningsgruppering (NUS)"
82
+ nus = utdanning.get_classification(36)
83
+ print(nus)
84
+ >>> "Classification 36: Standard for utdanningsgruppering (NUS)..."
85
+ nus_codes = nus.get_codes("2023-01-01")
86
+ print(nus_codes)
87
+ >>> "Codelist for classification: 36"
88
+ >>> " From date: 2023-01-01"
89
+ nus_codes.data # A pandas dataframe
90
+ ```
91
+
92
+
93
+ For more examples check out the demo-notebooks in the demo/ folder in the repo.
94
+
95
+
96
+
97
+ ## Technical notes
98
+ Documentation for the [endpoints we are using can be found on Statistics Norways pages.](https://data.ssb.no/api/klass/v1/api-guide.html)
99
+
100
+ Technical architecture of the API we are interacting with is detailed in [Statistics Norway's **internal** wiki](https://wiki.ssb.no/display/KP/Teknisk+arkitektur#Tekniskarkitektur-GSIM).
101
+
102
+ This project has been migrated to follow the [SSB PyPI Template] from [Statistics Norway].
103
+
104
+ [statistics norway]: https://www.ssb.no/en
105
+ [pypi]: https://pypi.org/
106
+ [ssb pypi template]: https://github.com/statisticsnorway/ssb-pypitemplate
107
+ [file an issue]: https://github.com/statisticsnorway/ssb-klass-python/issues
108
+ [pip]: https://pip.pypa.io/
109
+
110
+ <!-- github-only -->
111
+
112
+ [license]: https://github.com/statisticsnorway/ssb-klass-python/blob/main/LICENSE
113
+ [contributor guide]: https://github.com/statisticsnorway/ssb-klass-python/blob/main/CONTRIBUTING.md
114
+ [reference guide]: https://statisticsnorway.github.io/ssb-klass-python/reference.html
@@ -0,0 +1,172 @@
1
+ [project]
2
+ name = "ssb-klass-python"
3
+ version = "1.0.3"
4
+ description = "A Python package built on top of KLASS's API for retrieving classifications, codes, correspondences etc."
5
+ authors = [{name="Carl Corneil", email="ssb-pythonistas <ssb-pythonistas@ssb.no>"}, {name = "Statistics Norway" }]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ requires-python = ">=3.11,<4"
9
+
10
+ dependencies = [
11
+ "python-dateutil >=2.8.2",
12
+ "toml >=0.10.2",
13
+ "ipywidgets >=8.0.6",
14
+ "pandas >=1.5.3",
15
+ "requests >=2.31.0",
16
+ "ipython <9",
17
+ "typing-extensions >=4.12.2",
18
+
19
+ ]
20
+
21
+ [project.urls]
22
+ homepage = "https://github.com/statisticsnorway/ssb-klass-python"
23
+ repository = "https://github.com/statisticsnorway/ssb-klass-python"
24
+ documentation = "https://statisticsnorway.github.io/ssb-klass-python"
25
+
26
+
27
+ [tool.poetry]
28
+ packages = [{ include = "klass", from = "src" }]
29
+ classifiers = ["Development Status :: 4 - Beta"]
30
+ requires-poetry = ">=2.0"
31
+
32
+ [tool.poetry.urls]
33
+ Changelog = "https://github.com/statisticsnorway/ssb-klass-python/releases"
34
+
35
+
36
+
37
+ [tool.poetry.group.dev.dependencies]
38
+ pygments = ">=2.10.0"
39
+ black = { extras = ["jupyter"], version = ">=24.3.0" }
40
+ coverage = { extras = ["toml"], version = ">=6.2" }
41
+ darglint = ">=1.8.1"
42
+ furo = ">=2021.11.12"
43
+ mypy = ">=0.930"
44
+ ipykernel = ">=6.15.3"
45
+ pre-commit = ">=2.20.0"
46
+ pre-commit-hooks = ">=4.4.0"
47
+ pytest = ">=6.2.5"
48
+ pytest-cov = ">=4.0.0"
49
+ pyproject-flake8 = ">=5.0.4.post1"
50
+ nox = ">=2023.4.22"
51
+ nox-poetry = ">=1.0.3"
52
+ ruff = ">=0.0.284"
53
+ sphinx = ">=6.2.1"
54
+ sphinx-autobuild = ">=2021.3.14"
55
+ sphinx-autodoc-typehints = ">=1.24.0"
56
+ sphinx-click = ">=3.0.2"
57
+ typeguard = ">=2.13.3"
58
+ xdoctest = { extras = ["colors"], version = ">=0.15.10" }
59
+ myst-parser = { version = ">=0.16.1" }
60
+ deptry = ">=0.23.0"
61
+ # Stubs for Mypy
62
+ pandas-stubs = ">=2.1.1.230928"
63
+ types-requests = ">=2.31.0.10"
64
+ types-python-dateutil = ">=2.8.19.14"
65
+ types-toml = ">=0.10.8.7"
66
+
67
+ [tool.pytest.ini_options]
68
+ pythonpath = ["src"]
69
+
70
+
71
+ [tool.coverage.paths]
72
+ source = ["src", "*/site-packages"]
73
+ tests = ["tests", "*/tests"]
74
+
75
+ [tool.coverage.run]
76
+ branch = true
77
+ source = ["klass", "tests"]
78
+ relative_files = true
79
+
80
+ [tool.coverage.report]
81
+ show_missing = true
82
+ fail_under = 50
83
+
84
+ [tool.mypy]
85
+ strict = true
86
+ warn_unreachable = true
87
+ pretty = true
88
+ show_column_numbers = true
89
+ show_error_context = true
90
+ exclude = ["tests", "docs", "noxfile.py"]
91
+ explicit_package_bases = true
92
+
93
+ [[tool.mypy.overrides]]
94
+ module = ["ipywidgets.*", "argcomplete.*"]
95
+ ignore_missing_imports = true
96
+
97
+ [tool.ruff]
98
+ force-exclude = true # Apply excludes to pre-commit
99
+ show-fixes = true
100
+ src = ["src", "tests"]
101
+ target-version = "py310" # Minimum Python version supported
102
+
103
+ include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"]
104
+ extend-exclude = [
105
+ "__pycache__",
106
+ "old",
107
+ ".ipynb_checkpoints",
108
+ "noxfile.py",
109
+ "docs/conf.py",
110
+ ]
111
+
112
+ # Ruff rules may be customized as desired: https://docs.astral.sh/ruff/rules/
113
+ [tool.ruff.lint]
114
+ select = [
115
+ "A", # prevent using keywords that clobber python builtins
116
+ "ANN", # check type annotations
117
+ "B", # bugbear: security warnings
118
+ "D", # documentation
119
+ "E", # pycodestyle
120
+ "F", # pyflakes
121
+ "ISC", # implicit string concatenation
122
+ "I", # sort imports
123
+ "UP", # alert you when better syntax is available in your python version
124
+ "RUF", # the ruff developer's own rules
125
+ ]
126
+ ignore = [
127
+ "ANN202", # Don't requiere return type annotation for private functions.
128
+ "ANN401", # Allow type annotation with type Any.
129
+ "D100", # Supress undocumented-public-module. Only doc of public api required.
130
+ "E402", # Supress module-import-not-at-top-of-file, needed in jupyter notebooks.
131
+ "E501", # Supress line-too-long warnings: trust black's judgement on this one.
132
+ ]
133
+
134
+ [tool.ruff.lint.isort]
135
+ force-single-line = true
136
+
137
+ [tool.ruff.lint.mccabe]
138
+ max-complexity = 15
139
+
140
+ [tool.ruff.lint.pydocstyle]
141
+ convention = "google" # You can also use "numpy".
142
+
143
+ [tool.ruff.lint.pep8-naming]
144
+ classmethod-decorators = [
145
+ "classmethod",
146
+ "validator",
147
+ "root_validator",
148
+ "pydantic.validator",
149
+ ]
150
+
151
+ [tool.ruff.lint.per-file-ignores]
152
+ "*/__init__.py" = ["F401"]
153
+ "**/tests/*" = [
154
+ "ANN001", # type annotations don't add value for test functions
155
+ "ANN002", # type annotations don't add value for test functions
156
+ "ANN003", # type annotations don't add value for test functions
157
+ "ANN201", # type annotations don't add value for test functions
158
+ "ANN204", # type annotations don't add value for test functions
159
+ "ANN205", # type annotations don't add value for test functions
160
+ "ANN206", # type annotations don't add value for test functions
161
+ "D100", # docstrings are overkill for test functions
162
+ "D101",
163
+ "D102",
164
+ "D103",
165
+ "D100",
166
+ "S101", # asserts are encouraged in pytest
167
+ ]
168
+ "demo/*.py" = ["B018"] # Ignore the useless expressions in the notebooks
169
+
170
+ [build-system]
171
+ requires = ["poetry-core>=1.0.0"]
172
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,97 @@
1
+ """A Python package built on top of Statistics Norway's code- and classification-system "KLASS".
2
+
3
+ The package aims to make Klass's API for retrieving data easier to use by re-representing Klass's internal hierarchy as python-classes.
4
+ Containing methods for easier traversal down, search classes and widgets, reasonable defaults to parameters etc.
5
+ Where data is possible to fit into pandas DataFrames, this will be preferred, but hirerachical data will be kept as json / dict structure.
6
+ """
7
+
8
+ import importlib
9
+ import importlib.metadata
10
+
11
+ import toml
12
+
13
+
14
+ def _try_getting_pyproject_toml(e: Exception | None = None) -> str:
15
+ if e is None:
16
+ passed_excep: Exception = Exception("")
17
+ else:
18
+ passed_excep = e
19
+ try:
20
+ version: str = toml.load("pyproject.toml")["tool"]["poetry"]["version"]
21
+ return version
22
+ except Exception as e:
23
+ version_missing: str = "0.0.0"
24
+ print(
25
+ f"Error from ssb-klass-pythons __init__, not able to get version-number, setting it to {version_missing}: {passed_excep}"
26
+ )
27
+ return version_missing
28
+
29
+
30
+ # Gets the installed version from pyproject.toml, then there is no need to update this file
31
+ try:
32
+ __version__ = importlib.metadata.version("ssb-klass-python")
33
+ except importlib.metadata.PackageNotFoundError as e:
34
+ __version__ = _try_getting_pyproject_toml(e)
35
+
36
+
37
+ from klass.classes.classification import KlassClassification
38
+ from klass.classes.codes import KlassCodes
39
+ from klass.classes.correspondence import KlassCorrespondence
40
+ from klass.classes.family import KlassFamily
41
+ from klass.classes.search import KlassSearchClassifications
42
+ from klass.classes.search import KlassSearchFamilies
43
+ from klass.classes.variant import KlassVariant
44
+ from klass.classes.variant import KlassVariantSearchByName
45
+ from klass.classes.version import KlassVersion
46
+ from klass.requests.klass_requests import changes
47
+ from klass.requests.klass_requests import classification_by_id
48
+ from klass.requests.klass_requests import classification_search
49
+ from klass.requests.klass_requests import classificationfamilies
50
+ from klass.requests.klass_requests import classificationfamilies_by_id
51
+ from klass.requests.klass_requests import classifications
52
+ from klass.requests.klass_requests import codes
53
+ from klass.requests.klass_requests import codes_at
54
+ from klass.requests.klass_requests import correspondence_table_by_id
55
+ from klass.requests.klass_requests import corresponds
56
+ from klass.requests.klass_requests import corresponds_at
57
+ from klass.requests.klass_requests import variant
58
+ from klass.requests.klass_requests import variant_at
59
+ from klass.requests.klass_requests import variants_by_id
60
+ from klass.requests.klass_requests import version_by_id
61
+ from klass.requests.sections import sections_dict
62
+ from klass.requests.sections import sections_list
63
+ from klass.utility.classification import get_classification
64
+ from klass.utility.codes import get_codes
65
+ from klass.widgets.search_ipywidget import search_classification
66
+
67
+ __all__ = [
68
+ "KlassClassification",
69
+ "KlassCodes",
70
+ "KlassCorrespondence",
71
+ "KlassFamily",
72
+ "KlassSearchClassifications",
73
+ "KlassSearchFamilies",
74
+ "KlassVariant",
75
+ "KlassVariantSearchByName",
76
+ "KlassVersion",
77
+ "changes",
78
+ "classification_by_id",
79
+ "classification_search",
80
+ "classificationfamilies",
81
+ "classificationfamilies_by_id",
82
+ "classifications",
83
+ "codes",
84
+ "codes_at",
85
+ "correspondence_table_by_id",
86
+ "corresponds",
87
+ "corresponds_at",
88
+ "get_classification",
89
+ "get_codes",
90
+ "search_classification",
91
+ "sections_dict",
92
+ "sections_list",
93
+ "variant",
94
+ "variant_at",
95
+ "variants_by_id",
96
+ "version_by_id",
97
+ ]
@@ -0,0 +1,9 @@
1
+ """The classes sub-module contains the actual classes the user should interact with.
2
+
3
+ They call loose get-request-functions in the requests-module under initialization.
4
+ Populating their attributes with metadata and data.
5
+ Traversing down through a hierarchy of Family > Classification > Version (classification at time) > Codelist is possible.
6
+ Traversing upwards is harder, as the API does not refer to parents of objects (would be nice if it did).
7
+ You can also traverse sideways to "correspondences" which exist as edge-objects between two classification-versions.
8
+ And get "variants", which are "alternative groupings" of codelists, belonging to versions.
9
+ """