cql2 0.4.1__cp310-abi3-macosx_11_0_arm64.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.
- cql2/__init__.py +5 -0
- cql2/__init__.pyi +167 -0
- cql2/cql2.abi3.so +0 -0
- cql2/py.typed +0 -0
- cql2-0.4.1.dist-info/METADATA +14 -0
- cql2-0.4.1.dist-info/RECORD +9 -0
- cql2-0.4.1.dist-info/WHEEL +4 -0
- cql2-0.4.1.dist-info/entry_points.txt +2 -0
- cql2-0.4.1.dist-info/licenses/LICENSE +7 -0
cql2/__init__.py
ADDED
cql2/__init__.pyi
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
from os import PathLike
|
|
3
|
+
|
|
4
|
+
def parse_file(path: PathLike | str) -> Expr:
|
|
5
|
+
"""Parses CQL2 from a filesystem path.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
path (PathLike | str): The input path
|
|
9
|
+
|
|
10
|
+
Returns:
|
|
11
|
+
Expr: The CQL2 expression
|
|
12
|
+
|
|
13
|
+
Examples:
|
|
14
|
+
>>> from cql2 import Expr
|
|
15
|
+
>>> expr = Expr.parse_file("fixtures/text/example01.txt")
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def parse_text(s: str) -> Expr:
|
|
19
|
+
"""Parses cql2-text.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
s (str): The cql2-text
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
Expr: The CQL2 expression
|
|
26
|
+
|
|
27
|
+
Raises:
|
|
28
|
+
ParseError: Raised if the string does not parse as cql2-text
|
|
29
|
+
|
|
30
|
+
Examples:
|
|
31
|
+
>>> from cql2 import Expr
|
|
32
|
+
>>> expr = Expr.parse_text("landsat:scene_id = 'LC82030282019133LGN00'")
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def parse_json(s: str) -> Expr:
|
|
36
|
+
"""Parses cql2-json.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
s (str): The cql2-json string
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
Expr: The CQL2 expression
|
|
43
|
+
|
|
44
|
+
Raises:
|
|
45
|
+
ParseError: Raised if the string does not parse as cql2-json
|
|
46
|
+
|
|
47
|
+
Examples:
|
|
48
|
+
>>> from cql2 import Expr
|
|
49
|
+
>>> expr = Expr.parse_json('{"op":"=","args":[{"property":"landsat:scene_id"},"LC82030282019133LGN00"]}')
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
class Expr:
|
|
53
|
+
def __init__(self, cql2: str | dict[str, Any]) -> None:
|
|
54
|
+
"""A CQL2 expression.
|
|
55
|
+
|
|
56
|
+
The cql2 can either be a cql2-text string, a cql2-json string, or a
|
|
57
|
+
cql2-json dictionary.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
cql2 (str | dict[str, Any]): The input CQL2
|
|
61
|
+
|
|
62
|
+
Examples:
|
|
63
|
+
>>> from cql2 import Expr
|
|
64
|
+
>>> expr = Expr("landsat:scene_id = 'LC82030282019133LGN00'")
|
|
65
|
+
>>> expr = Expr({"op":"=","args":[{"property":"landsat:scene_id"},"LC82030282019133LGN00"]})
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
def validate(self) -> None:
|
|
69
|
+
"""Validates this expression using json-schema.
|
|
70
|
+
|
|
71
|
+
Raises:
|
|
72
|
+
ValidationError: Raised if the validation fails
|
|
73
|
+
|
|
74
|
+
Examples:
|
|
75
|
+
>>> from cql2 import Expr
|
|
76
|
+
>>> expr = Expr("landsat:scene_id = 'LC82030282019133LGN00'")
|
|
77
|
+
>>> expr.validate()
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
def matches(self, item: dict[str, Any]) -> bool:
|
|
81
|
+
"""Matches this expression against an item.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
item (dict[str, Any]): The item to match against
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
bool: True if the expression matches the item, False otherwise
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
def reduce(self, item: dict[str, Any] | None = None) -> Expr:
|
|
91
|
+
"""Reduces this expression against an item.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
item (dict[str, Any] | None): The item to reduce against
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
Expr: The reduced expression
|
|
98
|
+
|
|
99
|
+
Examples:
|
|
100
|
+
>>> from cql2 import Expr
|
|
101
|
+
>>> expr = Expr("true AND true").reduce()
|
|
102
|
+
>>> expr.to_text()
|
|
103
|
+
'true'
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
def to_json(self) -> dict[str, Any]:
|
|
107
|
+
"""Converts this cql2 expression to a cql2-json dictionary.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
dict[str, Any]: The cql2-json
|
|
111
|
+
|
|
112
|
+
Examples:
|
|
113
|
+
>>> from cql2 import Expr
|
|
114
|
+
>>> expr = Expr("landsat:scene_id = 'LC82030282019133LGN00'")
|
|
115
|
+
>>> expr.to_json()
|
|
116
|
+
{'op': '=', 'args': [{'property': 'landsat:scene_id'}, 'LC82030282019133LGN00']}
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
def to_text(self) -> str:
|
|
120
|
+
"""Converts this cql2 expression to cql2-text.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
str: The cql2-text
|
|
124
|
+
|
|
125
|
+
Examples:
|
|
126
|
+
>>> from cql2 import Expr
|
|
127
|
+
>>> expr = Expr({"op":"=","args":[{"property":"landsat:scene_id"},"LC82030282019133LGN00"]})
|
|
128
|
+
>>> expr.to_text()
|
|
129
|
+
'("landsat:scene_id" = \'LC82030282019133LGN00\')'
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
def to_sql(self) -> str:
|
|
133
|
+
"""Converts this cql2 expression to a SQL query.
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
str: The SQL query
|
|
137
|
+
|
|
138
|
+
Examples:
|
|
139
|
+
>>> from cql2 import Expr
|
|
140
|
+
>>> expr = Expr("landsat:scene_id = 'LC82030282019133LGN00'")
|
|
141
|
+
>>> q.query
|
|
142
|
+
'("landsat:scene_id" = $1)'
|
|
143
|
+
>>> q.params
|
|
144
|
+
['LC82030282019133LGN00']
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
def __add__(self, other: Expr) -> Expr:
|
|
148
|
+
"""Combines two cql2 expressions using the AND operator.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
other (Expr): The other expression
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
Expr: The combined expression
|
|
155
|
+
|
|
156
|
+
Examples:
|
|
157
|
+
>>> from cql2 import Expr
|
|
158
|
+
>>> expr1 = Expr("landsat:scene_id = 'LC82030282019133LGN00'")
|
|
159
|
+
>>> expr2 = Expr("landsat:cloud_cover = 10")
|
|
160
|
+
>>> expr = expr1 + expr2
|
|
161
|
+
"""
|
|
162
|
+
|
|
163
|
+
class ParseError(Exception):
|
|
164
|
+
"""An error raised when cql2 parsing fails."""
|
|
165
|
+
|
|
166
|
+
class ValidationError(Exception):
|
|
167
|
+
"""An error raised when cql2 json-schema validation fails."""
|
cql2/cql2.abi3.so
ADDED
|
Binary file
|
cql2/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cql2
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Classifier: Programming Language :: Rust
|
|
5
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Home-Page: https://github.com/developmentseed/cql2-rs
|
|
14
|
+
Requires-Python: >=3.10
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
cql2-0.4.1.dist-info/METADATA,sha256=jsRhL9bN4G53ID3cTBULcr0XEo4sex_hHiZwrugRUQI,585
|
|
2
|
+
cql2-0.4.1.dist-info/WHEEL,sha256=-lwEpi49KOTCcgx48T3fLSP8Dxynwa-iRMZNo-JZaqc,103
|
|
3
|
+
cql2-0.4.1.dist-info/entry_points.txt,sha256=71myRgqcjlXJ5L8YfBsyaQS-Ef8mXeSlOCDwf1rrURo,33
|
|
4
|
+
cql2-0.4.1.dist-info/licenses/LICENSE,sha256=t0LRkl7HEgDhGmOHdjpbyyLoAOmMcNfXAunBk1N18S4,1064
|
|
5
|
+
cql2/__init__.py,sha256=lQIzMwXTmBW1tLuKrIKf3_nxwWMiik5UOd5CBYV22uQ,99
|
|
6
|
+
cql2/__init__.pyi,sha256=LEYKGkqZwmN7ZdxObxgq07Fq3a4A2VLcAyXvCMG3kRk,4631
|
|
7
|
+
cql2/cql2.abi3.so,sha256=AgGE2drsh7Najgdp8-Kk3gSw6caRwAMV90b_uXVvnNE,9118832
|
|
8
|
+
cql2/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
cql2-0.4.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2024 Development Seed
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|