xpr-python — XPR Expression Language for Python
XPR is a sandboxed cross-language expression language for data pipeline transforms. This is the Python runtime.
Install
pip install xpr-lang
Requires Python 3.10+.
Quick Start
from xpr import Xpr
engine = Xpr()
engine.evaluate('items.filter(x => x.price > 50).map(x => x.name)', {
'items': [
{'name': 'Widget', 'price': 25},
{'name': 'Gadget', 'price': 75},
{'name': 'Doohickey', 'price': 100},
]
})
# → ["Gadget", "Doohickey"]
API
evaluate(expression, context=None)
Evaluates an XPR expression against an optional context object.
from xpr import Xpr
engine = Xpr()
engine.evaluate('1 + 2') # → 3
engine.evaluate('user.name', {'user': {'name': 'Alice'}}) # → "Alice"
engine.evaluate('items.length', {'items': [1, 2, 3]}) # → 3
Returns the result as object. Raises XprError on parse or evaluation errors.
add_function(name, fn)
Register a custom function callable from expressions:
from xpr import Xpr
engine = Xpr()
engine.add_function('double', lambda x: x * 2)
engine.add_function('greet', lambda name: f'Hello, {name}!')
engine.evaluate('double(21)') # → 42
engine.evaluate('greet("World")') # → "Hello, World!"
engine.evaluate('items.map(x => double(x))', {'items': [1, 2, 3]}) # → [2, 4, 6]
Built-in Functions
Math: round, floor, ceil, abs, min, max
Type: type, int, float, string, bool
String methods: .len(), .upper(), .lower(), .trim(), .startsWith(), .endsWith(), .contains(), .split(), .replace(), .slice(), .indexOf(), .repeat(), .trimStart(), .trimEnd(), .charAt(), .padStart(), .padEnd()
Array methods: .map(), .filter(), .reduce(), .find(), .some(), .every(), .flatMap(), .sort(), .reverse(), .length, .includes(), .indexOf(), .slice(), .join(), .concat(), .flat(), .unique(), .zip(), .chunk(), .groupBy()
Object methods: .keys(), .values(), .entries(), .has()
Utility: range()
v0.2 Features
Let Bindings: Immutable scoped bindings allow you to define and reuse values within expressions:
engine.evaluate('let x = 1; let y = x + 1; y') # → 2
engine.evaluate('let items = [1, 2, 3]; items.map(x => x * 2)', {}) # → [2, 4, 6]
Spread Operator: Spread syntax for arrays and objects enables composition and merging:
engine.evaluate('[1, 2, ...[3, 4]]') # → [1, 2, 3, 4]
engine.evaluate('{...{a: 1}, b: 2}') # → {'a': 1, 'b': 2}
Conformance
This runtime supports Level 1–3 (all conformance levels):
- Level 1: Literals, arithmetic, comparison, logic, ternary, property access, function calls
- Level 2: Arrow functions, collection methods, string methods, template literals
- Level 3: Pipe operator (
|>), optional chaining (?.), nullish coalescing (??)
v0.2 additions: Let bindings, spread operator, 20 new built-in methods (10 array, 7 string, 2 object, 1 global)
Passes all conformance tests (Levels 1–3 plus v0.2 features).
Specification
See the XPR Language Specification for the full EBNF grammar, type system, operator precedence, and conformance test suite.
License
MIT
Metadata
Release files for xpr-lang 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| xpr_lang-0.5.0.tar.gz | 53.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xpr_lang-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 75.2 kB
Release files / xpr_lang-0.5.0.tar.gz
| Download URL | xpr_lang-0.5.0.tar.gz |
|---|---|
| Size | 53.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e89e745f035e1725ea60357d22d0a9596b54ab24e0a0e757cfc7ab152ff713e9
|
|
BLAKE2b-256 checksum How to use checksums |
966758e5db26c6f6b5a5a7f90f4170ba3b160f2cff673c7b7d06efc5a049d56a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 15, 2026.
Transparency logRelease files / xpr_lang-0.5.0-py3-none-any.whl
| Download URL | xpr_lang-0.5.0-py3-none-any.whl |
|---|---|
| Size | 21.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b5276c43640406e56509438dceafe9b6ff771296aa8c70824a99d87d4a27088e
|
|
BLAKE2b-256 checksum How to use checksums |
91c9fa64f9134ed997a42c754f1b4d045ef9cd8b1b889181210182e3042ebe96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 15, 2026.
Transparency log