enforce-rules 3.2.3__tar.gz → 3.2.5__tar.gz
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.
- {enforce_rules-3.2.3/src/enforce_rules.egg-info → enforce_rules-3.2.5}/PKG-INFO +28 -28
- {enforce_rules-3.2.3 → enforce_rules-3.2.5}/README.md +28 -28
- {enforce_rules-3.2.3 → enforce_rules-3.2.5}/pyproject.toml +1 -1
- {enforce_rules-3.2.3 → enforce_rules-3.2.5}/src/enforce_rules/enforce_rules.py +1 -1
- {enforce_rules-3.2.3 → enforce_rules-3.2.5/src/enforce_rules.egg-info}/PKG-INFO +28 -28
- {enforce_rules-3.2.3 → enforce_rules-3.2.5}/LICENSE +0 -0
- {enforce_rules-3.2.3 → enforce_rules-3.2.5}/setup.cfg +0 -0
- {enforce_rules-3.2.3 → enforce_rules-3.2.5}/src/enforce_rules/__init__.py +0 -0
- {enforce_rules-3.2.3 → enforce_rules-3.2.5}/src/enforce_rules.egg-info/SOURCES.txt +0 -0
- {enforce_rules-3.2.3 → enforce_rules-3.2.5}/src/enforce_rules.egg-info/dependency_links.txt +0 -0
- {enforce_rules-3.2.3 → enforce_rules-3.2.5}/src/enforce_rules.egg-info/top_level.txt +0 -0
- {enforce_rules-3.2.3 → enforce_rules-3.2.5}/tests/test_enforce_rules.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: enforce-rules
|
|
3
|
-
Version: 3.2.
|
|
3
|
+
Version: 3.2.5
|
|
4
4
|
Summary: Runtime rule validation for Python using dictionary-based constraints.
|
|
5
5
|
Author: Jake Loepker, Microsoft Copilot (AI Assistant)
|
|
6
6
|
License: BSD 3-Clause License
|
|
@@ -63,7 +63,7 @@ MAJOR: 3
|
|
|
63
63
|
|
|
64
64
|
MINOR: 2
|
|
65
65
|
|
|
66
|
-
PATCH:
|
|
66
|
+
PATCH: 5
|
|
67
67
|
|
|
68
68
|
If you need to catch up, you can see the full version history in the [CHANGELOG](https://github.com/Loepker-James/enforce-rules/blob/main/CHANGELOG.md).
|
|
69
69
|
|
|
@@ -120,7 +120,7 @@ This means validated values behave exactly like normal Python values.
|
|
|
120
120
|
Keywords and Usage
|
|
121
121
|
Below are all supported keywords.
|
|
122
122
|
|
|
123
|
-
length
|
|
123
|
+
## length
|
|
124
124
|
|
|
125
125
|
The length of the object must be exactly this.
|
|
126
126
|
|
|
@@ -128,70 +128,70 @@ The length of the object must be exactly this.
|
|
|
128
128
|
lst = validate([1, 2, 3, 4, 5], {"length": 5})
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
min_length
|
|
131
|
+
## min_length
|
|
132
132
|
|
|
133
133
|
Minimum length (inclusive).
|
|
134
134
|
|
|
135
135
|
```python
|
|
136
136
|
lst = validate(['a', 'b', 'c', 'd', 'e'], {"min_length": 3})
|
|
137
137
|
```
|
|
138
|
-
max_length
|
|
138
|
+
## max_length
|
|
139
139
|
|
|
140
140
|
Maximum length (inclusive).
|
|
141
141
|
|
|
142
142
|
```python
|
|
143
143
|
lst = validate([1, 2, 3, 4, 5, 6], {"max_length": 7})
|
|
144
144
|
```
|
|
145
|
-
min
|
|
145
|
+
## min
|
|
146
146
|
|
|
147
147
|
Minimum numeric value (inclusive).
|
|
148
148
|
|
|
149
149
|
```python
|
|
150
150
|
number = validate(10, {"min": 0})
|
|
151
151
|
```
|
|
152
|
-
max
|
|
152
|
+
## max
|
|
153
153
|
|
|
154
154
|
Maximum numeric value (inclusive).
|
|
155
155
|
|
|
156
156
|
```python
|
|
157
157
|
number = validate(10, {"max": 20})
|
|
158
158
|
```
|
|
159
|
-
allowed_values
|
|
159
|
+
## allowed_values
|
|
160
160
|
|
|
161
161
|
Similar to Literal; value must be one of the allowed values.
|
|
162
162
|
|
|
163
163
|
```python
|
|
164
164
|
val = validate("a", {"allowed_values": ("a", "b", "c", "d")})
|
|
165
165
|
```
|
|
166
|
-
invariant
|
|
166
|
+
## invariant
|
|
167
167
|
|
|
168
168
|
Value must be truthy.
|
|
169
169
|
|
|
170
170
|
```python
|
|
171
171
|
val = validate((0 == 0), {"invariant": True})
|
|
172
172
|
```
|
|
173
|
-
all_same
|
|
173
|
+
## all_same
|
|
174
174
|
|
|
175
175
|
All values in the collection must be the same.
|
|
176
176
|
|
|
177
177
|
```python
|
|
178
178
|
numbers = validate([1, 1, 1], {"all_same": True})
|
|
179
179
|
```
|
|
180
|
-
all_unique
|
|
180
|
+
## all_unique
|
|
181
181
|
|
|
182
182
|
All values in the collection must be unique.
|
|
183
183
|
|
|
184
184
|
```python
|
|
185
185
|
numbers = validate([1, 2, 3], {"all_unique": True})
|
|
186
186
|
```
|
|
187
|
-
non_empty
|
|
187
|
+
## non_empty
|
|
188
188
|
|
|
189
189
|
Collection must not be empty.
|
|
190
190
|
|
|
191
191
|
```python
|
|
192
192
|
my_strings = validate(['a', 'b', 'c'], {"non_empty": True})
|
|
193
193
|
```
|
|
194
|
-
no_nulls
|
|
194
|
+
## no_nulls
|
|
195
195
|
|
|
196
196
|
Collection must not contain None.
|
|
197
197
|
|
|
@@ -199,7 +199,7 @@ Collection must not contain None.
|
|
|
199
199
|
my_things = validate([1, 2, 3, "a", "b", "c"], {"no_nulls": True})
|
|
200
200
|
```
|
|
201
201
|
|
|
202
|
-
sorted
|
|
202
|
+
## sorted
|
|
203
203
|
|
|
204
204
|
List must be sorted (increasing or decreasing).
|
|
205
205
|
|
|
@@ -207,7 +207,7 @@ List must be sorted (increasing or decreasing).
|
|
|
207
207
|
numbers = validate([1, 5, 9], {"sorted": True})
|
|
208
208
|
```
|
|
209
209
|
|
|
210
|
-
increasing
|
|
210
|
+
## increasing
|
|
211
211
|
|
|
212
212
|
List must be strictly increasing.
|
|
213
213
|
|
|
@@ -221,42 +221,42 @@ List must be strictly decreasing.
|
|
|
221
221
|
```python
|
|
222
222
|
numbers = validate([9, 5, 1], {"decreasing": True})
|
|
223
223
|
```
|
|
224
|
-
sum_min
|
|
224
|
+
## sum_min
|
|
225
225
|
|
|
226
226
|
Minimum sum of the collection (inclusive).
|
|
227
227
|
|
|
228
228
|
```python
|
|
229
229
|
numbers = validate([10, 20, 30], {"sum_min": 50})
|
|
230
230
|
```
|
|
231
|
-
sum_max
|
|
231
|
+
## sum_max
|
|
232
232
|
|
|
233
233
|
Maximum sum of the collection (inclusive).
|
|
234
234
|
|
|
235
235
|
```python
|
|
236
236
|
numbers = validate([10, 20, 30], {"sum_max": 70})
|
|
237
237
|
```
|
|
238
|
-
element_min
|
|
238
|
+
## element_min
|
|
239
239
|
|
|
240
240
|
Minimum value for any element (inclusive).
|
|
241
241
|
|
|
242
242
|
```python
|
|
243
243
|
numbers = validate([10, 20, 30], {"element_min": 5})
|
|
244
244
|
```
|
|
245
|
-
element_max
|
|
245
|
+
## element_max
|
|
246
246
|
|
|
247
247
|
Maximum value for any element (inclusive).
|
|
248
248
|
|
|
249
249
|
```python
|
|
250
250
|
numbers = validate([10, 20, 30], {"element_max": 40})
|
|
251
251
|
```
|
|
252
|
-
regex
|
|
252
|
+
## regex
|
|
253
253
|
|
|
254
254
|
String must match the regex.
|
|
255
255
|
|
|
256
256
|
```python
|
|
257
257
|
cat_or_dog = validate("cat", {"regex": "cat|dog"})
|
|
258
258
|
```
|
|
259
|
-
regex_flags
|
|
259
|
+
## regex_flags
|
|
260
260
|
|
|
261
261
|
Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
262
262
|
|
|
@@ -264,7 +264,7 @@ Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
|
264
264
|
from re import RegexFlag
|
|
265
265
|
cat_or_dog = validate("cat", {"regex": "cat|dog", {"regex_flags": RegexFlag.I | RegexFlag.M | RegexFlag.X
|
|
266
266
|
```
|
|
267
|
-
before_date
|
|
267
|
+
## before_date
|
|
268
268
|
|
|
269
269
|
Value must be strictly before the given datetime.
|
|
270
270
|
|
|
@@ -272,14 +272,14 @@ Value must be strictly before the given datetime.
|
|
|
272
272
|
validate(datetime(1999, 8, 29), {"before_date": datetime(2000, 1, 1)})
|
|
273
273
|
```
|
|
274
274
|
|
|
275
|
-
after_date
|
|
275
|
+
## after_date
|
|
276
276
|
|
|
277
277
|
Value must be strictly after the given datetime.
|
|
278
278
|
```python
|
|
279
279
|
validate(datetime(2026, 8, 29), {"after_date": datetime(2000, 1, 1)})
|
|
280
280
|
```
|
|
281
281
|
|
|
282
|
-
piece_color
|
|
282
|
+
## piece_color
|
|
283
283
|
|
|
284
284
|
The piece must have this exact color.
|
|
285
285
|
|
|
@@ -287,7 +287,7 @@ The piece must have this exact color.
|
|
|
287
287
|
import chess
|
|
288
288
|
piece = validate(chess.Piece(chess.ROOK, chess.WHITE), {"piece_color": chess.WHITE})
|
|
289
289
|
```
|
|
290
|
-
piece_type
|
|
290
|
+
## piece_type
|
|
291
291
|
|
|
292
292
|
The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
293
293
|
|
|
@@ -295,7 +295,7 @@ The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
|
295
295
|
import chess
|
|
296
296
|
piece = validate(chess.Piece(chess.KNIGHT, chess.WHITE), {"piece_type": chess.KNIGHT})
|
|
297
297
|
```
|
|
298
|
-
chess_symbol
|
|
298
|
+
## chess_symbol
|
|
299
299
|
|
|
300
300
|
The piece’s symbol must match this string ("P", "n", "r", etc.).
|
|
301
301
|
|
|
@@ -304,7 +304,7 @@ import chess
|
|
|
304
304
|
piece = validate(chess.Piece(chess.ROOK, chess.BLACK), {"chess_symbol": "r"})
|
|
305
305
|
```
|
|
306
306
|
|
|
307
|
-
is_password
|
|
307
|
+
## is_password
|
|
308
308
|
|
|
309
309
|
The value must satisfy all password requirements when this is set to True.
|
|
310
310
|
|
|
@@ -320,7 +320,7 @@ Requirements (sorted):
|
|
|
320
320
|
password = validate("Abcdef!1", {"is_password": True})
|
|
321
321
|
```
|
|
322
322
|
|
|
323
|
-
must_be_true
|
|
323
|
+
## must_be_true
|
|
324
324
|
|
|
325
325
|
Custom rule: a function that returns True for allowed values.
|
|
326
326
|
|
|
@@ -7,7 +7,7 @@ MAJOR: 3
|
|
|
7
7
|
|
|
8
8
|
MINOR: 2
|
|
9
9
|
|
|
10
|
-
PATCH:
|
|
10
|
+
PATCH: 5
|
|
11
11
|
|
|
12
12
|
If you need to catch up, you can see the full version history in the [CHANGELOG](https://github.com/Loepker-James/enforce-rules/blob/main/CHANGELOG.md).
|
|
13
13
|
|
|
@@ -64,7 +64,7 @@ This means validated values behave exactly like normal Python values.
|
|
|
64
64
|
Keywords and Usage
|
|
65
65
|
Below are all supported keywords.
|
|
66
66
|
|
|
67
|
-
length
|
|
67
|
+
## length
|
|
68
68
|
|
|
69
69
|
The length of the object must be exactly this.
|
|
70
70
|
|
|
@@ -72,70 +72,70 @@ The length of the object must be exactly this.
|
|
|
72
72
|
lst = validate([1, 2, 3, 4, 5], {"length": 5})
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
min_length
|
|
75
|
+
## min_length
|
|
76
76
|
|
|
77
77
|
Minimum length (inclusive).
|
|
78
78
|
|
|
79
79
|
```python
|
|
80
80
|
lst = validate(['a', 'b', 'c', 'd', 'e'], {"min_length": 3})
|
|
81
81
|
```
|
|
82
|
-
max_length
|
|
82
|
+
## max_length
|
|
83
83
|
|
|
84
84
|
Maximum length (inclusive).
|
|
85
85
|
|
|
86
86
|
```python
|
|
87
87
|
lst = validate([1, 2, 3, 4, 5, 6], {"max_length": 7})
|
|
88
88
|
```
|
|
89
|
-
min
|
|
89
|
+
## min
|
|
90
90
|
|
|
91
91
|
Minimum numeric value (inclusive).
|
|
92
92
|
|
|
93
93
|
```python
|
|
94
94
|
number = validate(10, {"min": 0})
|
|
95
95
|
```
|
|
96
|
-
max
|
|
96
|
+
## max
|
|
97
97
|
|
|
98
98
|
Maximum numeric value (inclusive).
|
|
99
99
|
|
|
100
100
|
```python
|
|
101
101
|
number = validate(10, {"max": 20})
|
|
102
102
|
```
|
|
103
|
-
allowed_values
|
|
103
|
+
## allowed_values
|
|
104
104
|
|
|
105
105
|
Similar to Literal; value must be one of the allowed values.
|
|
106
106
|
|
|
107
107
|
```python
|
|
108
108
|
val = validate("a", {"allowed_values": ("a", "b", "c", "d")})
|
|
109
109
|
```
|
|
110
|
-
invariant
|
|
110
|
+
## invariant
|
|
111
111
|
|
|
112
112
|
Value must be truthy.
|
|
113
113
|
|
|
114
114
|
```python
|
|
115
115
|
val = validate((0 == 0), {"invariant": True})
|
|
116
116
|
```
|
|
117
|
-
all_same
|
|
117
|
+
## all_same
|
|
118
118
|
|
|
119
119
|
All values in the collection must be the same.
|
|
120
120
|
|
|
121
121
|
```python
|
|
122
122
|
numbers = validate([1, 1, 1], {"all_same": True})
|
|
123
123
|
```
|
|
124
|
-
all_unique
|
|
124
|
+
## all_unique
|
|
125
125
|
|
|
126
126
|
All values in the collection must be unique.
|
|
127
127
|
|
|
128
128
|
```python
|
|
129
129
|
numbers = validate([1, 2, 3], {"all_unique": True})
|
|
130
130
|
```
|
|
131
|
-
non_empty
|
|
131
|
+
## non_empty
|
|
132
132
|
|
|
133
133
|
Collection must not be empty.
|
|
134
134
|
|
|
135
135
|
```python
|
|
136
136
|
my_strings = validate(['a', 'b', 'c'], {"non_empty": True})
|
|
137
137
|
```
|
|
138
|
-
no_nulls
|
|
138
|
+
## no_nulls
|
|
139
139
|
|
|
140
140
|
Collection must not contain None.
|
|
141
141
|
|
|
@@ -143,7 +143,7 @@ Collection must not contain None.
|
|
|
143
143
|
my_things = validate([1, 2, 3, "a", "b", "c"], {"no_nulls": True})
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
-
sorted
|
|
146
|
+
## sorted
|
|
147
147
|
|
|
148
148
|
List must be sorted (increasing or decreasing).
|
|
149
149
|
|
|
@@ -151,7 +151,7 @@ List must be sorted (increasing or decreasing).
|
|
|
151
151
|
numbers = validate([1, 5, 9], {"sorted": True})
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
-
increasing
|
|
154
|
+
## increasing
|
|
155
155
|
|
|
156
156
|
List must be strictly increasing.
|
|
157
157
|
|
|
@@ -165,42 +165,42 @@ List must be strictly decreasing.
|
|
|
165
165
|
```python
|
|
166
166
|
numbers = validate([9, 5, 1], {"decreasing": True})
|
|
167
167
|
```
|
|
168
|
-
sum_min
|
|
168
|
+
## sum_min
|
|
169
169
|
|
|
170
170
|
Minimum sum of the collection (inclusive).
|
|
171
171
|
|
|
172
172
|
```python
|
|
173
173
|
numbers = validate([10, 20, 30], {"sum_min": 50})
|
|
174
174
|
```
|
|
175
|
-
sum_max
|
|
175
|
+
## sum_max
|
|
176
176
|
|
|
177
177
|
Maximum sum of the collection (inclusive).
|
|
178
178
|
|
|
179
179
|
```python
|
|
180
180
|
numbers = validate([10, 20, 30], {"sum_max": 70})
|
|
181
181
|
```
|
|
182
|
-
element_min
|
|
182
|
+
## element_min
|
|
183
183
|
|
|
184
184
|
Minimum value for any element (inclusive).
|
|
185
185
|
|
|
186
186
|
```python
|
|
187
187
|
numbers = validate([10, 20, 30], {"element_min": 5})
|
|
188
188
|
```
|
|
189
|
-
element_max
|
|
189
|
+
## element_max
|
|
190
190
|
|
|
191
191
|
Maximum value for any element (inclusive).
|
|
192
192
|
|
|
193
193
|
```python
|
|
194
194
|
numbers = validate([10, 20, 30], {"element_max": 40})
|
|
195
195
|
```
|
|
196
|
-
regex
|
|
196
|
+
## regex
|
|
197
197
|
|
|
198
198
|
String must match the regex.
|
|
199
199
|
|
|
200
200
|
```python
|
|
201
201
|
cat_or_dog = validate("cat", {"regex": "cat|dog"})
|
|
202
202
|
```
|
|
203
|
-
regex_flags
|
|
203
|
+
## regex_flags
|
|
204
204
|
|
|
205
205
|
Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
206
206
|
|
|
@@ -208,7 +208,7 @@ Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
|
208
208
|
from re import RegexFlag
|
|
209
209
|
cat_or_dog = validate("cat", {"regex": "cat|dog", {"regex_flags": RegexFlag.I | RegexFlag.M | RegexFlag.X
|
|
210
210
|
```
|
|
211
|
-
before_date
|
|
211
|
+
## before_date
|
|
212
212
|
|
|
213
213
|
Value must be strictly before the given datetime.
|
|
214
214
|
|
|
@@ -216,14 +216,14 @@ Value must be strictly before the given datetime.
|
|
|
216
216
|
validate(datetime(1999, 8, 29), {"before_date": datetime(2000, 1, 1)})
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
-
after_date
|
|
219
|
+
## after_date
|
|
220
220
|
|
|
221
221
|
Value must be strictly after the given datetime.
|
|
222
222
|
```python
|
|
223
223
|
validate(datetime(2026, 8, 29), {"after_date": datetime(2000, 1, 1)})
|
|
224
224
|
```
|
|
225
225
|
|
|
226
|
-
piece_color
|
|
226
|
+
## piece_color
|
|
227
227
|
|
|
228
228
|
The piece must have this exact color.
|
|
229
229
|
|
|
@@ -231,7 +231,7 @@ The piece must have this exact color.
|
|
|
231
231
|
import chess
|
|
232
232
|
piece = validate(chess.Piece(chess.ROOK, chess.WHITE), {"piece_color": chess.WHITE})
|
|
233
233
|
```
|
|
234
|
-
piece_type
|
|
234
|
+
## piece_type
|
|
235
235
|
|
|
236
236
|
The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
237
237
|
|
|
@@ -239,7 +239,7 @@ The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
|
239
239
|
import chess
|
|
240
240
|
piece = validate(chess.Piece(chess.KNIGHT, chess.WHITE), {"piece_type": chess.KNIGHT})
|
|
241
241
|
```
|
|
242
|
-
chess_symbol
|
|
242
|
+
## chess_symbol
|
|
243
243
|
|
|
244
244
|
The piece’s symbol must match this string ("P", "n", "r", etc.).
|
|
245
245
|
|
|
@@ -248,7 +248,7 @@ import chess
|
|
|
248
248
|
piece = validate(chess.Piece(chess.ROOK, chess.BLACK), {"chess_symbol": "r"})
|
|
249
249
|
```
|
|
250
250
|
|
|
251
|
-
is_password
|
|
251
|
+
## is_password
|
|
252
252
|
|
|
253
253
|
The value must satisfy all password requirements when this is set to True.
|
|
254
254
|
|
|
@@ -264,7 +264,7 @@ Requirements (sorted):
|
|
|
264
264
|
password = validate("Abcdef!1", {"is_password": True})
|
|
265
265
|
```
|
|
266
266
|
|
|
267
|
-
must_be_true
|
|
267
|
+
## must_be_true
|
|
268
268
|
|
|
269
269
|
Custom rule: a function that returns True for allowed values.
|
|
270
270
|
|
|
@@ -336,4 +336,4 @@ Minor bumps always reset PATCH to 0
|
|
|
336
336
|
|
|
337
337
|
Credits:
|
|
338
338
|
* Copilot
|
|
339
|
-
* Dad
|
|
339
|
+
* Dad
|
|
@@ -156,7 +156,7 @@ def _validate_is_password(value: str, rule: bool) -> None:
|
|
|
156
156
|
symbols: Container[str] = {
|
|
157
157
|
"!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
|
|
158
158
|
":", ";", "<", "=", ">", "?", "@",
|
|
159
|
-
"[", "
|
|
159
|
+
"[", r"\", "]", "^", "_", "`",
|
|
160
160
|
"{", "|", "}", "~",
|
|
161
161
|
}
|
|
162
162
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: enforce-rules
|
|
3
|
-
Version: 3.2.
|
|
3
|
+
Version: 3.2.5
|
|
4
4
|
Summary: Runtime rule validation for Python using dictionary-based constraints.
|
|
5
5
|
Author: Jake Loepker, Microsoft Copilot (AI Assistant)
|
|
6
6
|
License: BSD 3-Clause License
|
|
@@ -63,7 +63,7 @@ MAJOR: 3
|
|
|
63
63
|
|
|
64
64
|
MINOR: 2
|
|
65
65
|
|
|
66
|
-
PATCH:
|
|
66
|
+
PATCH: 5
|
|
67
67
|
|
|
68
68
|
If you need to catch up, you can see the full version history in the [CHANGELOG](https://github.com/Loepker-James/enforce-rules/blob/main/CHANGELOG.md).
|
|
69
69
|
|
|
@@ -120,7 +120,7 @@ This means validated values behave exactly like normal Python values.
|
|
|
120
120
|
Keywords and Usage
|
|
121
121
|
Below are all supported keywords.
|
|
122
122
|
|
|
123
|
-
length
|
|
123
|
+
## length
|
|
124
124
|
|
|
125
125
|
The length of the object must be exactly this.
|
|
126
126
|
|
|
@@ -128,70 +128,70 @@ The length of the object must be exactly this.
|
|
|
128
128
|
lst = validate([1, 2, 3, 4, 5], {"length": 5})
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
min_length
|
|
131
|
+
## min_length
|
|
132
132
|
|
|
133
133
|
Minimum length (inclusive).
|
|
134
134
|
|
|
135
135
|
```python
|
|
136
136
|
lst = validate(['a', 'b', 'c', 'd', 'e'], {"min_length": 3})
|
|
137
137
|
```
|
|
138
|
-
max_length
|
|
138
|
+
## max_length
|
|
139
139
|
|
|
140
140
|
Maximum length (inclusive).
|
|
141
141
|
|
|
142
142
|
```python
|
|
143
143
|
lst = validate([1, 2, 3, 4, 5, 6], {"max_length": 7})
|
|
144
144
|
```
|
|
145
|
-
min
|
|
145
|
+
## min
|
|
146
146
|
|
|
147
147
|
Minimum numeric value (inclusive).
|
|
148
148
|
|
|
149
149
|
```python
|
|
150
150
|
number = validate(10, {"min": 0})
|
|
151
151
|
```
|
|
152
|
-
max
|
|
152
|
+
## max
|
|
153
153
|
|
|
154
154
|
Maximum numeric value (inclusive).
|
|
155
155
|
|
|
156
156
|
```python
|
|
157
157
|
number = validate(10, {"max": 20})
|
|
158
158
|
```
|
|
159
|
-
allowed_values
|
|
159
|
+
## allowed_values
|
|
160
160
|
|
|
161
161
|
Similar to Literal; value must be one of the allowed values.
|
|
162
162
|
|
|
163
163
|
```python
|
|
164
164
|
val = validate("a", {"allowed_values": ("a", "b", "c", "d")})
|
|
165
165
|
```
|
|
166
|
-
invariant
|
|
166
|
+
## invariant
|
|
167
167
|
|
|
168
168
|
Value must be truthy.
|
|
169
169
|
|
|
170
170
|
```python
|
|
171
171
|
val = validate((0 == 0), {"invariant": True})
|
|
172
172
|
```
|
|
173
|
-
all_same
|
|
173
|
+
## all_same
|
|
174
174
|
|
|
175
175
|
All values in the collection must be the same.
|
|
176
176
|
|
|
177
177
|
```python
|
|
178
178
|
numbers = validate([1, 1, 1], {"all_same": True})
|
|
179
179
|
```
|
|
180
|
-
all_unique
|
|
180
|
+
## all_unique
|
|
181
181
|
|
|
182
182
|
All values in the collection must be unique.
|
|
183
183
|
|
|
184
184
|
```python
|
|
185
185
|
numbers = validate([1, 2, 3], {"all_unique": True})
|
|
186
186
|
```
|
|
187
|
-
non_empty
|
|
187
|
+
## non_empty
|
|
188
188
|
|
|
189
189
|
Collection must not be empty.
|
|
190
190
|
|
|
191
191
|
```python
|
|
192
192
|
my_strings = validate(['a', 'b', 'c'], {"non_empty": True})
|
|
193
193
|
```
|
|
194
|
-
no_nulls
|
|
194
|
+
## no_nulls
|
|
195
195
|
|
|
196
196
|
Collection must not contain None.
|
|
197
197
|
|
|
@@ -199,7 +199,7 @@ Collection must not contain None.
|
|
|
199
199
|
my_things = validate([1, 2, 3, "a", "b", "c"], {"no_nulls": True})
|
|
200
200
|
```
|
|
201
201
|
|
|
202
|
-
sorted
|
|
202
|
+
## sorted
|
|
203
203
|
|
|
204
204
|
List must be sorted (increasing or decreasing).
|
|
205
205
|
|
|
@@ -207,7 +207,7 @@ List must be sorted (increasing or decreasing).
|
|
|
207
207
|
numbers = validate([1, 5, 9], {"sorted": True})
|
|
208
208
|
```
|
|
209
209
|
|
|
210
|
-
increasing
|
|
210
|
+
## increasing
|
|
211
211
|
|
|
212
212
|
List must be strictly increasing.
|
|
213
213
|
|
|
@@ -221,42 +221,42 @@ List must be strictly decreasing.
|
|
|
221
221
|
```python
|
|
222
222
|
numbers = validate([9, 5, 1], {"decreasing": True})
|
|
223
223
|
```
|
|
224
|
-
sum_min
|
|
224
|
+
## sum_min
|
|
225
225
|
|
|
226
226
|
Minimum sum of the collection (inclusive).
|
|
227
227
|
|
|
228
228
|
```python
|
|
229
229
|
numbers = validate([10, 20, 30], {"sum_min": 50})
|
|
230
230
|
```
|
|
231
|
-
sum_max
|
|
231
|
+
## sum_max
|
|
232
232
|
|
|
233
233
|
Maximum sum of the collection (inclusive).
|
|
234
234
|
|
|
235
235
|
```python
|
|
236
236
|
numbers = validate([10, 20, 30], {"sum_max": 70})
|
|
237
237
|
```
|
|
238
|
-
element_min
|
|
238
|
+
## element_min
|
|
239
239
|
|
|
240
240
|
Minimum value for any element (inclusive).
|
|
241
241
|
|
|
242
242
|
```python
|
|
243
243
|
numbers = validate([10, 20, 30], {"element_min": 5})
|
|
244
244
|
```
|
|
245
|
-
element_max
|
|
245
|
+
## element_max
|
|
246
246
|
|
|
247
247
|
Maximum value for any element (inclusive).
|
|
248
248
|
|
|
249
249
|
```python
|
|
250
250
|
numbers = validate([10, 20, 30], {"element_max": 40})
|
|
251
251
|
```
|
|
252
|
-
regex
|
|
252
|
+
## regex
|
|
253
253
|
|
|
254
254
|
String must match the regex.
|
|
255
255
|
|
|
256
256
|
```python
|
|
257
257
|
cat_or_dog = validate("cat", {"regex": "cat|dog"})
|
|
258
258
|
```
|
|
259
|
-
regex_flags
|
|
259
|
+
## regex_flags
|
|
260
260
|
|
|
261
261
|
Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
262
262
|
|
|
@@ -264,7 +264,7 @@ Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
|
264
264
|
from re import RegexFlag
|
|
265
265
|
cat_or_dog = validate("cat", {"regex": "cat|dog", {"regex_flags": RegexFlag.I | RegexFlag.M | RegexFlag.X
|
|
266
266
|
```
|
|
267
|
-
before_date
|
|
267
|
+
## before_date
|
|
268
268
|
|
|
269
269
|
Value must be strictly before the given datetime.
|
|
270
270
|
|
|
@@ -272,14 +272,14 @@ Value must be strictly before the given datetime.
|
|
|
272
272
|
validate(datetime(1999, 8, 29), {"before_date": datetime(2000, 1, 1)})
|
|
273
273
|
```
|
|
274
274
|
|
|
275
|
-
after_date
|
|
275
|
+
## after_date
|
|
276
276
|
|
|
277
277
|
Value must be strictly after the given datetime.
|
|
278
278
|
```python
|
|
279
279
|
validate(datetime(2026, 8, 29), {"after_date": datetime(2000, 1, 1)})
|
|
280
280
|
```
|
|
281
281
|
|
|
282
|
-
piece_color
|
|
282
|
+
## piece_color
|
|
283
283
|
|
|
284
284
|
The piece must have this exact color.
|
|
285
285
|
|
|
@@ -287,7 +287,7 @@ The piece must have this exact color.
|
|
|
287
287
|
import chess
|
|
288
288
|
piece = validate(chess.Piece(chess.ROOK, chess.WHITE), {"piece_color": chess.WHITE})
|
|
289
289
|
```
|
|
290
|
-
piece_type
|
|
290
|
+
## piece_type
|
|
291
291
|
|
|
292
292
|
The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
293
293
|
|
|
@@ -295,7 +295,7 @@ The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
|
295
295
|
import chess
|
|
296
296
|
piece = validate(chess.Piece(chess.KNIGHT, chess.WHITE), {"piece_type": chess.KNIGHT})
|
|
297
297
|
```
|
|
298
|
-
chess_symbol
|
|
298
|
+
## chess_symbol
|
|
299
299
|
|
|
300
300
|
The piece’s symbol must match this string ("P", "n", "r", etc.).
|
|
301
301
|
|
|
@@ -304,7 +304,7 @@ import chess
|
|
|
304
304
|
piece = validate(chess.Piece(chess.ROOK, chess.BLACK), {"chess_symbol": "r"})
|
|
305
305
|
```
|
|
306
306
|
|
|
307
|
-
is_password
|
|
307
|
+
## is_password
|
|
308
308
|
|
|
309
309
|
The value must satisfy all password requirements when this is set to True.
|
|
310
310
|
|
|
@@ -320,7 +320,7 @@ Requirements (sorted):
|
|
|
320
320
|
password = validate("Abcdef!1", {"is_password": True})
|
|
321
321
|
```
|
|
322
322
|
|
|
323
|
-
must_be_true
|
|
323
|
+
## must_be_true
|
|
324
324
|
|
|
325
325
|
Custom rule: a function that returns True for allowed values.
|
|
326
326
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|