An alternative to functional programming
Reason this release was yanked:
Not working
Project description
CLEX (Chained-Lambda-Expressions)
CLEX is a lightweight, string-based Domain Specific Language (DSL) for building clean, readable functional pipelines in Python.
If you've ever chained multiple map, filter, or zip calls together, you know how quickly things become unreadable:
result = list(map(lambda x: x * 2, filter(lambda x: x > 2, data)))
CLEX replaces this with a structured, expressive pipeline string that is easier to read, write, and maintain.
Installation
pip install clex_py
Quick Start
from CLEX import expression
# Compile a pipeline
add_one = expression("(x + 1:)")
# Execute it
result = add_one(x=[1, 2, 3, 4, 5])
print(result) # [2, 3, 4, 5, 6]
Core Concept
A CLEX pipeline is a chain of small, single-purpose operations, written inside a string.
Function Format
(input operation value; return_variable)
Shortcut:
(input operation value:)
→ Automatically assigns the result to the default register _
Anatomy of a Function
Each function has four parts:
-
Input Iterable (
x)- The active dataset
-
Operation
- The transformation, condition, or function applied
-
Acting Value
- A scalar (broadcasted), or another iterable (zipped)
-
Return Variable
- Where the result is stored
Execution Model
- Operations run element-wise
- Scalars are automatically broadcasted
- Iterables are zipped together
- Execution stops at the shortest iterable
- The final step’s result is automatically returned
Operators
Arithmetic
| Operator | Behavior |
|---|---|
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division (skips division by zero) |
| % | Modulus |
Comparison (Filtering)
Comparison operators act as filters:
| Operator | Behavior |
|---|---|
| > | Keep values greater than |
| < | Keep values less than |
| >= | Keep values ≥ |
| <= | Keep values ≤ |
| = | Keep equal values |
| != | Keep non-equal values |
Advanced Operations
| Operator | Behavior |
|---|---|
| @ | Index access (v1[v2]) |
| & | Truthy filter |
| !& | Falsy filter |
| ^ | Intersection |
| !^ | Difference |
| . | Startswith check (returns True/False) |
Chaining Pipelines
Use -> to chain operations:
pipeline = expression("(x + 1; r) -> (r + 2; r)")
result = pipeline(x=[1, 2, 3])
Example: Filtering Even Numbers
from CLEX import expression
is_even = expression("(x % 2; r) -> (x !& r:)")
result = is_even(x=[1, 2, 3, 4, 5])
print(result) # [2, 4]
Custom Lambda Functions
CLEX supports user-defined transformations using square-bracket lambda syntax:
expr = expression("(x [lambda x, y: x + 1] 1; r)")
- Note that lambdas are called for each element in an iterable passed as the first parameter with the second being the scalar.
Requirements
- Must accept two parameters
- Must return an iterable
- Should produce results compatible with element-wise execution
Safety Model
Lambda expressions are executed using Python’s eval, but with strict controls:
- Built-in functions are disabled by default
- Safe functions can be enabled via a whitelist
- Dunder methods are blocked unless explicitly allowed
This ensures controlled execution of dynamic expressions.
Parser & Engine
CLEX uses a modern parsing system designed for flexibility and performance:
- Built with Lark
- Supports arbitrarily long variable names
- Optimized execution pipeline
- Prefix-based result filtering system
Design Philosophy
CLEX is built around a few core ideas:
- Clarity over nesting
- Composable transformations
- Minimal syntax, maximum expressiveness
- Safe execution of dynamic logic
Roadmap
- Port to Java, C#, and JavaScript
- Expand built-in operations
- Improve runtime performance and safety
- Enable deeper integration with Python functions
Contributing
Contributions, issues, and suggestions are welcome.
Summary
CLEX provides:
- A clean DSL for functional pipelines
- A readable alternative to nested functional code
- Safe execution of dynamic expressions
- Extensible and composable transformations
It’s designed for developers who want powerful data transformations without sacrificing readability.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clex_py-0.1.5.tar.gz.
File metadata
- Download URL: clex_py-0.1.5.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
befb01cc9cc643ae5c0d67c69f0416d51342e5f4ad1faaa7084920642a9d73d1
|
|
| MD5 |
78f103214021cb5da3ee87aa6b11edc8
|
|
| BLAKE2b-256 |
9ebf383c03d9538b9b9632b8e590474c112a95f8260667732c1bbb0298722e2e
|
File details
Details for the file clex_py-0.1.5-py3-none-any.whl.
File metadata
- Download URL: clex_py-0.1.5-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26d2a87ead65d9755b950d488b7f07a07acd3016a2a3f59e7fc2b7a366a2fcba
|
|
| MD5 |
cf569d5c8d150f393d6f8480564e5048
|
|
| BLAKE2b-256 |
0454af6fc13a86fe8a0f89652b6b7827864adf5e6213203835414ed92c224e94
|