pydpm_xl 0.2.1__py3-none-any.whl → 0.2.3__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.
py_dpm/__init__.py CHANGED
@@ -41,7 +41,7 @@ Available packages:
41
41
  - pydpm.api: Main APIs for migration, syntax, and semantic analysis
42
42
  """
43
43
 
44
- __version__ = "0.2.1"
44
+ __version__ = "0.2.3"
45
45
  __author__ = "MeaningfulData S.L."
46
46
  __email__ = "info@meaningfuldata.eu"
47
47
  __license__ = "GPL-3.0-or-later"
py_dpm/api/__init__.py CHANGED
@@ -9,70 +9,42 @@ Provides both DPM-XL specific and general DPM functionality.
9
9
  from py_dpm.api.dpm_xl import (
10
10
  SyntaxAPI,
11
11
  SemanticAPI,
12
- ASTGenerator,
12
+ ASTGeneratorAPI,
13
+ OperationScopesAPI,
14
+ generate_complete_ast,
15
+ generate_complete_batch,
16
+ generate_enriched_ast,
17
+ enrich_ast_with_metadata,
18
+ parse_with_data_fields,
13
19
  )
14
20
 
15
21
  # Import from general DPM API
16
22
  from py_dpm.api.dpm import (
23
+ MigrationAPI,
17
24
  DataDictionaryAPI,
18
25
  ExplorerQueryAPI,
19
- OperationScopesAPI,
20
- MigrationAPI,
21
26
  HierarchicalQueryAPI,
27
+ InstanceAPI,
22
28
  )
23
29
 
24
- # Import convenience functions and types from DPM API
25
- from py_dpm.api.dpm.operation_scopes import (
26
- calculate_scopes_from_expression,
27
- get_existing_scopes,
28
- OperationScopeDetailedInfo,
29
- OperationScopeResult,
30
- )
31
-
32
-
33
- # Import AST generator convenience functions
34
- from py_dpm.api.dpm_xl.ast_generator import (
35
- parse_expression,
36
- validate_expression,
37
- parse_batch,
38
- )
39
30
 
40
- # Import complete AST functions
41
- from py_dpm.api.dpm_xl.complete_ast import (
42
- generate_complete_ast,
43
- generate_complete_batch,
44
- generate_enriched_ast,
45
- enrich_ast_with_metadata,
46
- )
47
-
48
-
49
- # Export the main API classes
31
+ # Export the main API classes and functions
50
32
  __all__ = [
51
- # Complete AST API (recommended - includes data fields)
52
- "generate_complete_ast",
53
- "generate_complete_batch",
54
- # Enriched AST API (engine-ready with framework structure)
55
- "generate_enriched_ast",
56
- "enrich_ast_with_metadata",
57
- # Simple AST API
58
- "ASTGenerator",
59
- "parse_expression",
60
- "validate_expression",
61
- "parse_batch",
62
- # Advanced APIs
33
+ # General DPM APIs
63
34
  "MigrationAPI",
35
+ "DataDictionaryAPI",
36
+ "ExplorerQueryAPI",
37
+ "HierarchicalQueryAPI",
38
+ "InstanceAPI",
39
+ # DPM-XL APIs
64
40
  "SyntaxAPI",
65
41
  "SemanticAPI",
66
- "DataDictionaryAPI",
42
+ "ASTGeneratorAPI",
67
43
  "OperationScopesAPI",
68
- "ExplorerQueryAPI",
69
- # Operation Scopes Convenience Functions
70
- "calculate_scopes_from_expression",
71
- "get_existing_scopes",
72
- # Operation Scopes Data Classes
73
- "ModuleVersionInfo",
74
- "TableVersionInfo",
75
- "HeaderVersionInfo",
76
- "OperationScopeDetailedInfo",
77
- "OperationScopeResult",
44
+ # Complete AST functions (backwards compatibility)
45
+ "generate_complete_ast",
46
+ "generate_complete_batch",
47
+ "generate_enriched_ast",
48
+ "enrich_ast_with_metadata",
49
+ "parse_with_data_fields",
78
50
  ]
@@ -6,15 +6,15 @@ Public APIs for general DPM functionality (database, exploration, scopes).
6
6
 
7
7
  from py_dpm.api.dpm.data_dictionary import DataDictionaryAPI
8
8
  from py_dpm.api.dpm.explorer import ExplorerQueryAPI
9
- from py_dpm.api.dpm.operation_scopes import OperationScopesAPI
10
9
  from py_dpm.api.dpm.migration import MigrationAPI
11
10
  from py_dpm.api.dpm.hierarchical_queries import HierarchicalQueryAPI
11
+ from py_dpm.api.dpm.instance import InstanceAPI
12
12
 
13
13
 
14
14
  __all__ = [
15
15
  "DataDictionaryAPI",
16
16
  "ExplorerQueryAPI",
17
- "OperationScopesAPI",
18
17
  "MigrationAPI",
19
18
  "HierarchicalQueryAPI",
19
+ "InstanceAPI",
20
20
  ]
@@ -0,0 +1,111 @@
1
+ """
2
+ Instance API
3
+
4
+ Public API for building XBRL-CSV report packages from instance data.
5
+ """
6
+
7
+ from pathlib import Path
8
+ from typing import Union, Dict, Any, TYPE_CHECKING
9
+
10
+ if TYPE_CHECKING:
11
+ from py_dpm.instance.instance import Instance
12
+
13
+
14
+ class InstanceAPI:
15
+ """
16
+ API for working with Instance data and building XBRL-CSV report packages.
17
+
18
+ This API provides methods to create instances from JSON files or dictionaries
19
+ and build XBRL-CSV packages from them.
20
+ """
21
+
22
+ @staticmethod
23
+ def build_package_from_dict(
24
+ instance_data: Dict[str, Any],
25
+ output_folder: Union[Path, str],
26
+ file_prefix: str = None,
27
+ ) -> Path:
28
+ """
29
+ Build an XBRL-CSV package from a dictionary containing instance data.
30
+
31
+ Args:
32
+ instance_data: Dictionary with the instance configuration.
33
+ Must contain: module_code, parameters (with refPeriod),
34
+ and operands (list of facts)
35
+ output_folder: Directory where the output ZIP file will be created
36
+ file_prefix: Optional prefix for the output filename
37
+
38
+ Returns:
39
+ Path to the created ZIP file
40
+
41
+ Raises:
42
+ ValueError: If required keys are missing or invalid
43
+ TypeError: If data types are incorrect
44
+
45
+ Example:
46
+ >>> api = InstanceAPI()
47
+ >>> data = {
48
+ ... "module_code": "F_01.01",
49
+ ... "parameters": {
50
+ ... "refPeriod": "2024-12-31"
51
+ ... },
52
+ ... "operands": [
53
+ ... {
54
+ ... "table_code": "t001",
55
+ ... "row_code": "r010",
56
+ ... "column_code": "c010",
57
+ ... "value": 1000000
58
+ ... }
59
+ ... ]
60
+ ... }
61
+ >>> output_path = api.build_package_from_dict(data, "/tmp/output")
62
+ """
63
+ # Import here to avoid circular import
64
+ from py_dpm.instance.instance import Instance
65
+
66
+ instance = Instance.from_dict(instance_data)
67
+ return instance.build_package(output_folder=output_folder, file_prefix=file_prefix)
68
+
69
+ @staticmethod
70
+ def build_package_from_json(
71
+ json_file: Union[Path, str],
72
+ output_folder: Union[Path, str],
73
+ file_prefix: str = None,
74
+ ) -> Path:
75
+ """
76
+ Build an XBRL-CSV package from a JSON file containing instance data.
77
+
78
+ Args:
79
+ json_file: Path to JSON file with instance configuration.
80
+ Must contain: module_code, parameters (with refPeriod),
81
+ and operands (list of facts)
82
+ output_folder: Directory where the output ZIP file will be created
83
+ file_prefix: Optional prefix for the output filename
84
+
85
+ Returns:
86
+ Path to the created ZIP file
87
+
88
+ Raises:
89
+ FileNotFoundError: If the JSON file doesn't exist
90
+ ValueError: If required keys are missing or invalid
91
+ TypeError: If data types are incorrect
92
+ json.JSONDecodeError: If the file contains invalid JSON
93
+
94
+ Example:
95
+ >>> api = InstanceAPI()
96
+ >>> output_path = api.build_package_from_json(
97
+ ... "/path/to/instance.json",
98
+ ... "/tmp/output"
99
+ ... )
100
+ """
101
+ # Import here to avoid circular import
102
+ from py_dpm.instance.instance import Instance
103
+
104
+ if isinstance(json_file, str):
105
+ json_file = Path(json_file)
106
+
107
+ if not json_file.exists():
108
+ raise FileNotFoundError(f"JSON file not found: {json_file}")
109
+
110
+ instance = Instance.from_json_file(json_file)
111
+ return instance.build_package(output_folder=output_folder, file_prefix=file_prefix)
@@ -6,20 +6,28 @@ Public APIs for DPM-XL expression parsing, validation, and AST generation.
6
6
 
7
7
  from py_dpm.api.dpm_xl.syntax import SyntaxAPI
8
8
  from py_dpm.api.dpm_xl.semantic import SemanticAPI
9
- from py_dpm.api.dpm_xl.ast_generator import ASTGenerator
9
+ from py_dpm.api.dpm_xl.ast_generator import ASTGeneratorAPI
10
+ from py_dpm.api.dpm_xl.operation_scopes import OperationScopesAPI
11
+
12
+ # Backwards-compatible standalone functions (delegate to ASTGeneratorAPI)
10
13
  from py_dpm.api.dpm_xl.complete_ast import (
11
14
  generate_complete_ast,
12
15
  generate_complete_batch,
13
16
  generate_enriched_ast,
14
17
  enrich_ast_with_metadata,
18
+ parse_with_data_fields,
15
19
  )
16
20
 
17
21
  __all__ = [
22
+ # Class-based APIs
18
23
  "SyntaxAPI",
19
24
  "SemanticAPI",
20
- "ASTGenerator",
25
+ "ASTGeneratorAPI",
26
+ "OperationScopesAPI",
27
+ # Standalone functions (backwards compatibility)
21
28
  "generate_complete_ast",
22
29
  "generate_complete_batch",
23
30
  "generate_enriched_ast",
24
31
  "enrich_ast_with_metadata",
32
+ "parse_with_data_fields",
25
33
  ]