
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
dataweave-py
Advanced tools
A native Python implementation of the DataWeave data transformation language, providing powerful data transformation capabilities directly in Python without requiring the JVM.
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:
from dwpy import DataWeaveRuntime
# Create a runtime instance
runtime = DataWeaveRuntime()
# Define a DataWeave script
script = """%dw 2.0
output application/json
---
{
message: "Hello, " ++ upper(payload.name),
timestamp: now()
}
"""
# Execute with a payload
payload = {"name": "world"}
result = runtime.execute(script, payload)
print(result)
# Output: {'message': 'Hello, WORLD', 'timestamp': '2025-11-03T...Z'}
from dwpy import DataWeaveRuntime
runtime = DataWeaveRuntime()
# Transform and enrich order data
script = """%dw 2.0
output application/json
---
{
orderId: payload.id,
status: upper(payload.status default "pending"),
total: payload.items reduce ((item, acc = 0) ->
acc + (item.price * (item.quantity default 1))
),
itemCount: sizeOf(payload.items)
}
"""
payload = {
"id": "ORD-123",
"status": "confirmed",
"items": [
{"price": 29.99, "quantity": 2},
{"price": 15.50, "quantity": 1}
]
}
result = runtime.execute(script, payload)
print(result)
# Output: {'orderId': 'ORD-123', 'status': 'CONFIRMED', 'total': 75.48, 'itemCount': 2}
from dwpy import DataWeaveRuntime
runtime = DataWeaveRuntime()
script = """%dw 2.0
output application/json
var requestTime = vars.requestTime default now()
---
{
user: payload.userId,
processedAt: requestTime
}
"""
payload = {"userId": "U-456"}
vars = {"requestTime": "2024-05-05T12:00:00Z"}
result = runtime.execute(script, payload, vars=vars)
from dwpy import DataWeaveRuntime
runtime = DataWeaveRuntime()
script = """%dw 2.0
output application/json
---
{
category: payload.price match {
case var p when p > 100 -> "premium",
case var p when p > 50 -> "standard",
else -> "budget"
}
}
"""
result = runtime.execute(script, {"price": 75})
# Output: {'category': 'standard'}
from dwpy import DataWeaveRuntime
runtime = DataWeaveRuntime()
# Simple interpolation
script = """%dw 2.0
output application/json
---
{
greeting: "Hello $(payload.name)!",
total: "Total: $(payload.price * payload.quantity)",
status: "Order $(payload.orderId) is $(upper(payload.status))"
}
"""
payload = {
"name": "Alice",
"price": 10.5,
"quantity": 3,
"orderId": "ORD-123",
"status": "confirmed"
}
result = runtime.execute(script, payload)
# Output: {
# 'greeting': 'Hello Alice!',
# 'total': 'Total: 31.5',
# 'status': 'Order ORD-123 is CONFIRMED'
# }
String interpolation allows you to embed expressions directly within strings using the $(expression) syntax. The expression can be:
$(payload.name)$(payload.user.email)$(payload.price * 1.1)$(upper(payload.status))DataWeave-Py currently supports a wide range of DataWeave language features:
%dw 2.0, output, var, import).field, ?.field, [index])// and block /* */)payload.field default "fallback")"Hello $(payload.name)")++)--)+, -, *, /)==, !=, >, <, >=, <=)and, or, not)to)if-else)match-case)case var x when condition)map - Transform elementsfilter - Select elementsreduce - Aggregate valuesflatMap - Map and flattendistinctBy - Remove duplicatesgroupBy - Group by criteriaorderBy - Sort elementsupper, lower, trim, contains, startsWith, endsWith, isBlank, splitBy, joinBy, find, match, matches
abs, ceil, floor, round, pow, mod, sum, avg, max, min, random, randomInt, isDecimal, isInteger, isEven, isOdd
sizeOf, isEmpty, flatten, indexOf, lastIndexOf, distinctBy, filterObject, keysOf, valuesOf, entriesOf, pluck, maxBy, minBy
now, isLeapYear, daysBetween
log, logInfo, logDebug, logWarn, logError
The project includes comprehensive test coverage:
# Run all tests
pytest
# Run specific test file
pytest tests/test_runtime_basic.py
# Run with verbose output
pytest -v
# Run with coverage
pytest --cov=dwpy
runtime-2.11.0-20250825-src/
βββ dwpy/ # Main Python package
β βββ __init__.py # Package exports
β βββ parser.py # DataWeave parser
β βββ runtime.py # Execution engine
β βββ builtins.py # Built-in functions
βββ tests/ # Test suite
β βββ test_runtime_basic.py # Core functionality tests
β βββ test_builtins.py # Built-in function tests
β βββ fixtures/ # Test data and fixtures
βββ runtime-2.11.0-20250825/ # Original JVM runtime reference
βββ docs/ # Documentation
βββ pyproject.toml # Project configuration
βββ README.md # This file
# Create virtual environment
uv venv --python 3.12
source .venv/bin/activate
# Install development dependencies
uv pip sync
# Install in editable mode
pip install -e .
# Run all tests
python -m pytest tests/
# Run specific test category
python -m pytest tests/test_builtins.py
# Run with coverage report
python -m pytest --cov=dwpy --cov-report=html tests/
The project follows standard Python conventions:
DataWeave-Py aims to provide feature parity with the official JVM-based DataWeave runtime. Key differences:
| Feature | JVM Runtime | DataWeave-Py |
|---|---|---|
| Language | Scala | Python |
| Performance | High (compiled) | Good (interpreted) |
| Startup Time | Slower (JVM warmup) | Fast (native Python) |
| Memory Usage | Higher (JVM overhead) | Lower (Python runtime) |
| Integration | Java/Mule apps | Python apps |
| Module System | Full support | In progress |
| Type System | Static typing | Dynamic typing |
Contributions are welcome! Please:
git checkout -b feature/amazing-feature)pytest)git commit -m 'feat: add amazing feature')git push origin feature/amazing-feature)See the original DataWeave runtime license terms. This project is a reference implementation for educational and development purposes.
For questions, issues, or contributions:
docs/ directorytests/ for usage examplesNote: 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.
FAQs
DataWeave interpreter running natively on Python
We found that dataweave-py demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.