pysdmx 1.10.1__py3-none-any.whl → 1.11.0__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.
Files changed (35) hide show
  1. pysdmx/__init__.py +1 -1
  2. pysdmx/api/fmr/maintenance.py +10 -5
  3. pysdmx/io/input_processor.py +4 -0
  4. pysdmx/io/json/fusion/messages/dsd.py +19 -14
  5. pysdmx/io/json/fusion/messages/msd.py +6 -9
  6. pysdmx/io/json/sdmxjson2/messages/core.py +12 -5
  7. pysdmx/io/json/sdmxjson2/messages/dsd.py +11 -17
  8. pysdmx/io/json/sdmxjson2/messages/msd.py +2 -5
  9. pysdmx/io/json/sdmxjson2/messages/report.py +7 -3
  10. pysdmx/io/json/sdmxjson2/messages/structure.py +7 -3
  11. pysdmx/io/json/sdmxjson2/reader/metadata.py +3 -3
  12. pysdmx/io/json/sdmxjson2/reader/structure.py +3 -3
  13. pysdmx/io/json/sdmxjson2/writer/_helper.py +118 -0
  14. pysdmx/io/json/sdmxjson2/writer/v2_0/__init__.py +1 -0
  15. pysdmx/io/json/sdmxjson2/writer/v2_0/metadata.py +33 -0
  16. pysdmx/io/json/sdmxjson2/writer/v2_0/structure.py +33 -0
  17. pysdmx/io/json/sdmxjson2/writer/v2_1/__init__.py +1 -0
  18. pysdmx/io/json/sdmxjson2/writer/v2_1/metadata.py +31 -0
  19. pysdmx/io/json/sdmxjson2/writer/v2_1/structure.py +33 -0
  20. pysdmx/io/reader.py +12 -3
  21. pysdmx/io/writer.py +13 -3
  22. pysdmx/io/xml/__ss_aux_reader.py +39 -17
  23. pysdmx/io/xml/__structure_aux_reader.py +221 -33
  24. pysdmx/io/xml/__structure_aux_writer.py +304 -5
  25. pysdmx/io/xml/__tokens.py +12 -0
  26. pysdmx/io/xml/__write_aux.py +9 -0
  27. pysdmx/io/xml/sdmx21/writer/generic.py +2 -2
  28. pysdmx/model/dataflow.py +2 -2
  29. pysdmx/toolkit/pd/_data_utils.py +1 -1
  30. {pysdmx-1.10.1.dist-info → pysdmx-1.11.0.dist-info}/METADATA +7 -1
  31. {pysdmx-1.10.1.dist-info → pysdmx-1.11.0.dist-info}/RECORD +33 -28
  32. {pysdmx-1.10.1.dist-info → pysdmx-1.11.0.dist-info}/WHEEL +1 -1
  33. pysdmx/io/json/sdmxjson2/writer/metadata.py +0 -60
  34. pysdmx/io/json/sdmxjson2/writer/structure.py +0 -61
  35. {pysdmx-1.10.1.dist-info → pysdmx-1.11.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,60 +0,0 @@
1
- """Writer interface for SDMX-JSON 2.0.0 Reference Metadata messages."""
2
-
3
- from pathlib import Path
4
- from typing import Optional, Sequence, Union
5
-
6
- import msgspec
7
-
8
- from pysdmx.io.json.sdmxjson2.messages import JsonMetadataMessage
9
- from pysdmx.model import MetadataReport, encoders
10
- from pysdmx.model.message import Header, MetadataMessage
11
-
12
-
13
- def write(
14
- reports: Sequence[MetadataReport],
15
- output_path: Optional[Union[str, Path]] = None,
16
- prettyprint: bool = True,
17
- header: Optional[Header] = None,
18
- ) -> Optional[str]:
19
- """Write metadata reports in SDMX-JSON 2.0.0.
20
-
21
- Args:
22
- reports: The reference metadata reports to be serialized.
23
- output_path: The path to save the JSON file. If None or empty, the
24
- serialized content is returned as a string instead.
25
- prettyprint: Whether to format the JSON output with indentation (True)
26
- or output compact JSON without extra whitespace (False).
27
- header: The header to be used in the SDMX-JSON message
28
- (will be generated if no header is supplied).
29
-
30
- Returns:
31
- The JSON string if output_path is None or empty, None otherwise.
32
- """
33
- if not header:
34
- header = Header()
35
- sm = MetadataMessage(header, reports)
36
- jsm = JsonMetadataMessage.from_model(sm)
37
-
38
- encoder = msgspec.json.Encoder(enc_hook=encoders)
39
- serialized_data = encoder.encode(jsm)
40
-
41
- # Apply pretty-printing if requested
42
- if prettyprint:
43
- serialized_data = msgspec.json.format(serialized_data, indent=4)
44
-
45
- # If output_path is provided, write to file
46
- if output_path:
47
- # Convert to Path object if string
48
- if isinstance(output_path, str):
49
- output_path = Path(output_path)
50
-
51
- # Create parent directories if they don't exist
52
- output_path.parent.mkdir(parents=True, exist_ok=True)
53
-
54
- # Write to file
55
- with open(output_path, "wb") as f:
56
- f.write(serialized_data)
57
- return None
58
- else:
59
- # Return as string
60
- return serialized_data.decode("utf-8")
@@ -1,61 +0,0 @@
1
- """Writer interface for SDMX-JSON 2.0.0 Structure messages."""
2
-
3
- from pathlib import Path
4
- from typing import Optional, Sequence, Union
5
-
6
- import msgspec
7
-
8
- from pysdmx.io.json.sdmxjson2.messages import JsonStructureMessage
9
- from pysdmx.model import encoders
10
- from pysdmx.model.__base import MaintainableArtefact
11
- from pysdmx.model.message import Header, StructureMessage
12
-
13
-
14
- def write(
15
- structures: Sequence[MaintainableArtefact],
16
- output_path: Optional[Union[str, Path]] = None,
17
- prettyprint: bool = True,
18
- header: Optional[Header] = None,
19
- ) -> Optional[str]:
20
- """Write maintainable SDMX artefacts in SDMX-JSON 2.0.0.
21
-
22
- Args:
23
- structures: The maintainable SDMX artefacts to be serialized.
24
- output_path: The path to save the JSON file. If None or empty, the
25
- serialized content is returned as a string instead.
26
- prettyprint: Whether to format the JSON output with indentation (True)
27
- or output compact JSON without extra whitespace (False).
28
- header: The header to be used in the SDMX-JSON message
29
- (will be generated if no header is supplied).
30
-
31
- Returns:
32
- The JSON string if output_path is None or empty, None otherwise.
33
- """
34
- if not header:
35
- header = Header()
36
- sm = StructureMessage(header, structures)
37
- jsm = JsonStructureMessage.from_model(sm)
38
-
39
- encoder = msgspec.json.Encoder(enc_hook=encoders)
40
- serialized_data = encoder.encode(jsm)
41
-
42
- # Apply pretty-printing if requested
43
- if prettyprint:
44
- serialized_data = msgspec.json.format(serialized_data, indent=4)
45
-
46
- # If output_path is provided, write to file
47
- if output_path:
48
- # Convert to Path object if string
49
- if isinstance(output_path, str):
50
- output_path = Path(output_path)
51
-
52
- # Create parent directories if they don't exist
53
- output_path.parent.mkdir(parents=True, exist_ok=True)
54
-
55
- # Write to file
56
- with open(output_path, "wb") as f:
57
- f.write(serialized_data)
58
- return None
59
- else:
60
- # Return as string
61
- return serialized_data.decode("utf-8")