dapla-toolbelt-metadata 0.2.1__py3-none-any.whl → 0.9.11__py3-none-any.whl

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.

Potentially problematic release.


This version of dapla-toolbelt-metadata might be problematic. Click here for more details.

Files changed (97) hide show
  1. dapla_metadata/__init__.py +11 -1
  2. dapla_metadata/_shared/__init__.py +1 -0
  3. dapla_metadata/_shared/config.py +109 -0
  4. dapla_metadata/_shared/enums.py +27 -0
  5. dapla_metadata/_shared/py.typed +0 -0
  6. dapla_metadata/dapla/__init__.py +4 -0
  7. dapla_metadata/dapla/user_info.py +138 -0
  8. dapla_metadata/datasets/__init__.py +1 -1
  9. dapla_metadata/datasets/_merge.py +333 -0
  10. dapla_metadata/datasets/code_list.py +5 -6
  11. dapla_metadata/datasets/compatibility/__init__.py +10 -0
  12. dapla_metadata/datasets/compatibility/_handlers.py +363 -0
  13. dapla_metadata/datasets/compatibility/_utils.py +259 -0
  14. dapla_metadata/datasets/compatibility/model_backwards_compatibility.py +135 -0
  15. dapla_metadata/datasets/core.py +136 -182
  16. dapla_metadata/datasets/dapla_dataset_path_info.py +145 -19
  17. dapla_metadata/datasets/dataset_parser.py +41 -28
  18. dapla_metadata/datasets/model_validation.py +29 -20
  19. dapla_metadata/datasets/statistic_subject_mapping.py +5 -1
  20. dapla_metadata/datasets/utility/constants.py +22 -15
  21. dapla_metadata/datasets/utility/enums.py +8 -20
  22. dapla_metadata/datasets/utility/urn.py +234 -0
  23. dapla_metadata/datasets/utility/utils.py +183 -111
  24. dapla_metadata/standards/__init__.py +4 -0
  25. dapla_metadata/standards/name_validator.py +250 -0
  26. dapla_metadata/standards/standard_validators.py +98 -0
  27. dapla_metadata/standards/utils/__init__.py +1 -0
  28. dapla_metadata/standards/utils/constants.py +49 -0
  29. dapla_metadata/variable_definitions/__init__.py +11 -0
  30. dapla_metadata/variable_definitions/_generated/.openapi-generator/FILES +20 -0
  31. dapla_metadata/variable_definitions/_generated/.openapi-generator/VERSION +1 -0
  32. dapla_metadata/variable_definitions/_generated/.openapi-generator-ignore +6 -0
  33. dapla_metadata/variable_definitions/_generated/README.md +148 -0
  34. dapla_metadata/variable_definitions/_generated/__init__.py +0 -0
  35. dapla_metadata/variable_definitions/_generated/vardef_client/__init__.py +47 -0
  36. dapla_metadata/variable_definitions/_generated/vardef_client/api/__init__.py +8 -0
  37. dapla_metadata/variable_definitions/_generated/vardef_client/api/data_migration_api.py +766 -0
  38. dapla_metadata/variable_definitions/_generated/vardef_client/api/draft_variable_definitions_api.py +888 -0
  39. dapla_metadata/variable_definitions/_generated/vardef_client/api/patches_api.py +888 -0
  40. dapla_metadata/variable_definitions/_generated/vardef_client/api/validity_periods_api.py +583 -0
  41. dapla_metadata/variable_definitions/_generated/vardef_client/api/variable_definitions_api.py +613 -0
  42. dapla_metadata/variable_definitions/_generated/vardef_client/api_client.py +779 -0
  43. dapla_metadata/variable_definitions/_generated/vardef_client/api_response.py +27 -0
  44. dapla_metadata/variable_definitions/_generated/vardef_client/configuration.py +474 -0
  45. dapla_metadata/variable_definitions/_generated/vardef_client/docs/CompleteResponse.md +51 -0
  46. dapla_metadata/variable_definitions/_generated/vardef_client/docs/Contact.md +30 -0
  47. dapla_metadata/variable_definitions/_generated/vardef_client/docs/DataMigrationApi.md +90 -0
  48. dapla_metadata/variable_definitions/_generated/vardef_client/docs/Draft.md +42 -0
  49. dapla_metadata/variable_definitions/_generated/vardef_client/docs/DraftVariableDefinitionsApi.md +259 -0
  50. dapla_metadata/variable_definitions/_generated/vardef_client/docs/LanguageStringType.md +31 -0
  51. dapla_metadata/variable_definitions/_generated/vardef_client/docs/Owner.md +31 -0
  52. dapla_metadata/variable_definitions/_generated/vardef_client/docs/Patch.md +43 -0
  53. dapla_metadata/variable_definitions/_generated/vardef_client/docs/PatchesApi.md +249 -0
  54. dapla_metadata/variable_definitions/_generated/vardef_client/docs/PublicApi.md +218 -0
  55. dapla_metadata/variable_definitions/_generated/vardef_client/docs/SupportedLanguages.md +15 -0
  56. dapla_metadata/variable_definitions/_generated/vardef_client/docs/UpdateDraft.md +44 -0
  57. dapla_metadata/variable_definitions/_generated/vardef_client/docs/ValidityPeriod.md +42 -0
  58. dapla_metadata/variable_definitions/_generated/vardef_client/docs/ValidityPeriodsApi.md +236 -0
  59. dapla_metadata/variable_definitions/_generated/vardef_client/docs/VariableDefinitionsApi.md +304 -0
  60. dapla_metadata/variable_definitions/_generated/vardef_client/docs/VariableStatus.md +17 -0
  61. dapla_metadata/variable_definitions/_generated/vardef_client/exceptions.py +193 -0
  62. dapla_metadata/variable_definitions/_generated/vardef_client/models/__init__.py +31 -0
  63. dapla_metadata/variable_definitions/_generated/vardef_client/models/complete_response.py +260 -0
  64. dapla_metadata/variable_definitions/_generated/vardef_client/models/contact.py +94 -0
  65. dapla_metadata/variable_definitions/_generated/vardef_client/models/draft.py +228 -0
  66. dapla_metadata/variable_definitions/_generated/vardef_client/models/get_vardok_vardef_mapping_by_id200_response.py +158 -0
  67. dapla_metadata/variable_definitions/_generated/vardef_client/models/language_string_type.py +101 -0
  68. dapla_metadata/variable_definitions/_generated/vardef_client/models/owner.py +87 -0
  69. dapla_metadata/variable_definitions/_generated/vardef_client/models/patch.py +244 -0
  70. dapla_metadata/variable_definitions/_generated/vardef_client/models/problem.py +118 -0
  71. dapla_metadata/variable_definitions/_generated/vardef_client/models/update_draft.py +274 -0
  72. dapla_metadata/variable_definitions/_generated/vardef_client/models/validity_period.py +225 -0
  73. dapla_metadata/variable_definitions/_generated/vardef_client/models/vardok_id_response.py +81 -0
  74. dapla_metadata/variable_definitions/_generated/vardef_client/models/vardok_vardef_id_pair_response.py +84 -0
  75. dapla_metadata/variable_definitions/_generated/vardef_client/models/variable_status.py +33 -0
  76. dapla_metadata/variable_definitions/_generated/vardef_client/py.typed +0 -0
  77. dapla_metadata/variable_definitions/_generated/vardef_client/rest.py +249 -0
  78. dapla_metadata/variable_definitions/_utils/__init__.py +1 -0
  79. dapla_metadata/variable_definitions/_utils/_client.py +32 -0
  80. dapla_metadata/variable_definitions/_utils/config.py +54 -0
  81. dapla_metadata/variable_definitions/_utils/constants.py +80 -0
  82. dapla_metadata/variable_definitions/_utils/files.py +309 -0
  83. dapla_metadata/variable_definitions/_utils/template_files.py +99 -0
  84. dapla_metadata/variable_definitions/_utils/variable_definition_files.py +143 -0
  85. dapla_metadata/variable_definitions/exceptions.py +255 -0
  86. dapla_metadata/variable_definitions/vardef.py +372 -0
  87. dapla_metadata/variable_definitions/vardok_id.py +48 -0
  88. dapla_metadata/variable_definitions/vardok_vardef_id_pair.py +47 -0
  89. dapla_metadata/variable_definitions/variable_definition.py +422 -0
  90. {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info}/METADATA +34 -36
  91. dapla_toolbelt_metadata-0.9.11.dist-info/RECORD +97 -0
  92. {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info}/WHEEL +1 -1
  93. dapla_metadata/datasets/config.py +0 -80
  94. dapla_metadata/datasets/model_backwards_compatibility.py +0 -520
  95. dapla_metadata/datasets/user_info.py +0 -88
  96. dapla_toolbelt_metadata-0.2.1.dist-info/RECORD +0 -22
  97. {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,158 @@
1
+ """Internal Variable Definitions Administration API
2
+
3
+ ## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
4
+
5
+ The version of the OpenAPI document: 0.1
6
+ Contact: metadata@ssb.no
7
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
8
+
9
+ Do not edit the class manually.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import pprint
16
+ from typing import Any
17
+
18
+ from pydantic import BaseModel
19
+ from pydantic import ConfigDict
20
+ from pydantic import ValidationError
21
+ from pydantic import field_validator
22
+ from typing_extensions import Self
23
+
24
+ from ..models.complete_response import CompleteResponse
25
+ from ..models.vardok_id_response import VardokIdResponse
26
+
27
+ GETVARDOKVARDEFMAPPINGBYID200RESPONSE_ONE_OF_SCHEMAS = [
28
+ "CompleteResponse",
29
+ "VardokIdResponse",
30
+ ]
31
+
32
+
33
+ class GetVardokVardefMappingById200Response(BaseModel):
34
+ """GetVardokVardefMappingById200Response"""
35
+
36
+ # data type: CompleteResponse
37
+ oneof_schema_1_validator: CompleteResponse | None = None
38
+ # data type: VardokIdResponse
39
+ oneof_schema_2_validator: VardokIdResponse | None = None
40
+ actual_instance: CompleteResponse | VardokIdResponse | None = None
41
+ one_of_schemas: set[str] = {"CompleteResponse", "VardokIdResponse"}
42
+
43
+ model_config = ConfigDict(
44
+ validate_assignment=True,
45
+ protected_namespaces=(),
46
+ )
47
+
48
+ def __init__(self, *args, **kwargs) -> None:
49
+ if args:
50
+ if len(args) > 1:
51
+ raise ValueError(
52
+ "If a position argument is used, only 1 is allowed to set `actual_instance`"
53
+ )
54
+ if kwargs:
55
+ raise ValueError(
56
+ "If a position argument is used, keyword arguments cannot be used."
57
+ )
58
+ super().__init__(actual_instance=args[0])
59
+ else:
60
+ super().__init__(**kwargs)
61
+
62
+ @field_validator("actual_instance")
63
+ def actual_instance_must_validate_oneof(cls, v):
64
+ instance = GetVardokVardefMappingById200Response.model_construct()
65
+ error_messages = []
66
+ match = 0
67
+ # validate data type: CompleteResponse
68
+ if not isinstance(v, CompleteResponse):
69
+ error_messages.append(
70
+ f"Error! Input type `{type(v)}` is not `CompleteResponse`"
71
+ )
72
+ else:
73
+ match += 1
74
+ # validate data type: VardokIdResponse
75
+ if not isinstance(v, VardokIdResponse):
76
+ error_messages.append(
77
+ f"Error! Input type `{type(v)}` is not `VardokIdResponse`"
78
+ )
79
+ else:
80
+ match += 1
81
+ if match > 1:
82
+ # more than 1 match
83
+ raise ValueError(
84
+ "Multiple matches found when setting `actual_instance` in GetVardokVardefMappingById200Response with oneOf schemas: CompleteResponse, VardokIdResponse. Details: "
85
+ + ", ".join(error_messages)
86
+ )
87
+ if match == 0:
88
+ # no match
89
+ raise ValueError(
90
+ "No match found when setting `actual_instance` in GetVardokVardefMappingById200Response with oneOf schemas: CompleteResponse, VardokIdResponse. Details: "
91
+ + ", ".join(error_messages)
92
+ )
93
+ return v
94
+
95
+ @classmethod
96
+ def from_dict(cls, obj: str | dict[str, Any]) -> Self:
97
+ return cls.from_json(json.dumps(obj))
98
+
99
+ @classmethod
100
+ def from_json(cls, json_str: str) -> Self:
101
+ """Returns the object represented by the json string"""
102
+ instance = cls.model_construct()
103
+ error_messages = []
104
+ match = 0
105
+
106
+ # deserialize data into CompleteResponse
107
+ try:
108
+ instance.actual_instance = CompleteResponse.from_json(json_str)
109
+ match += 1
110
+ except (ValidationError, ValueError) as e:
111
+ error_messages.append(str(e))
112
+ # deserialize data into VardokIdResponse
113
+ try:
114
+ instance.actual_instance = VardokIdResponse.from_json(json_str)
115
+ match += 1
116
+ except (ValidationError, ValueError) as e:
117
+ error_messages.append(str(e))
118
+
119
+ if match > 1:
120
+ # more than 1 match
121
+ raise ValueError(
122
+ "Multiple matches found when deserializing the JSON string into GetVardokVardefMappingById200Response with oneOf schemas: CompleteResponse, VardokIdResponse. Details: "
123
+ + ", ".join(error_messages)
124
+ )
125
+ if match == 0:
126
+ # no match
127
+ raise ValueError(
128
+ "No match found when deserializing the JSON string into GetVardokVardefMappingById200Response with oneOf schemas: CompleteResponse, VardokIdResponse. Details: "
129
+ + ", ".join(error_messages)
130
+ )
131
+ return instance
132
+
133
+ def to_json(self) -> str:
134
+ """Returns the JSON representation of the actual instance"""
135
+ if self.actual_instance is None:
136
+ return "null"
137
+
138
+ if hasattr(self.actual_instance, "to_json") and callable(
139
+ self.actual_instance.to_json
140
+ ):
141
+ return self.actual_instance.to_json()
142
+ return json.dumps(self.actual_instance)
143
+
144
+ def to_dict(self) -> dict[str, Any] | CompleteResponse | VardokIdResponse | None:
145
+ """Returns the dict representation of the actual instance"""
146
+ if self.actual_instance is None:
147
+ return None
148
+
149
+ if hasattr(self.actual_instance, "to_dict") and callable(
150
+ self.actual_instance.to_dict
151
+ ):
152
+ return self.actual_instance.to_dict()
153
+ # primitive type
154
+ return self.actual_instance
155
+
156
+ def to_str(self) -> str:
157
+ """Returns the string representation of the actual instance"""
158
+ return pprint.pformat(self.model_dump())
@@ -0,0 +1,101 @@
1
+ """Internal Variable Definitions Administration API
2
+
3
+ ## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
4
+
5
+ The version of the OpenAPI document: 0.1
6
+ Contact: metadata@ssb.no
7
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
8
+
9
+ Do not edit the class manually.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import pprint
16
+ import re # noqa: F401
17
+ from typing import Any
18
+ from typing import ClassVar
19
+
20
+ from pydantic import BaseModel
21
+ from pydantic import ConfigDict
22
+ from pydantic import Field
23
+ from pydantic import StrictStr
24
+ from typing_extensions import Self
25
+
26
+
27
+ class LanguageStringType(BaseModel):
28
+ """Language string type Represents one text, with translations for the languages in \\[SupportedLanguages\\]. All fields are nullable to allow for flexibility for maintainers."""
29
+
30
+ nb: StrictStr | None = Field(default=None, description="Norwegian Bokmål")
31
+ nn: StrictStr | None = Field(default=None, description="Norwegian Nynorsk")
32
+ en: StrictStr | None = Field(default=None, description="English")
33
+ __properties: ClassVar[list[str]] = ["nb", "nn", "en"]
34
+
35
+ model_config = ConfigDict(
36
+ populate_by_name=True,
37
+ validate_assignment=True,
38
+ protected_namespaces=(),
39
+ )
40
+
41
+ def to_str(self) -> str:
42
+ """Returns the string representation of the model using alias"""
43
+ return pprint.pformat(self.model_dump(by_alias=True))
44
+
45
+ def to_json(self) -> str:
46
+ """Returns the JSON representation of the model using alias"""
47
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
48
+ return json.dumps(self.to_dict())
49
+
50
+ @classmethod
51
+ def from_json(cls, json_str: str) -> Self | None:
52
+ """Create an instance of LanguageStringType from a JSON string"""
53
+ return cls.from_dict(json.loads(json_str))
54
+
55
+ def to_dict(self) -> dict[str, Any]:
56
+ """Return the dictionary representation of the model using alias.
57
+
58
+ This has the following differences from calling pydantic's
59
+ `self.model_dump(by_alias=True)`:
60
+
61
+ * `None` is only added to the output dict for nullable fields that
62
+ were set at model initialization. Other fields with value `None`
63
+ are ignored.
64
+ """
65
+ excluded_fields: set[str] = set([])
66
+
67
+ _dict = self.model_dump(
68
+ by_alias=True,
69
+ exclude=excluded_fields,
70
+ exclude_none=True,
71
+ )
72
+ # set to None if nb (nullable) is None
73
+ # and model_fields_set contains the field
74
+ if self.nb is None and "nb" in self.model_fields_set:
75
+ _dict["nb"] = None
76
+
77
+ # set to None if nn (nullable) is None
78
+ # and model_fields_set contains the field
79
+ if self.nn is None and "nn" in self.model_fields_set:
80
+ _dict["nn"] = None
81
+
82
+ # set to None if en (nullable) is None
83
+ # and model_fields_set contains the field
84
+ if self.en is None and "en" in self.model_fields_set:
85
+ _dict["en"] = None
86
+
87
+ return _dict
88
+
89
+ @classmethod
90
+ def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
91
+ """Create an instance of LanguageStringType from a dict"""
92
+ if obj is None:
93
+ return None
94
+
95
+ if not isinstance(obj, dict):
96
+ return cls.model_validate(obj)
97
+
98
+ _obj = cls.model_validate(
99
+ {"nb": obj.get("nb"), "nn": obj.get("nn"), "en": obj.get("en")}
100
+ )
101
+ return _obj
@@ -0,0 +1,87 @@
1
+ """Internal Variable Definitions Administration API
2
+
3
+ ## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
4
+
5
+ The version of the OpenAPI document: 0.1
6
+ Contact: metadata@ssb.no
7
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
8
+
9
+ Do not edit the class manually.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import pprint
16
+ import re # noqa: F401
17
+ from typing import Annotated
18
+ from typing import Any
19
+ from typing import ClassVar
20
+
21
+ from pydantic import BaseModel
22
+ from pydantic import ConfigDict
23
+ from pydantic import Field
24
+ from typing_extensions import Self
25
+
26
+
27
+ class Owner(BaseModel):
28
+ """Owner"""
29
+
30
+ team: Annotated[str, Field(min_length=1, strict=True)]
31
+ groups: Annotated[
32
+ list[Annotated[str, Field(min_length=1, strict=True)]], Field(min_length=1)
33
+ ]
34
+ __properties: ClassVar[list[str]] = ["team", "groups"]
35
+
36
+ model_config = ConfigDict(
37
+ populate_by_name=True,
38
+ validate_assignment=True,
39
+ protected_namespaces=(),
40
+ )
41
+
42
+ def to_str(self) -> str:
43
+ """Returns the string representation of the model using alias"""
44
+ return pprint.pformat(self.model_dump(by_alias=True))
45
+
46
+ def to_json(self) -> str:
47
+ """Returns the JSON representation of the model using alias"""
48
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49
+ return json.dumps(self.to_dict())
50
+
51
+ @classmethod
52
+ def from_json(cls, json_str: str) -> Self | None:
53
+ """Create an instance of Owner from a JSON string"""
54
+ return cls.from_dict(json.loads(json_str))
55
+
56
+ def to_dict(self) -> dict[str, Any]:
57
+ """Return the dictionary representation of the model using alias.
58
+
59
+ This has the following differences from calling pydantic's
60
+ `self.model_dump(by_alias=True)`:
61
+
62
+ * `None` is only added to the output dict for nullable fields that
63
+ were set at model initialization. Other fields with value `None`
64
+ are ignored.
65
+ """
66
+ excluded_fields: set[str] = set([])
67
+
68
+ _dict = self.model_dump(
69
+ by_alias=True,
70
+ exclude=excluded_fields,
71
+ exclude_none=True,
72
+ )
73
+ return _dict
74
+
75
+ @classmethod
76
+ def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
77
+ """Create an instance of Owner from a dict"""
78
+ if obj is None:
79
+ return None
80
+
81
+ if not isinstance(obj, dict):
82
+ return cls.model_validate(obj)
83
+
84
+ _obj = cls.model_validate(
85
+ {"team": obj.get("team"), "groups": obj.get("groups")}
86
+ )
87
+ return _obj
@@ -0,0 +1,244 @@
1
+ """Internal Variable Definitions Administration API
2
+
3
+ ## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
4
+
5
+ The version of the OpenAPI document: 0.1
6
+ Contact: metadata@ssb.no
7
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
8
+
9
+ Do not edit the class manually.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import pprint
16
+ import re # noqa: F401
17
+ from datetime import date
18
+ from typing import Annotated
19
+ from typing import Any
20
+ from typing import ClassVar
21
+
22
+ from pydantic import BaseModel
23
+ from pydantic import ConfigDict
24
+ from pydantic import Field
25
+ from pydantic import StrictBool
26
+ from pydantic import StrictStr
27
+ from typing_extensions import Self
28
+
29
+ from ..models.contact import Contact
30
+ from ..models.language_string_type import LanguageStringType
31
+ from ..models.owner import Owner
32
+ from ..models.variable_status import VariableStatus
33
+
34
+
35
+ class Patch(BaseModel):
36
+ """Create a new Patch version on a Published Variable Definition."""
37
+
38
+ name: LanguageStringType | None = None
39
+ definition: LanguageStringType | None = None
40
+ classification_reference: StrictStr | None = Field(
41
+ default=None,
42
+ description="ID of a classification or code list from Klass. The given classification defines all possible values for the defined variable.",
43
+ )
44
+ unit_types: list[Annotated[str, Field(min_length=1, strict=True)]] | None = Field(
45
+ default=None,
46
+ description="A list of one or more unit types, e.g. person, vehicle, household. Must be defined as codes from https://www.ssb.no/klass/klassifikasjoner/702.",
47
+ )
48
+ subject_fields: list[Annotated[str, Field(min_length=1, strict=True)]] | None = (
49
+ Field(
50
+ default=None,
51
+ description="A list of subject fields that the variable is used in. Must be defined as codes from https://www.ssb.no/klass/klassifikasjoner/618.",
52
+ )
53
+ )
54
+ contains_special_categories_of_personal_data: StrictBool | None = Field(
55
+ default=None,
56
+ description="True if variable instances contain particularly sensitive information. Applies even if the information or identifiers are pseudonymized. Information within the following categories are regarded as particularly sensitive: Ethnicity, Political alignment, Religion, Philosophical beliefs, Union membership, Genetics, Biometrics, Health, Sexual relations, Sexual orientation",
57
+ )
58
+ variable_status: VariableStatus | None = None
59
+ measurement_type: StrictStr | None = Field(
60
+ default=None,
61
+ description="Type of measurement for the variable, e.g. length, volume, currency. Must be defined as codes from https://www.ssb.no/klass/klassifikasjoner/303",
62
+ )
63
+ valid_until: date | None = Field(
64
+ default=None,
65
+ description="The variable definition is valid until this date inclusive",
66
+ )
67
+ external_reference_uri: StrictStr | None = Field(
68
+ default=None, description="A link (URI) to an external definition/documentation"
69
+ )
70
+ comment: LanguageStringType | None = None
71
+ related_variable_definition_uris: list[StrictStr] | None = Field(
72
+ default=None,
73
+ description="Link(s) to related definitions of variables - a list of one or more definitions. For example for a variable after-tax income it could be relevant to link to definitions of income from work, property income etc.",
74
+ )
75
+ owner: Owner | None = None
76
+ contact: Contact | None = None
77
+ __properties: ClassVar[list[str]] = [
78
+ "name",
79
+ "definition",
80
+ "classification_reference",
81
+ "unit_types",
82
+ "subject_fields",
83
+ "contains_special_categories_of_personal_data",
84
+ "variable_status",
85
+ "measurement_type",
86
+ "valid_until",
87
+ "external_reference_uri",
88
+ "comment",
89
+ "related_variable_definition_uris",
90
+ "owner",
91
+ "contact",
92
+ ]
93
+
94
+ model_config = ConfigDict(
95
+ populate_by_name=True,
96
+ validate_assignment=True,
97
+ protected_namespaces=(),
98
+ )
99
+
100
+ def to_str(self) -> str:
101
+ """Returns the string representation of the model using alias"""
102
+ return pprint.pformat(self.model_dump(by_alias=True))
103
+
104
+ def to_json(self) -> str:
105
+ """Returns the JSON representation of the model using alias"""
106
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
107
+ return json.dumps(self.to_dict())
108
+
109
+ @classmethod
110
+ def from_json(cls, json_str: str) -> Self | None:
111
+ """Create an instance of Patch from a JSON string"""
112
+ return cls.from_dict(json.loads(json_str))
113
+
114
+ def to_dict(self) -> dict[str, Any]:
115
+ """Return the dictionary representation of the model using alias.
116
+
117
+ This has the following differences from calling pydantic's
118
+ `self.model_dump(by_alias=True)`:
119
+
120
+ * `None` is only added to the output dict for nullable fields that
121
+ were set at model initialization. Other fields with value `None`
122
+ are ignored.
123
+ """
124
+ excluded_fields: set[str] = set([])
125
+
126
+ _dict = self.model_dump(
127
+ by_alias=True,
128
+ exclude=excluded_fields,
129
+ exclude_none=True,
130
+ )
131
+ # override the default output from pydantic by calling `to_dict()` of name
132
+ if self.name:
133
+ _dict["name"] = self.name.to_dict()
134
+ # override the default output from pydantic by calling `to_dict()` of definition
135
+ if self.definition:
136
+ _dict["definition"] = self.definition.to_dict()
137
+ # override the default output from pydantic by calling `to_dict()` of comment
138
+ if self.comment:
139
+ _dict["comment"] = self.comment.to_dict()
140
+ # override the default output from pydantic by calling `to_dict()` of owner
141
+ if self.owner:
142
+ _dict["owner"] = self.owner.to_dict()
143
+ # override the default output from pydantic by calling `to_dict()` of contact
144
+ if self.contact:
145
+ _dict["contact"] = self.contact.to_dict()
146
+ # set to None if classification_reference (nullable) is None
147
+ # and model_fields_set contains the field
148
+ if (
149
+ self.classification_reference is None
150
+ and "classification_reference" in self.model_fields_set
151
+ ):
152
+ _dict["classification_reference"] = None
153
+
154
+ # set to None if unit_types (nullable) is None
155
+ # and model_fields_set contains the field
156
+ if self.unit_types is None and "unit_types" in self.model_fields_set:
157
+ _dict["unit_types"] = None
158
+
159
+ # set to None if subject_fields (nullable) is None
160
+ # and model_fields_set contains the field
161
+ if self.subject_fields is None and "subject_fields" in self.model_fields_set:
162
+ _dict["subject_fields"] = None
163
+
164
+ # set to None if contains_special_categories_of_personal_data (nullable) is None
165
+ # and model_fields_set contains the field
166
+ if (
167
+ self.contains_special_categories_of_personal_data is None
168
+ and "contains_special_categories_of_personal_data" in self.model_fields_set
169
+ ):
170
+ _dict["contains_special_categories_of_personal_data"] = None
171
+
172
+ # set to None if measurement_type (nullable) is None
173
+ # and model_fields_set contains the field
174
+ if (
175
+ self.measurement_type is None
176
+ and "measurement_type" in self.model_fields_set
177
+ ):
178
+ _dict["measurement_type"] = None
179
+
180
+ # set to None if valid_until (nullable) is None
181
+ # and model_fields_set contains the field
182
+ if self.valid_until is None and "valid_until" in self.model_fields_set:
183
+ _dict["valid_until"] = None
184
+
185
+ # set to None if external_reference_uri (nullable) is None
186
+ # and model_fields_set contains the field
187
+ if (
188
+ self.external_reference_uri is None
189
+ and "external_reference_uri" in self.model_fields_set
190
+ ):
191
+ _dict["external_reference_uri"] = None
192
+
193
+ # set to None if related_variable_definition_uris (nullable) is None
194
+ # and model_fields_set contains the field
195
+ if (
196
+ self.related_variable_definition_uris is None
197
+ and "related_variable_definition_uris" in self.model_fields_set
198
+ ):
199
+ _dict["related_variable_definition_uris"] = None
200
+
201
+ return _dict
202
+
203
+ @classmethod
204
+ def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
205
+ """Create an instance of Patch from a dict"""
206
+ if obj is None:
207
+ return None
208
+
209
+ if not isinstance(obj, dict):
210
+ return cls.model_validate(obj)
211
+
212
+ _obj = cls.model_validate(
213
+ {
214
+ "name": LanguageStringType.from_dict(obj["name"])
215
+ if obj.get("name") is not None
216
+ else None,
217
+ "definition": LanguageStringType.from_dict(obj["definition"])
218
+ if obj.get("definition") is not None
219
+ else None,
220
+ "classification_reference": obj.get("classification_reference"),
221
+ "unit_types": obj.get("unit_types"),
222
+ "subject_fields": obj.get("subject_fields"),
223
+ "contains_special_categories_of_personal_data": obj.get(
224
+ "contains_special_categories_of_personal_data"
225
+ ),
226
+ "variable_status": obj.get("variable_status"),
227
+ "measurement_type": obj.get("measurement_type"),
228
+ "valid_until": obj.get("valid_until"),
229
+ "external_reference_uri": obj.get("external_reference_uri"),
230
+ "comment": LanguageStringType.from_dict(obj["comment"])
231
+ if obj.get("comment") is not None
232
+ else None,
233
+ "related_variable_definition_uris": obj.get(
234
+ "related_variable_definition_uris"
235
+ ),
236
+ "owner": Owner.from_dict(obj["owner"])
237
+ if obj.get("owner") is not None
238
+ else None,
239
+ "contact": Contact.from_dict(obj["contact"])
240
+ if obj.get("contact") is not None
241
+ else None,
242
+ }
243
+ )
244
+ return _obj