vtlengine 1.1rc1__py3-none-any.whl → 1.1.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 vtlengine might be problematic. Click here for more details.

@@ -1,248 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: vtlengine
3
- Version: 1.1rc1
4
- Summary: Run and Validate VTL Scripts
5
- License: AGPL-3.0
6
- Keywords: vtl,sdmx,vtlengine,Validation and Transformation Language
7
- Author: MeaningfulData
8
- Author-email: info@meaningfuldata.eu
9
- Maintainer: Francisco Javier Hernandez del Caño
10
- Maintainer-email: javier.hernandez@meaningfuldata.eu
11
- Requires-Python: >=3.9,<4
12
- Classifier: Development Status :: 5 - Production/Stable
13
- Classifier: Intended Audience :: Developers
14
- Classifier: Intended Audience :: Information Technology
15
- Classifier: Intended Audience :: Science/Research
16
- Classifier: Typing :: Typed
17
- Provides-Extra: all
18
- Provides-Extra: s3
19
- Requires-Dist: antlr4-python3-runtime (>=4.9.2,<4.10)
20
- Requires-Dist: duckdb (>=1.1,<1.2)
21
- Requires-Dist: fsspec (>=2022.11.0,<2023.0) ; extra == "all"
22
- Requires-Dist: fsspec (>=2022.11.0,<2023.0) ; extra == "s3"
23
- Requires-Dist: jsonschema (>=3.2.0,<5.0)
24
- Requires-Dist: networkx (>=2.8,<3.0)
25
- Requires-Dist: pandas (>=2.1,<3.0)
26
- Requires-Dist: s3fs (>=2022.11.0,<2023.0) ; extra == "all"
27
- Requires-Dist: s3fs (>=2022.11.0,<2023.0) ; extra == "s3"
28
- Requires-Dist: sqlglot (>=22.2.0,<23.0)
29
- Project-URL: Authors, https://github.com/Meaningful-Data/vtlengine/graphs/contributors
30
- Project-URL: Documentation, https://docs.vtlengine.meaningfuldata.eu
31
- Project-URL: IssueTracker, https://github.com/Meaningful-Data/vtlengine/issues
32
- Project-URL: MeaningfulData, https://www.meaningfuldata.eu/
33
- Project-URL: Repository, https://github.com/Meaningful-Data/vtlengine
34
- Description-Content-Type: text/markdown
35
-
36
- # VTL Engine
37
-
38
- | | |
39
- |---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
40
- | Testing | [![Testing](https://github.com/Meaningful-Data/vtlengine/actions/workflows/testing.yml/badge.svg)](https://github.com/Meaningful-Data/vtlengine/actions/workflows/testing.yml) |
41
- | Package | [![PyPI Latest Release](https://img.shields.io/pypi/v/vtlengine.svg)](https://pypi.org/project/vtlengine/) |
42
- | License | [![License - AGPL 3.0](https://img.shields.io/pypi/l/vtlengine.svg)](https://github.com/Meaningful-Data/vtlengine/blob/main/LICENSE.md) |
43
-
44
- ## Introduction
45
-
46
- The VTL Engine is a Python library for validating and running VTL scripts.
47
-
48
- It is a Python-based library around the [VTL Language](http://sdmx.org/?page_id=5096).
49
-
50
- ## Installation
51
-
52
- ### Requirements
53
-
54
- The VTL Engine requires Python 3.10 or higher.
55
-
56
- ### Install with pip
57
-
58
- To install the VTL Engine on any Operating System, you can use pip:
59
-
60
- ```bash
61
-
62
- pip install vtlengine
63
-
64
- ```
65
-
66
- *Note: it is recommended to install the VTL Engine in a virtual environment.*
67
-
68
- ## Usage
69
-
70
- The VTL Engine API implements two basic methods:
71
-
72
- * **Semantic Analysis**: aimed at validating the correctness of a script and computing the data
73
- structures of the data sets created in the script.
74
- * **Run**: aimed at executing the provided input on the provided input datasets.
75
-
76
- Any action with VTL requires the following elements as input:
77
-
78
- * **VTL Script**: Is the VTL to be executed, which includes the transformation scheme, as well as de
79
- User Defined Operators, Hierarchical Rulesets and Datapoint Rulesets. It is provided as a string
80
- or as a Path object to a vtl file.
81
- * **Data structures** : Provides the structure of the input artifacts of the VTL script, according
82
- to
83
- the VTL Information model. Given that the current version doesn't prescribe a standard format for
84
- providing the information, the VTL Engine is implementing a JSON format that can be found here.
85
- Data Structures can be provided as Dictionaries or as Paths to JSON files. It is possible to have
86
- * **External routines**: The VTL Engine allows using SQL (SQLite) with the eval operator. Can be
87
- provided as a string with the SQL or as a path object to an SQL file. Its default value is `None`,
88
- which shall be used if external routines are not applicable to the VTL script.
89
- * **Value domains**: Provides the value domains that are used in the VTL script, normally with an in
90
- operator. Can be provided as a dictionary or as a path to a JSON file. Its default value
91
- is `None`, which shall be used if value domains are not applicable to the VTL script.
92
-
93
- ### Semantic Analysis
94
-
95
- The `semantic_analysis` method serves to validate the correctness of a VTL script, as well as to
96
- calculate the data structures of the datasets generated by the VTL script itself (that calculation
97
- is a pre-requisite for the semantic analysis).
98
-
99
- * If the VTL script is correct, the method returns a dictionary with the data structures of all the
100
- datasets generated by the script.
101
- * If the VTL script is incorrect, raises a VTL Engine custom error Explaining the error.
102
-
103
- #### Example 1: Correct VTL
104
-
105
- ```python
106
- from vtlengine import semantic_analysis
107
-
108
- script = """
109
- DS_A := DS_1 * 10;
110
- """
111
-
112
- data_structures = {
113
- 'datasets': [
114
- {'name': 'DS_1',
115
- 'DataStructure': [
116
- {'name': 'Id_1',
117
- 'type':
118
- 'Integer',
119
- 'role': 'Identifier',
120
- 'nullable': False},
121
- {'name': 'Me_1',
122
- 'type': 'Number',
123
- 'role': 'Measure',
124
- 'nullable': True}
125
- ]
126
- }
127
- ]
128
- }
129
-
130
- sa_result = semantic_analysis(script=script, data_structures=data_structures)
131
-
132
- print(sa_result)
133
-
134
- ```
135
-
136
- Returns:
137
-
138
- ```
139
- {'DS_A': Dataset(name='DS_A', components={'Id_1': Component(name='Id_1', data_type=<class 'vtlengine.DataTypes.Integer'>, role=<Role.IDENTIFIER: 'Identifier'>, nullable=False), 'Me_1': Component(name='Me_1', data_type=<class 'vtlengine.DataTypes.Number'>, role=<Role.MEASURE: 'Measure'>, nullable=True)}, data=None)}
140
- ```
141
-
142
- #### Example 2: Incorrect VTL
143
-
144
- Note that, as compared to Example 1, the only change is that Me_1 is of the String data type,
145
- instead of Number.
146
-
147
- ```python
148
- from vtlengine import semantic_analysis
149
-
150
- script = """
151
- DS_A := DS_1 * 10;
152
- """
153
-
154
- data_structures = {
155
- 'datasets': [
156
- {'name': 'DS_1',
157
- 'DataStructure': [
158
- {'name': 'Id_1',
159
- 'type':
160
- 'Integer',
161
- 'role': 'Identifier',
162
- 'nullable': False},
163
- {'name': 'Me_1',
164
- 'type': 'String',
165
- 'role': 'Measure',
166
- 'nullable': True}
167
- ]
168
- }
169
- ]
170
- }
171
-
172
- sa_result = semantic_analysis(script=script, data_structures=data_structures)
173
-
174
- print(sa_result)
175
-
176
- ```
177
-
178
- Will raise the following Error:
179
-
180
- ``` python
181
- raise SemanticError(code="1-1-1-2",
182
- vtlengine.Exceptions.SemanticError: ('Invalid implicit cast from String and Integer to Number.', '1-1-1-2')
183
- ```
184
-
185
- ### Run VTL Scripts
186
-
187
- The `run` method serves to execute a VTL script with input datapoints.
188
-
189
- Returns a dictionary with all the generated Datasets.
190
- When the output parameter is set, the engine will write the result of the computation to the output
191
- folder, else it will include the data in the dictionary of the computed datasets.
192
-
193
- Two validations are performed before running, which can raise errors:
194
-
195
- * Semantic analysis: Equivalent to running the `semantic_analysis` method
196
- * Data load analysis: Basic check of the data structure (names and types)
197
-
198
- #### Example 3: Simple run
199
-
200
- ```python
201
- from vtlengine import run
202
- import pandas as pd
203
-
204
- script = """
205
- DS_A := DS_1 * 10;
206
- """
207
-
208
- data_structures = {
209
- 'datasets': [
210
- {'name': 'DS_1',
211
- 'DataStructure': [
212
- {'name': 'Id_1',
213
- 'type':
214
- 'Integer',
215
- 'role': 'Identifier',
216
- 'nullable': False},
217
- {'name': 'Me_1',
218
- 'type': 'Number',
219
- 'role': 'Measure',
220
- 'nullable': True}
221
- ]
222
- }
223
- ]
224
- }
225
-
226
- data_df = pd.DataFrame(
227
- {"Id_1": [1, 2, 3],
228
- "Me_1": [10, 20, 30]})
229
-
230
- datapoints = {"DS_1": data_df}
231
-
232
- run_result = run(script=script, data_structures=data_structures,
233
- datapoints=datapoints)
234
-
235
- print(run_result)
236
- ```
237
-
238
- returns:
239
-
240
- ``` python
241
- {'DS_A': Dataset(name='DS_A', components={'Id_1': Component(name='Id_1', data_type=<class 'vtlengine.DataTypes.Integer'>, role=<Role.IDENTIFIER: 'Identifier'>, nullable=False), 'Me_1': Component(name='Me_1', data_type=<class 'vtlengine.DataTypes.Number'>, role=<Role.MEASURE: 'Measure'>, nullable=True)}, data= Id_1 Me_1
242
- 0 1 100.0
243
- 1 2 200.0
244
- 2 3 300.0)}
245
- ```
246
-
247
- For more information on usage, please refer to
248
- the [API documentation](https://docs.vtlengine.meaningfuldata.eu/api.html).