dataweave-py 0.1.0__tar.gz

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 (52) hide show
  1. dataweave_py-0.1.0/LICENSE +22 -0
  2. dataweave_py-0.1.0/MANIFEST.in +4 -0
  3. dataweave_py-0.1.0/PKG-INFO +391 -0
  4. dataweave_py-0.1.0/README.md +360 -0
  5. dataweave_py-0.1.0/dataweave_py.egg-info/PKG-INFO +391 -0
  6. dataweave_py-0.1.0/dataweave_py.egg-info/SOURCES.txt +50 -0
  7. dataweave_py-0.1.0/dataweave_py.egg-info/dependency_links.txt +1 -0
  8. dataweave_py-0.1.0/dataweave_py.egg-info/requires.txt +4 -0
  9. dataweave_py-0.1.0/dataweave_py.egg-info/top_level.txt +1 -0
  10. dataweave_py-0.1.0/dwpy/__init__.py +3 -0
  11. dataweave_py-0.1.0/dwpy/builtins.py +852 -0
  12. dataweave_py-0.1.0/dwpy/modules/dw/Core.bdwl +0 -0
  13. dataweave_py-0.1.0/dwpy/modules/dw/Core.dwl +7462 -0
  14. dataweave_py-0.1.0/dwpy/modules/dw/Crypto.bdwl +0 -0
  15. dataweave_py-0.1.0/dwpy/modules/dw/Crypto.dwl +231 -0
  16. dataweave_py-0.1.0/dwpy/modules/dw/Runtime.bdwl +0 -0
  17. dataweave_py-0.1.0/dwpy/modules/dw/Runtime.dwl +1588 -0
  18. dataweave_py-0.1.0/dwpy/modules/dw/System.bdwl +0 -0
  19. dataweave_py-0.1.0/dwpy/modules/dw/System.dwl +92 -0
  20. dataweave_py-0.1.0/dwpy/modules/dw/core/Arrays.dwl +1329 -0
  21. dataweave_py-0.1.0/dwpy/modules/dw/core/Binaries.dwl +306 -0
  22. dataweave_py-0.1.0/dwpy/modules/dw/core/Dates.dwl +1131 -0
  23. dataweave_py-0.1.0/dwpy/modules/dw/core/Numbers.dwl +311 -0
  24. dataweave_py-0.1.0/dwpy/modules/dw/core/Objects.dwl +547 -0
  25. dataweave_py-0.1.0/dwpy/modules/dw/extension/DataFormat.bdwl +0 -0
  26. dataweave_py-0.1.0/dwpy/modules/dw/extension/DataFormat.dwl +75 -0
  27. dataweave_py-0.1.0/dwpy/modules/dw/module/Mime.bdwl +0 -0
  28. dataweave_py-0.1.0/dwpy/modules/dw/module/Mime.dwl +266 -0
  29. dataweave_py-0.1.0/dwpy/modules/dw/module/Multipart.bdwl +0 -0
  30. dataweave_py-0.1.0/dwpy/modules/dw/module/Multipart.dwl +662 -0
  31. dataweave_py-0.1.0/dwpy/modules/dw/util/Coercions.bdwl +0 -0
  32. dataweave_py-0.1.0/dwpy/modules/dw/util/Coercions.dwl +1836 -0
  33. dataweave_py-0.1.0/dwpy/modules/dw/util/Diff.bdwl +0 -0
  34. dataweave_py-0.1.0/dwpy/modules/dw/util/Diff.dwl +363 -0
  35. dataweave_py-0.1.0/dwpy/modules/dw/util/Math.bdwl +0 -0
  36. dataweave_py-0.1.0/dwpy/modules/dw/util/Math.dwl +588 -0
  37. dataweave_py-0.1.0/dwpy/modules/dw/util/Timer.bdwl +0 -0
  38. dataweave_py-0.1.0/dwpy/modules/dw/util/Timer.dwl +199 -0
  39. dataweave_py-0.1.0/dwpy/modules/dw/util/Tree.bdwl +0 -0
  40. dataweave_py-0.1.0/dwpy/modules/dw/util/Tree.dwl +801 -0
  41. dataweave_py-0.1.0/dwpy/modules/dw/util/Values.bdwl +0 -0
  42. dataweave_py-0.1.0/dwpy/modules/dw/util/Values.dwl +777 -0
  43. dataweave_py-0.1.0/dwpy/modules/dw/xml/Dtd.bdwl +0 -0
  44. dataweave_py-0.1.0/dwpy/modules/dw/xml/Dtd.dwl +100 -0
  45. dataweave_py-0.1.0/dwpy/parser.py +886 -0
  46. dataweave_py-0.1.0/dwpy/runtime.py +750 -0
  47. dataweave_py-0.1.0/pyproject.toml +64 -0
  48. dataweave_py-0.1.0/setup.cfg +4 -0
  49. dataweave_py-0.1.0/tests/test_builtins.py +148 -0
  50. dataweave_py-0.1.0/tests/test_objects_module.py +114 -0
  51. dataweave_py-0.1.0/tests/test_runtime_basic.py +537 -0
  52. dataweave_py-0.1.0/tests/test_string_interpolation.py +232 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 [Your Name]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,4 @@
1
+ include README.md
2
+ include LICENSE
3
+ recursive-include dwpy/modules *.dwl *.bdwl
4
+
@@ -0,0 +1,391 @@
1
+ Metadata-Version: 2.4
2
+ Name: dataweave-py
3
+ Version: 0.1.0
4
+ Summary: DataWeave interpreter running natively on Python
5
+ Author-email: Your Name <your.email@example.com>
6
+ Maintainer-email: Your Name <your.email@example.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/estebanwasinger/dataweave-py
9
+ Project-URL: Documentation, https://github.com/estebanwasinger/dataweave-py#readme
10
+ Project-URL: Repository, https://github.com/estebanwasinger/dataweave-py
11
+ Project-URL: Issues, https://github.com/estebanwasinger/dataweave-py/issues
12
+ Keywords: dataweave,data-transformation,etl,mulesoft,interpreter,functional-programming
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Software Development :: Interpreters
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Operating System :: OS Independent
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=8.4.2; extra == "dev"
29
+ Requires-Dist: ipykernel>=7.1.0; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # DataWeave-Py
33
+
34
+ A native Python implementation of the DataWeave data transformation language, providing powerful data transformation capabilities directly in Python without requiring the JVM.
35
+
36
+ ## Overview
37
+
38
+ DataWeave-Py (`dwpy`) is a Python interpreter for the DataWeave language, originally developed by MuleSoft for data transformation in the Mule runtime. This project brings DataWeave's expressive transformation syntax and rich feature set to the Python ecosystem, enabling:
39
+
40
+ - **Data transformation**: Convert between JSON, XML, CSV and other formats
41
+ - **Functional programming**: Leverage map, filter, reduce, and other functional operators
42
+ - **Pattern matching**: Use powerful match expressions with guards and bindings
43
+ - **Safe navigation**: Handle null values gracefully with null-safe operators
44
+ - **Rich built-ins**: Access 100+ built-in functions for strings, numbers, dates, arrays, and objects
45
+
46
+ ## Requirements
47
+
48
+ - Python 3.10 or higher
49
+ - Dependencies managed via [uv](https://github.com/astral-sh/uv) (recommended) or pip
50
+
51
+ ## Quick Start
52
+
53
+ ### Basic Usage
54
+
55
+ ```python
56
+ from dwpy import DataWeaveRuntime
57
+
58
+ # Create a runtime instance
59
+ runtime = DataWeaveRuntime()
60
+
61
+ # Define a DataWeave script
62
+ script = """%dw 2.0
63
+ output application/json
64
+ ---
65
+ {
66
+ message: "Hello, " ++ upper(payload.name),
67
+ timestamp: now()
68
+ }
69
+ """
70
+
71
+ # Execute with a payload
72
+ payload = {"name": "world"}
73
+ result = runtime.execute(script, payload)
74
+
75
+ print(result)
76
+ # Output: {'message': 'Hello, WORLD', 'timestamp': '2025-11-03T...Z'}
77
+ ```
78
+
79
+ ### Data Transformation Example
80
+
81
+ ```python
82
+ from dwpy import DataWeaveRuntime
83
+
84
+ runtime = DataWeaveRuntime()
85
+
86
+ # Transform and enrich order data
87
+ script = """%dw 2.0
88
+ output application/json
89
+ ---
90
+ {
91
+ orderId: payload.id,
92
+ status: upper(payload.status default "pending"),
93
+ total: payload.items reduce ((item, acc = 0) ->
94
+ acc + (item.price * (item.quantity default 1))
95
+ ),
96
+ itemCount: sizeOf(payload.items)
97
+ }
98
+ """
99
+
100
+ payload = {
101
+ "id": "ORD-123",
102
+ "status": "confirmed",
103
+ "items": [
104
+ {"price": 29.99, "quantity": 2},
105
+ {"price": 15.50, "quantity": 1}
106
+ ]
107
+ }
108
+
109
+ result = runtime.execute(script, payload)
110
+ print(result)
111
+ # Output: {'orderId': 'ORD-123', 'status': 'CONFIRMED', 'total': 75.48, 'itemCount': 2}
112
+ ```
113
+
114
+ ### Using Variables
115
+
116
+ ```python
117
+ from dwpy import DataWeaveRuntime
118
+
119
+ runtime = DataWeaveRuntime()
120
+
121
+ script = """%dw 2.0
122
+ output application/json
123
+ var requestTime = vars.requestTime default now()
124
+ ---
125
+ {
126
+ user: payload.userId,
127
+ processedAt: requestTime
128
+ }
129
+ """
130
+
131
+ payload = {"userId": "U-456"}
132
+ vars = {"requestTime": "2024-05-05T12:00:00Z"}
133
+
134
+ result = runtime.execute(script, payload, vars=vars)
135
+ ```
136
+
137
+ ### Pattern Matching
138
+
139
+ ```python
140
+ from dwpy import DataWeaveRuntime
141
+
142
+ runtime = DataWeaveRuntime()
143
+
144
+ script = """%dw 2.0
145
+ output application/json
146
+ ---
147
+ {
148
+ category: payload.price match {
149
+ case var p when p > 100 -> "premium",
150
+ case var p when p > 50 -> "standard",
151
+ else -> "budget"
152
+ }
153
+ }
154
+ """
155
+
156
+ result = runtime.execute(script, {"price": 75})
157
+ # Output: {'category': 'standard'}
158
+ ```
159
+
160
+ ### String Interpolation
161
+
162
+ ```python
163
+ from dwpy import DataWeaveRuntime
164
+
165
+ runtime = DataWeaveRuntime()
166
+
167
+ # Simple interpolation
168
+ script = """%dw 2.0
169
+ output application/json
170
+ ---
171
+ {
172
+ greeting: "Hello $(payload.name)!",
173
+ total: "Total: $(payload.price * payload.quantity)",
174
+ status: "Order $(payload.orderId) is $(upper(payload.status))"
175
+ }
176
+ """
177
+
178
+ payload = {
179
+ "name": "Alice",
180
+ "price": 10.5,
181
+ "quantity": 3,
182
+ "orderId": "ORD-123",
183
+ "status": "confirmed"
184
+ }
185
+
186
+ result = runtime.execute(script, payload)
187
+ # Output: {
188
+ # 'greeting': 'Hello Alice!',
189
+ # 'total': 'Total: 31.5',
190
+ # 'status': 'Order ORD-123 is CONFIRMED'
191
+ # }
192
+ ```
193
+
194
+ String interpolation allows you to embed expressions directly within strings using the `$(expression)` syntax. The expression can be:
195
+ - Property access: `$(payload.name)`
196
+ - Nested properties: `$(payload.user.email)`
197
+ - Expressions: `$(payload.price * 1.1)`
198
+ - Function calls: `$(upper(payload.status))`
199
+ - Any valid DataWeave expression
200
+
201
+ ## Supported Features
202
+
203
+ DataWeave-Py currently supports a wide range of DataWeave language features:
204
+
205
+ ### Core Language Features
206
+ - ✅ Header directives (`%dw 2.0`, `output`, `var`, `import`)
207
+ - ✅ Payload and variable access
208
+ - ✅ Object and array literals
209
+ - ✅ Field selectors (`.field`, `?.field`, `[index]`)
210
+ - ✅ Comments (line `//` and block `/* */`)
211
+ - ✅ Default values (`payload.field default "fallback"`)
212
+ - ✅ String interpolation (`"Hello $(payload.name)"`)
213
+
214
+ ### Operators
215
+ - ✅ Concatenation (`++`)
216
+ - ✅ Difference (`--`)
217
+ - ✅ Arithmetic (`+`, `-`, `*`, `/`)
218
+ - ✅ Comparison (`==`, `!=`, `>`, `<`, `>=`, `<=`)
219
+ - ✅ Logical (`and`, `or`, `not`)
220
+ - ✅ Range (`to`)
221
+
222
+ ### Control Flow
223
+ - ✅ Conditional expressions (`if-else`)
224
+ - ✅ Pattern matching (`match-case`)
225
+ - ✅ Match guards (`case var x when condition`)
226
+
227
+ ### Collection Operations
228
+ - ✅ `map` - Transform elements
229
+ - ✅ `filter` - Select elements
230
+ - ✅ `reduce` - Aggregate values
231
+ - ✅ `flatMap` - Map and flatten
232
+ - ✅ `distinctBy` - Remove duplicates
233
+ - ✅ `groupBy` - Group by criteria
234
+ - ✅ `orderBy` - Sort elements
235
+
236
+ ### Built-in Functions
237
+
238
+ #### String Functions
239
+ `upper`, `lower`, `trim`, `contains`, `startsWith`, `endsWith`, `isBlank`, `splitBy`, `joinBy`, `find`, `match`, `matches`
240
+
241
+ #### Numeric Functions
242
+ `abs`, `ceil`, `floor`, `round`, `pow`, `mod`, `sum`, `avg`, `max`, `min`, `random`, `randomInt`, `isDecimal`, `isInteger`, `isEven`, `isOdd`
243
+
244
+ #### Array/Object Functions
245
+ `sizeOf`, `isEmpty`, `flatten`, `indexOf`, `lastIndexOf`, `distinctBy`, `filterObject`, `keysOf`, `valuesOf`, `entriesOf`, `pluck`, `maxBy`, `minBy`
246
+
247
+ #### Date Functions
248
+ `now`, `isLeapYear`, `daysBetween`
249
+
250
+ #### Utility Functions
251
+ `log`, `logInfo`, `logDebug`, `logWarn`, `logError`
252
+
253
+ ## Running Tests
254
+
255
+ The project includes comprehensive test coverage:
256
+
257
+ ```bash
258
+ # Run all tests
259
+ pytest
260
+
261
+ # Run specific test file
262
+ pytest tests/test_runtime_basic.py
263
+
264
+ # Run with verbose output
265
+ pytest -v
266
+
267
+ # Run with coverage
268
+ pytest --cov=dwpy
269
+ ```
270
+
271
+ ## Project Structure
272
+
273
+ ```
274
+ runtime-2.11.0-20250825-src/
275
+ ├── dwpy/ # Main Python package
276
+ │ ├── __init__.py # Package exports
277
+ │ ├── parser.py # DataWeave parser
278
+ │ ├── runtime.py # Execution engine
279
+ │ └── builtins.py # Built-in functions
280
+ ├── tests/ # Test suite
281
+ │ ├── test_runtime_basic.py # Core functionality tests
282
+ │ ├── test_builtins.py # Built-in function tests
283
+ │ └── fixtures/ # Test data and fixtures
284
+ ├── runtime-2.11.0-20250825/ # Original JVM runtime reference
285
+ ├── docs/ # Documentation
286
+ ├── pyproject.toml # Project configuration
287
+ └── README.md # This file
288
+ ```
289
+
290
+ ## Development
291
+
292
+ ### Setting Up Development Environment
293
+
294
+ ```bash
295
+ # Create virtual environment
296
+ uv venv --python 3.12
297
+ source .venv/bin/activate
298
+
299
+ # Install development dependencies
300
+ uv pip sync
301
+
302
+ # Install in editable mode
303
+ pip install -e .
304
+ ```
305
+
306
+ ### Running the Test Suite
307
+
308
+ ```bash
309
+ # Run all tests
310
+ python -m pytest tests/
311
+
312
+ # Run specific test category
313
+ python -m pytest tests/test_builtins.py
314
+
315
+ # Run with coverage report
316
+ python -m pytest --cov=dwpy --cov-report=html tests/
317
+ ```
318
+
319
+ ### Code Style
320
+
321
+ The project follows standard Python conventions:
322
+ - PEP 8 style guide
323
+ - Type hints where appropriate
324
+ - Comprehensive docstrings
325
+ - Two-space indentation for consistency with Scala codebase
326
+
327
+ ## Comparison with JVM Runtime
328
+
329
+ DataWeave-Py aims to provide feature parity with the official JVM-based DataWeave runtime. Key differences:
330
+
331
+ | Feature | JVM Runtime | DataWeave-Py |
332
+ |---------|-------------|--------------|
333
+ | Language | Scala | Python |
334
+ | Performance | High (compiled) | Good (interpreted) |
335
+ | Startup Time | Slower (JVM warmup) | Fast (native Python) |
336
+ | Memory Usage | Higher (JVM overhead) | Lower (Python runtime) |
337
+ | Integration | Java/Mule apps | Python apps |
338
+ | Module System | Full support | In progress |
339
+ | Type System | Static typing | Dynamic typing |
340
+
341
+ ## Roadmap
342
+
343
+ ### Current Status (v0.1.0)
344
+ - ✅ Core language parser
345
+ - ✅ Expression evaluation
346
+ - ✅ 60+ built-in functions
347
+ - ✅ Pattern matching
348
+ - ✅ Collection operators
349
+
350
+ ### Planned Features
351
+ - 🔄 Full module system support
352
+ - 🔄 Import statements
353
+ - 🔄 Custom function definitions
354
+ - 🔄 XML/CSV format support
355
+ - 🔄 Streaming for large datasets
356
+ - 🔄 Type validation
357
+ - 🔄 Performance optimizations
358
+
359
+ ## Contributing
360
+
361
+ Contributions are welcome! Please:
362
+
363
+ 1. Fork the repository
364
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
365
+ 3. Write tests for your changes
366
+ 4. Ensure all tests pass (`pytest`)
367
+ 5. Commit your changes (`git commit -m 'feat: add amazing feature'`)
368
+ 6. Push to the branch (`git push origin feature/amazing-feature`)
369
+ 7. Open a Pull Request
370
+
371
+ ## License
372
+
373
+ See the original DataWeave runtime license terms. This project is a reference implementation for educational and development purposes.
374
+
375
+ ## Resources
376
+
377
+ - [DataWeave Documentation](https://docs.mulesoft.com/dataweave/)
378
+ - [DataWeave Tutorial](https://developer.mulesoft.com/tutorials-and-howtos/dataweave/)
379
+ - [DataWeave Playground](https://dataweave.mulesoft.com/learn/playground)
380
+
381
+ ## Support
382
+
383
+ For questions, issues, or contributions:
384
+ - Open an issue on GitHub
385
+ - Check existing documentation in the `docs/` directory
386
+ - Review test cases in `tests/` for usage examples
387
+
388
+ ---
389
+
390
+ **Note**: This is an independent Python implementation and is not officially supported by MuleSoft. For production use cases requiring full DataWeave compatibility, please use the official JVM-based runtime.
391
+