Skip to main content

A Python package built on top of KLASS's API for retrieving classifications, codes, correspondences etc.

Project description

ssb-klass-python / KLASS

PyPI Status Python Version License

Documentation Tests Coverage Quality Gate Status

pre-commit Black Ruff Poetry

A Python package built on top of Statistics Norway's code- and classification-system "KLASS".
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. 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.

Installing

The package is available on Pypi, and can be installed by for example poetry like this:

poetry add ssb-klass-python

Example usages

Getting started

from klass import search_classification
# Opens a ipywidget in notebooks for searching for classifications and copying code, to get started
search_classification(no_dupes=True)

The GUI available through the search_classification function

Getting a classification directly

from klass import get_classification # Import the utility-function
nus = get_classification(36)
# Does the same as the code above, but does not shy away from using the class directly
from klass import KlassClassification # Import the class for KlassClassifications
nus = KlassClassification(36)  # Use ID for classification

When you have the classification stored in an object, you can "dig into" the API from there.

codes = nus.get_codes() # codes from current date
print(codes)
codes.data  # Pandas dataframe available under the .data attribute

From searching through "families", down to a specific codelist

from klass import KlassSearchFamilies
search = KlassSearchFamilies(360)
print(search)
>>> "Family ID: 20 - Utdanning - Number of classifications: 5"
utdanning = search.get_family(20)
print(utdanning)
>>> "The Klass Family "Utdanning" has id 20."
>>> "And contains the following classifications:"
>>>  "36: Standard for utdanningsgruppering (NUS)"
nus = utdanning.get_classification(36)
print(nus)
>>> "Classification 36: Standard for utdanningsgruppering (NUS)..."
nus_codes = nus.get_codes("2023-01-01")
print(nus_codes)
>>> "Codelist for classification: 36"
>>> " From date: 2023-01-01"
nus_codes.data  # A pandas dataframe

For more examples check out the demo-notebooks in the demo/ folder in the repo.

Technical notes

Documentation for the endpoints we are using can be found on Statistics Norways pages.

Technical architecture of the API we are interacting with is detailed in Statistics Norway's internal wiki.

This project has been migrated to follow the SSB PyPI Template from Statistics Norway.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssb_klass_python-1.0.6.tar.gz (30.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ssb_klass_python-1.0.6-py3-none-any.whl (38.0 kB view details)

Uploaded Python 3

File details

Details for the file ssb_klass_python-1.0.6.tar.gz.

File metadata

  • Download URL: ssb_klass_python-1.0.6.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ssb_klass_python-1.0.6.tar.gz
Algorithm Hash digest
SHA256 2532e53da27a8afad5f4fc1e2fe894b03e37057481f017a300721b0671871935
MD5 cd9e973353b24c74422a9ada7e332021
BLAKE2b-256 a7420a8062f359bc01b0f82f8d262ba14712124ead05ba1e829d9b1865a04814

See more details on using hashes here.

Provenance

The following attestation bundles were made for ssb_klass_python-1.0.6.tar.gz:

Publisher: release.yml on statisticsnorway/ssb-klass-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ssb_klass_python-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for ssb_klass_python-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0c91683c6b9b1e902b0317db04c819e42dd5ce4fab8c351921b07afca3b5b355
MD5 59af17103c3c225e0dbae699d5fe63e1
BLAKE2b-256 f76941307a5c103cc7d93dd0c66b20e00cf3b2ba8ebe00fa1dcbd26d23597d1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ssb_klass_python-1.0.6-py3-none-any.whl:

Publisher: release.yml on statisticsnorway/ssb-klass-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page