klass.requests package

klass.requests.klass_requests module

changes(classification_id, from_date, to_date='', language='nb', include_future=False)

Get from the classifications/changes-endpoint.

Return type:

DataFrame

Parameters:
  • classification_id (str)

  • from_date (str)

  • to_date (str)

  • language (str)

  • include_future (bool)

classification_by_id(classification_id, language='nb', include_future=False)

Get from the classification-by-id-endpoint.

Return type:

ClassificationsByIdType

Parameters:
  • classification_id (str)

  • language (str)

  • include_future (bool)

Get from the classification/search-endpoint.

Return type:

ClassificationSearchType

Parameters:
  • query (str)

  • include_codelists (bool)

  • ssbsection (str)

classificationfamilies(ssbsection='', include_codelists=False, language='nb')

Get from the classificationfamilies-endpoint.

Return type:

ClassificationFamiliesType

Parameters:
  • ssbsection (str)

  • include_codelists (bool)

  • language (str)

classificationfamilies_by_id(classificationfamily_id, ssbsection='', include_codelists=False, language='nb')

Get from the classificationsfamilies-endpoint with id.

Return type:

ClassificationFamiliesByIdType

Parameters:
  • classificationfamily_id (str)

  • ssbsection (str)

  • include_codelists (bool)

  • language (str)

classifications(include_codelists=False, changed_since='')

Get from the classifications-endpoint.

Return type:

ClassificationsType

Parameters:
  • include_codelists (bool)

  • changed_since (str)

codes(classification_id, from_date, to_date='', select_codes='', select_level='', presentation_name_pattern='', language='nb', include_future=False)

Get from the codes-endpoint.

Return type:

DataFrame

Parameters:
  • classification_id (str)

  • from_date (str)

  • to_date (str)

  • select_codes (str)

  • select_level (str)

  • presentation_name_pattern (str)

  • language (str)

  • include_future (bool)

codes_at(classification_id, date, select_codes='', select_level='', presentation_name_pattern='', language='nb', include_future=False)

Get from the codesAt-endpoint.

Return type:

DataFrame

Parameters:
  • classification_id (str)

  • date (str)

  • select_codes (str)

  • select_level (str)

  • presentation_name_pattern (str)

  • language (str)

  • include_future (bool)

convert_datestring(date, return_type='isoklass')

First try dateutil to guess the format of a simple time sent in, secondary try the fromisoformat.

Convert it to the expected string format of the API.

Return type:

str

Parameters:
  • date (str | datetime)

  • return_type (str)

convert_section(section)

Get the full section-name-string (that the API needs) from just a provided section-number/numeric string.

Return type:

str

Parameters:

section (str)

correspondence_table_by_id(correspondence_id, language='nb')

Get from the correspondence-table-by-id-endpoint.

Return type:

CorrespondenceTableIdType

Parameters:
  • correspondence_id (str)

  • language (str)

corresponds(source_classification_id, target_classification_id, from_date, to_date='', language='nb', include_future=False)

Get from the classifications/corresponds-endpoint.

Return type:

CorrespondsType

Parameters:
  • source_classification_id (str)

  • target_classification_id (str)

  • from_date (str)

  • to_date (str)

  • language (str)

  • include_future (bool)

corresponds_at(source_classification_id, target_classification_id, date, language='nb', include_future=False)

Get from the classificatins/correspondsAt-endpoint.

Return type:

CorrespondsType

Parameters:
  • source_classification_id (str)

  • target_classification_id (str)

  • date (str)

  • language (str)

  • include_future (bool)

get_json(url, params)

Simplify getting the JSON out of a GET request to the KLASS API.

Used in most of the following functions.

Parameters:
  • url (str) – The URL to the endpoint.

  • params (ParamsAfterType) – The parameters to send to the endpoint.

Returns:

The JSON response from the endpoint, hard to type because all endpoints have differently structured responses.

Return type:

Any

variant(classification_id, variant_name, from_date, to_date='', select_codes='', select_level='', presentation_name_pattern='', language='nb', include_future=False)

Get from the variant-endpoint.

Return type:

DataFrame

Parameters:
  • classification_id (str)

  • variant_name (str)

  • from_date (str)

  • to_date (str)

  • select_codes (str)

  • select_level (str)

  • presentation_name_pattern (str)

  • language (str)

  • include_future (bool)

variant_at(classification_id, variant_name, date, select_codes='', select_level='', presentation_name_pattern='', language='nb', include_future=False)

Get from the variantAt-endpoint.

Return type:

DataFrame

Parameters:
  • classification_id (str)

  • variant_name (str)

  • date (str)

  • select_codes (str)

  • select_level (str)

  • presentation_name_pattern (str)

  • language (str)

  • include_future (bool)

variants_by_id(variant_id, language='nb')

Get from the variants-endpoint.

Return type:

VariantsByIdType

Parameters:
  • variant_id (str)

  • language (str)

version_by_id(version_id, language='nb', include_future=False)

Get from the version-by-id-endpoint.

Return type:

VersionByIDType

Parameters:
  • version_id (str)

  • language (str)

  • include_future (bool)

klass.requests.sections module

sections_dict()

Reshape the section list to a dict, with section-numbers as keys.

Return type:

dict[str, str]

sections_list()

Get the sections that are registered in KLASS-api. Unlikely to change often, so we cache this.

Return type:

list[str]

klass.requests.validate module

validate_alnum_spaces(variant_name)

Except for some other special characters, should be all alpha-numeric.

Return type:

str

Parameters:

variant_name (str)

validate_bool(val)

Validate as a bool, then converts it to a lowercase string (required by API).

Return type:

str

Parameters:

val (bool)

validate_date(date)

Validate a date-string against the expected format.

Return type:

str

Parameters:

date (str)

validate_language(language)

Validate the language-string against possible languages from the config.

Return type:

str

Parameters:

language (str)

validate_params(params)

Links parameters to their validate-functions.

Return type:

ParamsAfterType

Parameters:

params (ParamsBeforeType)

validate_presentation_name_patterns(pattern)

Name patters must be alphanumeric, except for some special chars.

Return type:

str

Parameters:

pattern (str)

validate_select_codes(codestring)

Select codes should only contain numbers, and some special characters.

Return type:

str

Parameters:

codestring (str)

validate_ssb_section(section)

Check if the section sent in exists in the API.

Return type:

str

Parameters:

section (str)

validate_time_iso8601(datestring)

Validate date-string by checking against datetime format YYYY-MM-DDThh:mm:ss.SSS+00:00.

If no match, will try to convert it using dateutil.parser.parse to a datetime that includes milliseconds.

Return type:

str

Parameters:

datestring (str)

validate_whole_number(level)

Check that string is an int.

Return type:

str

Parameters:

level (str)