alap-python 0.1.0__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.
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: alap-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Alap expression parser for Python — resolve link expressions server-side
|
|
5
|
+
Author: Daniel Smith
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://alap.info
|
|
8
|
+
Project-URL: Repository, https://github.com/DanielSmith/alap-python
|
|
9
|
+
Keywords: alap,expression-parser,links,menu
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Alap Expression Parser — Python
|
|
22
|
+
|
|
23
|
+
[Alap](https://github.com/DanielSmith/alap) is a JavaScript library that turns links into dynamic menus with multiple curated targets. This is the server-side Python port of the expression parser, enabling expression resolution in Python servers without a Node.js sidecar.
|
|
24
|
+
|
|
25
|
+
## What's included
|
|
26
|
+
|
|
27
|
+
- **`expression_parser.py`** — Recursive descent parser for the Alap expression grammar, macro expansion, regex search, config merging
|
|
28
|
+
- **`validate_regex.py`** — ReDoS guard for user-supplied regex patterns
|
|
29
|
+
|
|
30
|
+
## What's NOT included
|
|
31
|
+
|
|
32
|
+
This is the server-side subset of `alap/core`. It covers expression parsing, config merging, and regex validation — everything a server needs to resolve cherry-pick and query requests.
|
|
33
|
+
|
|
34
|
+
Browser-side concerns (DOM rendering, menu positioning, event handling, URL sanitization) are handled by the JavaScript client and are not ported here.
|
|
35
|
+
|
|
36
|
+
## Supported expression syntax
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
item1, item2 # item IDs (comma-separated)
|
|
40
|
+
.coffee # tag query
|
|
41
|
+
.nyc + .bridge # AND (intersection)
|
|
42
|
+
.nyc | .sf # OR (union)
|
|
43
|
+
.nyc - .tourist # WITHOUT (subtraction)
|
|
44
|
+
(.nyc | .sf) + .open # parenthesized grouping
|
|
45
|
+
@favorites # macro expansion
|
|
46
|
+
/mypattern/ # regex search (by pattern key)
|
|
47
|
+
/mypattern/lu # regex with field options
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from expression_parser import ExpressionParser, resolve_expression, cherry_pick_links, merge_configs
|
|
54
|
+
|
|
55
|
+
config = {
|
|
56
|
+
"allLinks": {
|
|
57
|
+
"item1": {"label": "Example", "url": "https://example.com", "tags": ["demo"]},
|
|
58
|
+
"item2": {"label": "Other", "url": "https://other.com", "tags": ["demo", "test"]},
|
|
59
|
+
},
|
|
60
|
+
"macros": {
|
|
61
|
+
"all": {"linkItems": ".demo"}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
# Low-level: get matching IDs
|
|
66
|
+
parser = ExpressionParser(config)
|
|
67
|
+
ids = parser.query(".demo") # ["item1", "item2"]
|
|
68
|
+
ids = parser.query(".demo - .test") # ["item1"]
|
|
69
|
+
|
|
70
|
+
# Convenience: expression -> full link objects
|
|
71
|
+
results = resolve_expression(config, ".demo")
|
|
72
|
+
# [{"id": "item1", "label": "Example", ...}, {"id": "item2", ...}]
|
|
73
|
+
|
|
74
|
+
# Cherry-pick: expression -> { id: link } dict
|
|
75
|
+
subset = cherry_pick_links(config, ".test")
|
|
76
|
+
# {"item2": {"label": "Other", ...}}
|
|
77
|
+
|
|
78
|
+
# Merge multiple configs
|
|
79
|
+
merged = merge_configs(config1, config2)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Installation
|
|
83
|
+
|
|
84
|
+
Copy `expression_parser.py` and `validate_regex.py` into your project, or install from PyPI:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pip install alap
|
|
88
|
+
# or, with uv (recommended):
|
|
89
|
+
uv add alap
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Used by
|
|
93
|
+
|
|
94
|
+
- [flask-sqlite](https://github.com/DanielSmith/alap/tree/main/examples/servers/flask-sqlite) server
|
|
95
|
+
- [fastapi-postgres](https://github.com/DanielSmith/alap/tree/main/examples/servers/fastapi-postgres) server
|
|
96
|
+
- [django-sqlite](https://github.com/DanielSmith/alap/tree/main/examples/servers/django-sqlite) server
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
alap_python-0.1.0.dist-info/METADATA,sha256=pB1rl9_0pp3ly15EgOYt7ahIVE_329psILAePFxXajI,3639
|
|
2
|
+
alap_python-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
3
|
+
alap_python-0.1.0.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
4
|
+
alap_python-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|