dapla-toolbelt-metadata 0.3.0__py3-none-any.whl → 0.4.1__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 (69) hide show
  1. dapla_metadata/__init__.py +1 -0
  2. dapla_metadata/_shared/__init__.py +1 -0
  3. dapla_metadata/{datasets → _shared}/config.py +39 -13
  4. dapla_metadata/_shared/enums.py +28 -0
  5. dapla_metadata/{datasets → _shared}/user_info.py +4 -4
  6. dapla_metadata/datasets/core.py +6 -3
  7. dapla_metadata/datasets/utility/enums.py +0 -19
  8. dapla_metadata/datasets/utility/utils.py +1 -1
  9. dapla_metadata/variable_definitions/__init__.py +7 -0
  10. dapla_metadata/variable_definitions/_client.py +30 -0
  11. dapla_metadata/variable_definitions/config.py +49 -0
  12. dapla_metadata/variable_definitions/exceptions.py +66 -0
  13. dapla_metadata/variable_definitions/generated/.openapi-generator/FILES +22 -0
  14. dapla_metadata/variable_definitions/generated/.openapi-generator/VERSION +1 -0
  15. dapla_metadata/variable_definitions/generated/.openapi-generator-ignore +6 -0
  16. dapla_metadata/variable_definitions/generated/README.md +148 -0
  17. dapla_metadata/variable_definitions/generated/__init__.py +0 -0
  18. dapla_metadata/variable_definitions/generated/vardef_client/__init__.py +52 -0
  19. dapla_metadata/variable_definitions/generated/vardef_client/api/__init__.py +9 -0
  20. dapla_metadata/variable_definitions/generated/vardef_client/api/data_migration_api.py +313 -0
  21. dapla_metadata/variable_definitions/generated/vardef_client/api/draft_variable_definitions_api.py +919 -0
  22. dapla_metadata/variable_definitions/generated/vardef_client/api/patches_api.py +919 -0
  23. dapla_metadata/variable_definitions/generated/vardef_client/api/public_api.py +915 -0
  24. dapla_metadata/variable_definitions/generated/vardef_client/api/validity_periods_api.py +876 -0
  25. dapla_metadata/variable_definitions/generated/vardef_client/api/variable_definitions_api.py +1205 -0
  26. dapla_metadata/variable_definitions/generated/vardef_client/api_client.py +779 -0
  27. dapla_metadata/variable_definitions/generated/vardef_client/api_response.py +27 -0
  28. dapla_metadata/variable_definitions/generated/vardef_client/configuration.py +474 -0
  29. dapla_metadata/variable_definitions/generated/vardef_client/docs/CompleteResponse.md +51 -0
  30. dapla_metadata/variable_definitions/generated/vardef_client/docs/Contact.md +30 -0
  31. dapla_metadata/variable_definitions/generated/vardef_client/docs/DataMigrationApi.md +90 -0
  32. dapla_metadata/variable_definitions/generated/vardef_client/docs/Draft.md +42 -0
  33. dapla_metadata/variable_definitions/generated/vardef_client/docs/DraftVariableDefinitionsApi.md +259 -0
  34. dapla_metadata/variable_definitions/generated/vardef_client/docs/LanguageStringType.md +31 -0
  35. dapla_metadata/variable_definitions/generated/vardef_client/docs/Owner.md +31 -0
  36. dapla_metadata/variable_definitions/generated/vardef_client/docs/Patch.md +43 -0
  37. dapla_metadata/variable_definitions/generated/vardef_client/docs/PatchesApi.md +249 -0
  38. dapla_metadata/variable_definitions/generated/vardef_client/docs/PublicApi.md +218 -0
  39. dapla_metadata/variable_definitions/generated/vardef_client/docs/SupportedLanguages.md +15 -0
  40. dapla_metadata/variable_definitions/generated/vardef_client/docs/UpdateDraft.md +44 -0
  41. dapla_metadata/variable_definitions/generated/vardef_client/docs/ValidityPeriod.md +42 -0
  42. dapla_metadata/variable_definitions/generated/vardef_client/docs/ValidityPeriodsApi.md +236 -0
  43. dapla_metadata/variable_definitions/generated/vardef_client/docs/VariableDefinitionsApi.md +304 -0
  44. dapla_metadata/variable_definitions/generated/vardef_client/docs/VariableStatus.md +17 -0
  45. dapla_metadata/variable_definitions/generated/vardef_client/exceptions.py +193 -0
  46. dapla_metadata/variable_definitions/generated/vardef_client/models/__init__.py +30 -0
  47. dapla_metadata/variable_definitions/generated/vardef_client/models/complete_response.py +284 -0
  48. dapla_metadata/variable_definitions/generated/vardef_client/models/contact.py +94 -0
  49. dapla_metadata/variable_definitions/generated/vardef_client/models/draft.py +243 -0
  50. dapla_metadata/variable_definitions/generated/vardef_client/models/klass_reference.py +99 -0
  51. dapla_metadata/variable_definitions/generated/vardef_client/models/language_string_type.py +104 -0
  52. dapla_metadata/variable_definitions/generated/vardef_client/models/owner.py +90 -0
  53. dapla_metadata/variable_definitions/generated/vardef_client/models/patch.py +289 -0
  54. dapla_metadata/variable_definitions/generated/vardef_client/models/problem.py +118 -0
  55. dapla_metadata/variable_definitions/generated/vardef_client/models/rendered_contact.py +92 -0
  56. dapla_metadata/variable_definitions/generated/vardef_client/models/rendered_variable_definition.py +235 -0
  57. dapla_metadata/variable_definitions/generated/vardef_client/models/supported_languages.py +33 -0
  58. dapla_metadata/variable_definitions/generated/vardef_client/models/update_draft.py +307 -0
  59. dapla_metadata/variable_definitions/generated/vardef_client/models/validity_period.py +259 -0
  60. dapla_metadata/variable_definitions/generated/vardef_client/models/variable_status.py +33 -0
  61. dapla_metadata/variable_definitions/generated/vardef_client/py.typed +0 -0
  62. dapla_metadata/variable_definitions/generated/vardef_client/rest.py +249 -0
  63. dapla_metadata/variable_definitions/vardef.py +173 -0
  64. dapla_metadata/variable_definitions/variable_definition.py +212 -0
  65. {dapla_toolbelt_metadata-0.3.0.dist-info → dapla_toolbelt_metadata-0.4.1.dist-info}/METADATA +1 -1
  66. dapla_toolbelt_metadata-0.4.1.dist-info/RECORD +80 -0
  67. dapla_toolbelt_metadata-0.3.0.dist-info/RECORD +0 -22
  68. {dapla_toolbelt_metadata-0.3.0.dist-info → dapla_toolbelt_metadata-0.4.1.dist-info}/LICENSE +0 -0
  69. {dapla_toolbelt_metadata-0.3.0.dist-info → dapla_toolbelt_metadata-0.4.1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,307 @@
1
+ """Variable Definitions
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
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 pydantic import field_validator
28
+ from typing_extensions import Self
29
+
30
+ from ..models.contact import Contact
31
+ from ..models.language_string_type import LanguageStringType
32
+ from ..models.owner import Owner
33
+ from ..models.variable_status import VariableStatus
34
+
35
+
36
+ class UpdateDraft(BaseModel):
37
+ """Update variable definition Data structure with all fields optional for updating a Draft Variable Definition."""
38
+
39
+ name: LanguageStringType | None = Field(
40
+ default=None,
41
+ description="Name of the variable. Must be unique for a given Unit Type and Owner combination.",
42
+ )
43
+ short_name: Annotated[str, Field(strict=True)] | None = Field(
44
+ default=None,
45
+ description="Recommended short name. Must be unique within an organization.",
46
+ )
47
+ definition: LanguageStringType | None = Field(
48
+ default=None, description="Definition of the variable."
49
+ )
50
+ classification_reference: StrictStr | None = Field(
51
+ default=None,
52
+ description="ID of a classification or code list from Klass. The given classification defines all possible values for the defined variable.",
53
+ )
54
+ unit_types: list[StrictStr] | None = Field(
55
+ default=None,
56
+ 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.",
57
+ )
58
+ subject_fields: list[StrictStr] | None = Field(
59
+ default=None,
60
+ 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.",
61
+ )
62
+ contains_special_categories_of_personal_data: StrictBool | None = Field(
63
+ default=None,
64
+ 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",
65
+ )
66
+ variable_status: VariableStatus | None = Field(
67
+ default=None, description="Status of the life cycle of the variable"
68
+ )
69
+ measurement_type: StrictStr | None = Field(
70
+ default=None,
71
+ 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",
72
+ )
73
+ valid_from: date | None = Field(
74
+ default=None,
75
+ description="The variable definition is valid from this date inclusive",
76
+ )
77
+ external_reference_uri: StrictStr | None = Field(
78
+ default=None, description="A link (URI) to an external definition/documentation"
79
+ )
80
+ comment: LanguageStringType | None = Field(
81
+ default=None,
82
+ description="Optional comment to explain the definition or communicate potential changes.",
83
+ )
84
+ related_variable_definition_uris: list[StrictStr] | None = Field(
85
+ default=None,
86
+ 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.",
87
+ )
88
+ owner: Owner | None = Field(
89
+ default=None,
90
+ description="Owner of the definition, i.e. responsible Dapla team (statistics team) and information about access management groups.",
91
+ )
92
+ contact: Contact | None = Field(default=None, description="Contact details")
93
+ __properties: ClassVar[list[str]] = [
94
+ "name",
95
+ "short_name",
96
+ "definition",
97
+ "classification_reference",
98
+ "unit_types",
99
+ "subject_fields",
100
+ "contains_special_categories_of_personal_data",
101
+ "variable_status",
102
+ "measurement_type",
103
+ "valid_from",
104
+ "external_reference_uri",
105
+ "comment",
106
+ "related_variable_definition_uris",
107
+ "owner",
108
+ "contact",
109
+ ]
110
+
111
+ @field_validator("short_name")
112
+ def short_name_validate_regular_expression(cls, value):
113
+ """Validates the regular expression"""
114
+ if value is None:
115
+ return value
116
+
117
+ if not re.match(r"^[a-z0-9_]{2,}$", value):
118
+ raise ValueError(r"must validate the regular expression /^[a-z0-9_]{2,}$/")
119
+ return value
120
+
121
+ model_config = ConfigDict(
122
+ populate_by_name=True,
123
+ validate_assignment=True,
124
+ protected_namespaces=(),
125
+ )
126
+
127
+ def to_str(self) -> str:
128
+ """Returns the string representation of the model using alias"""
129
+ return pprint.pformat(self.model_dump(by_alias=True))
130
+
131
+ def to_json(self) -> str:
132
+ """Returns the JSON representation of the model using alias"""
133
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
134
+ return json.dumps(self.to_dict())
135
+
136
+ @classmethod
137
+ def from_json(cls, json_str: str) -> Self | None:
138
+ """Create an instance of UpdateDraft from a JSON string"""
139
+ return cls.from_dict(json.loads(json_str))
140
+
141
+ def to_dict(self) -> dict[str, Any]:
142
+ """Return the dictionary representation of the model using alias.
143
+
144
+ This has the following differences from calling pydantic's
145
+ `self.model_dump(by_alias=True)`:
146
+
147
+ * `None` is only added to the output dict for nullable fields that
148
+ were set at model initialization. Other fields with value `None`
149
+ are ignored.
150
+ """
151
+ excluded_fields: set[str] = set([])
152
+
153
+ _dict = self.model_dump(
154
+ by_alias=True,
155
+ exclude=excluded_fields,
156
+ exclude_none=True,
157
+ )
158
+ # override the default output from pydantic by calling `to_dict()` of name
159
+ if self.name:
160
+ _dict["name"] = self.name.to_dict()
161
+ # override the default output from pydantic by calling `to_dict()` of definition
162
+ if self.definition:
163
+ _dict["definition"] = self.definition.to_dict()
164
+ # override the default output from pydantic by calling `to_dict()` of comment
165
+ if self.comment:
166
+ _dict["comment"] = self.comment.to_dict()
167
+ # override the default output from pydantic by calling `to_dict()` of owner
168
+ if self.owner:
169
+ _dict["owner"] = self.owner.to_dict()
170
+ # override the default output from pydantic by calling `to_dict()` of contact
171
+ if self.contact:
172
+ _dict["contact"] = self.contact.to_dict()
173
+ # set to None if name (nullable) is None
174
+ # and model_fields_set contains the field
175
+ if self.name is None and "name" in self.model_fields_set:
176
+ _dict["name"] = None
177
+
178
+ # set to None if short_name (nullable) is None
179
+ # and model_fields_set contains the field
180
+ if self.short_name is None and "short_name" in self.model_fields_set:
181
+ _dict["short_name"] = None
182
+
183
+ # set to None if definition (nullable) is None
184
+ # and model_fields_set contains the field
185
+ if self.definition is None and "definition" in self.model_fields_set:
186
+ _dict["definition"] = None
187
+
188
+ # set to None if classification_reference (nullable) is None
189
+ # and model_fields_set contains the field
190
+ if (
191
+ self.classification_reference is None
192
+ and "classification_reference" in self.model_fields_set
193
+ ):
194
+ _dict["classification_reference"] = None
195
+
196
+ # set to None if unit_types (nullable) is None
197
+ # and model_fields_set contains the field
198
+ if self.unit_types is None and "unit_types" in self.model_fields_set:
199
+ _dict["unit_types"] = None
200
+
201
+ # set to None if subject_fields (nullable) is None
202
+ # and model_fields_set contains the field
203
+ if self.subject_fields is None and "subject_fields" in self.model_fields_set:
204
+ _dict["subject_fields"] = None
205
+
206
+ # set to None if contains_special_categories_of_personal_data (nullable) is None
207
+ # and model_fields_set contains the field
208
+ if (
209
+ self.contains_special_categories_of_personal_data is None
210
+ and "contains_special_categories_of_personal_data" in self.model_fields_set
211
+ ):
212
+ _dict["contains_special_categories_of_personal_data"] = None
213
+
214
+ # set to None if variable_status (nullable) is None
215
+ # and model_fields_set contains the field
216
+ if self.variable_status is None and "variable_status" in self.model_fields_set:
217
+ _dict["variable_status"] = None
218
+
219
+ # set to None if measurement_type (nullable) is None
220
+ # and model_fields_set contains the field
221
+ if (
222
+ self.measurement_type is None
223
+ and "measurement_type" in self.model_fields_set
224
+ ):
225
+ _dict["measurement_type"] = None
226
+
227
+ # set to None if valid_from (nullable) is None
228
+ # and model_fields_set contains the field
229
+ if self.valid_from is None and "valid_from" in self.model_fields_set:
230
+ _dict["valid_from"] = None
231
+
232
+ # set to None if external_reference_uri (nullable) is None
233
+ # and model_fields_set contains the field
234
+ if (
235
+ self.external_reference_uri is None
236
+ and "external_reference_uri" in self.model_fields_set
237
+ ):
238
+ _dict["external_reference_uri"] = None
239
+
240
+ # set to None if comment (nullable) is None
241
+ # and model_fields_set contains the field
242
+ if self.comment is None and "comment" in self.model_fields_set:
243
+ _dict["comment"] = None
244
+
245
+ # set to None if related_variable_definition_uris (nullable) is None
246
+ # and model_fields_set contains the field
247
+ if (
248
+ self.related_variable_definition_uris is None
249
+ and "related_variable_definition_uris" in self.model_fields_set
250
+ ):
251
+ _dict["related_variable_definition_uris"] = None
252
+
253
+ # set to None if owner (nullable) is None
254
+ # and model_fields_set contains the field
255
+ if self.owner is None and "owner" in self.model_fields_set:
256
+ _dict["owner"] = None
257
+
258
+ # set to None if contact (nullable) is None
259
+ # and model_fields_set contains the field
260
+ if self.contact is None and "contact" in self.model_fields_set:
261
+ _dict["contact"] = None
262
+
263
+ return _dict
264
+
265
+ @classmethod
266
+ def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
267
+ """Create an instance of UpdateDraft from a dict"""
268
+ if obj is None:
269
+ return None
270
+
271
+ if not isinstance(obj, dict):
272
+ return cls.model_validate(obj)
273
+
274
+ _obj = cls.model_validate(
275
+ {
276
+ "name": LanguageStringType.from_dict(obj["name"])
277
+ if obj.get("name") is not None
278
+ else None,
279
+ "short_name": obj.get("short_name"),
280
+ "definition": LanguageStringType.from_dict(obj["definition"])
281
+ if obj.get("definition") is not None
282
+ else None,
283
+ "classification_reference": obj.get("classification_reference"),
284
+ "unit_types": obj.get("unit_types"),
285
+ "subject_fields": obj.get("subject_fields"),
286
+ "contains_special_categories_of_personal_data": obj.get(
287
+ "contains_special_categories_of_personal_data"
288
+ ),
289
+ "variable_status": obj.get("variable_status"),
290
+ "measurement_type": obj.get("measurement_type"),
291
+ "valid_from": obj.get("valid_from"),
292
+ "external_reference_uri": obj.get("external_reference_uri"),
293
+ "comment": LanguageStringType.from_dict(obj["comment"])
294
+ if obj.get("comment") is not None
295
+ else None,
296
+ "related_variable_definition_uris": obj.get(
297
+ "related_variable_definition_uris"
298
+ ),
299
+ "owner": Owner.from_dict(obj["owner"])
300
+ if obj.get("owner") is not None
301
+ else None,
302
+ "contact": Contact.from_dict(obj["contact"])
303
+ if obj.get("contact") is not None
304
+ else None,
305
+ }
306
+ )
307
+ return _obj
@@ -0,0 +1,259 @@
1
+ """Variable Definitions
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 Any
19
+ from typing import ClassVar
20
+
21
+ from pydantic import BaseModel
22
+ from pydantic import ConfigDict
23
+ from pydantic import Field
24
+ from pydantic import StrictBool
25
+ from pydantic import StrictStr
26
+ from typing_extensions import Self
27
+
28
+ from ..models.contact import Contact
29
+ from ..models.language_string_type import LanguageStringType
30
+ from ..models.variable_status import VariableStatus
31
+
32
+
33
+ class ValidityPeriod(BaseModel):
34
+ """Create a new Validity Period on a Published Variable Definition."""
35
+
36
+ name: LanguageStringType | None = Field(
37
+ default=None,
38
+ description="Name of the variable. Must be unique for a given Unit Type and Owner combination.",
39
+ )
40
+ definition: LanguageStringType = Field(description="Definition of the variable.")
41
+ classification_reference: StrictStr | None = Field(
42
+ default=None,
43
+ description="ID of a classification or code list from Klass. The given classification defines all possible values for the defined variable.",
44
+ )
45
+ unit_types: list[StrictStr] | None = Field(
46
+ default=None,
47
+ 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.",
48
+ )
49
+ subject_fields: list[StrictStr] | None = 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
+ contains_special_categories_of_personal_data: StrictBool | None = Field(
54
+ default=None,
55
+ 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",
56
+ )
57
+ variable_status: VariableStatus | None = Field(
58
+ default=None, description="Status of the life cycle of the variable"
59
+ )
60
+ measurement_type: StrictStr | None = Field(
61
+ default=None,
62
+ 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",
63
+ )
64
+ valid_from: date = Field(
65
+ description="The variable definition is valid from 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 = Field(
71
+ default=None,
72
+ description="Optional comment to explain the definition or communicate potential changes.",
73
+ )
74
+ related_variable_definition_uris: list[StrictStr] | None = Field(
75
+ default=None,
76
+ 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.",
77
+ )
78
+ contact: Contact | None = Field(default=None, description="Contact details")
79
+ __properties: ClassVar[list[str]] = [
80
+ "name",
81
+ "definition",
82
+ "classification_reference",
83
+ "unit_types",
84
+ "subject_fields",
85
+ "contains_special_categories_of_personal_data",
86
+ "variable_status",
87
+ "measurement_type",
88
+ "valid_from",
89
+ "external_reference_uri",
90
+ "comment",
91
+ "related_variable_definition_uris",
92
+ "contact",
93
+ ]
94
+
95
+ model_config = ConfigDict(
96
+ populate_by_name=True,
97
+ validate_assignment=True,
98
+ protected_namespaces=(),
99
+ )
100
+
101
+ def to_str(self) -> str:
102
+ """Returns the string representation of the model using alias"""
103
+ return pprint.pformat(self.model_dump(by_alias=True))
104
+
105
+ def to_json(self) -> str:
106
+ """Returns the JSON representation of the model using alias"""
107
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
108
+ return json.dumps(self.to_dict())
109
+
110
+ @classmethod
111
+ def from_json(cls, json_str: str) -> Self | None:
112
+ """Create an instance of ValidityPeriod from a JSON string"""
113
+ return cls.from_dict(json.loads(json_str))
114
+
115
+ def to_dict(self) -> dict[str, Any]:
116
+ """Return the dictionary representation of the model using alias.
117
+
118
+ This has the following differences from calling pydantic's
119
+ `self.model_dump(by_alias=True)`:
120
+
121
+ * `None` is only added to the output dict for nullable fields that
122
+ were set at model initialization. Other fields with value `None`
123
+ are ignored.
124
+ * OpenAPI `readOnly` fields are excluded.
125
+ """
126
+ excluded_fields: set[str] = set(
127
+ [
128
+ "variable_status",
129
+ ]
130
+ )
131
+
132
+ _dict = self.model_dump(
133
+ by_alias=True,
134
+ exclude=excluded_fields,
135
+ exclude_none=True,
136
+ )
137
+ # override the default output from pydantic by calling `to_dict()` of name
138
+ if self.name:
139
+ _dict["name"] = self.name.to_dict()
140
+ # override the default output from pydantic by calling `to_dict()` of definition
141
+ if self.definition:
142
+ _dict["definition"] = self.definition.to_dict()
143
+ # override the default output from pydantic by calling `to_dict()` of comment
144
+ if self.comment:
145
+ _dict["comment"] = self.comment.to_dict()
146
+ # override the default output from pydantic by calling `to_dict()` of contact
147
+ if self.contact:
148
+ _dict["contact"] = self.contact.to_dict()
149
+ # set to None if name (nullable) is None
150
+ # and model_fields_set contains the field
151
+ if self.name is None and "name" in self.model_fields_set:
152
+ _dict["name"] = None
153
+
154
+ # set to None if classification_reference (nullable) is None
155
+ # and model_fields_set contains the field
156
+ if (
157
+ self.classification_reference is None
158
+ and "classification_reference" in self.model_fields_set
159
+ ):
160
+ _dict["classification_reference"] = None
161
+
162
+ # set to None if unit_types (nullable) is None
163
+ # and model_fields_set contains the field
164
+ if self.unit_types is None and "unit_types" in self.model_fields_set:
165
+ _dict["unit_types"] = None
166
+
167
+ # set to None if subject_fields (nullable) is None
168
+ # and model_fields_set contains the field
169
+ if self.subject_fields is None and "subject_fields" in self.model_fields_set:
170
+ _dict["subject_fields"] = None
171
+
172
+ # set to None if contains_special_categories_of_personal_data (nullable) is None
173
+ # and model_fields_set contains the field
174
+ if (
175
+ self.contains_special_categories_of_personal_data is None
176
+ and "contains_special_categories_of_personal_data" in self.model_fields_set
177
+ ):
178
+ _dict["contains_special_categories_of_personal_data"] = None
179
+
180
+ # set to None if variable_status (nullable) is None
181
+ # and model_fields_set contains the field
182
+ if self.variable_status is None and "variable_status" in self.model_fields_set:
183
+ _dict["variable_status"] = None
184
+
185
+ # set to None if measurement_type (nullable) is None
186
+ # and model_fields_set contains the field
187
+ if (
188
+ self.measurement_type is None
189
+ and "measurement_type" in self.model_fields_set
190
+ ):
191
+ _dict["measurement_type"] = None
192
+
193
+ # set to None if external_reference_uri (nullable) is None
194
+ # and model_fields_set contains the field
195
+ if (
196
+ self.external_reference_uri is None
197
+ and "external_reference_uri" in self.model_fields_set
198
+ ):
199
+ _dict["external_reference_uri"] = None
200
+
201
+ # set to None if comment (nullable) is None
202
+ # and model_fields_set contains the field
203
+ if self.comment is None and "comment" in self.model_fields_set:
204
+ _dict["comment"] = None
205
+
206
+ # set to None if related_variable_definition_uris (nullable) is None
207
+ # and model_fields_set contains the field
208
+ if (
209
+ self.related_variable_definition_uris is None
210
+ and "related_variable_definition_uris" in self.model_fields_set
211
+ ):
212
+ _dict["related_variable_definition_uris"] = None
213
+
214
+ # set to None if contact (nullable) is None
215
+ # and model_fields_set contains the field
216
+ if self.contact is None and "contact" in self.model_fields_set:
217
+ _dict["contact"] = None
218
+
219
+ return _dict
220
+
221
+ @classmethod
222
+ def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
223
+ """Create an instance of ValidityPeriod from a dict"""
224
+ if obj is None:
225
+ return None
226
+
227
+ if not isinstance(obj, dict):
228
+ return cls.model_validate(obj)
229
+
230
+ _obj = cls.model_validate(
231
+ {
232
+ "name": LanguageStringType.from_dict(obj["name"])
233
+ if obj.get("name") is not None
234
+ else None,
235
+ "definition": LanguageStringType.from_dict(obj["definition"])
236
+ if obj.get("definition") is not None
237
+ else None,
238
+ "classification_reference": obj.get("classification_reference"),
239
+ "unit_types": obj.get("unit_types"),
240
+ "subject_fields": obj.get("subject_fields"),
241
+ "contains_special_categories_of_personal_data": obj.get(
242
+ "contains_special_categories_of_personal_data"
243
+ ),
244
+ "variable_status": obj.get("variable_status"),
245
+ "measurement_type": obj.get("measurement_type"),
246
+ "valid_from": obj.get("valid_from"),
247
+ "external_reference_uri": obj.get("external_reference_uri"),
248
+ "comment": LanguageStringType.from_dict(obj["comment"])
249
+ if obj.get("comment") is not None
250
+ else None,
251
+ "related_variable_definition_uris": obj.get(
252
+ "related_variable_definition_uris"
253
+ ),
254
+ "contact": Contact.from_dict(obj["contact"])
255
+ if obj.get("contact") is not None
256
+ else None,
257
+ }
258
+ )
259
+ return _obj
@@ -0,0 +1,33 @@
1
+ """Variable Definitions
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
+ from enum import Enum
16
+
17
+ from typing_extensions import Self
18
+
19
+
20
+ class VariableStatus(str, Enum):
21
+ """Life cycle status of a variable definition."""
22
+
23
+ """
24
+ allowed enum values
25
+ """
26
+ DRAFT = "DRAFT"
27
+ PUBLISHED_INTERNAL = "PUBLISHED_INTERNAL"
28
+ PUBLISHED_EXTERNAL = "PUBLISHED_EXTERNAL"
29
+
30
+ @classmethod
31
+ def from_json(cls, json_str: str) -> Self:
32
+ """Create an instance of VariableStatus from a JSON string"""
33
+ return cls(json.loads(json_str))