flpit 0.4.0.dev2__tar.gz → 0.4.0.dev6__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.
- flpit-0.4.0.dev2/README.md → flpit-0.4.0.dev6/PKG-INFO +64 -3
- flpit-0.4.0.dev2/PKG-INFO → flpit-0.4.0.dev6/README.md +36 -27
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/pyproject.toml +11 -2
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/core/linq.py +20 -3
- flpit-0.4.0.dev6/src/flpit/csv.py +644 -0
- flpit-0.4.0.dev6/src/flpit/json/__init__.py +168 -0
- flpit-0.4.0.dev6/src/flpit/json/_core.py +418 -0
- flpit-0.4.0.dev2/src/flpit/json.py → flpit-0.4.0.dev6/src/flpit/json/_msgspec.py +164 -245
- flpit-0.4.0.dev6/src/flpit/json/_native.py +1076 -0
- flpit-0.4.0.dev2/src/flpit/csv.py +0 -188
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/.gitignore +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/LICENSE +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flp/__init__.py +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/__init__.py +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/core/__init__.py +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/core/_grouping.py +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/core/_index.py +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/core/_join.py +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/core/_lookup.py +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/core/_zip.py +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/core/async_linq.py +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/flp.py +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/py.typed +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/task.py +0 -0
- {flpit-0.4.0.dev2 → flpit-0.4.0.dev6}/src/flpit/threading.py +0 -0
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: flpit
|
|
3
|
+
Version: 0.4.0.dev6
|
|
4
|
+
Summary: Fluent LINQ for Python — flip your iterables
|
|
5
|
+
Project-URL: Homepage, https://github.com/riemar/flpit
|
|
6
|
+
Project-URL: Repository, https://github.com/riemar/flpit
|
|
7
|
+
Project-URL: Issues, https://github.com/riemar/flpit/issues
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: fluent,generators,iterable,lazy-evaluation,linq,pipeline,pyrefly,type-safe
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.12
|
|
22
|
+
Requires-Dist: msgspec>=0.22.0; platform_python_implementation == 'CPython' and sys_platform != 'emscripten'
|
|
23
|
+
Provides-Extra: msgspec
|
|
24
|
+
Requires-Dist: msgspec>=0.22.0; extra == 'msgspec'
|
|
25
|
+
Provides-Extra: whenever
|
|
26
|
+
Requires-Dist: whenever>=0.11; extra == 'whenever'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
1
29
|
# FlpIt
|
|
2
30
|
|
|
3
31
|
**[🌐 View on GitHub](https://github.com/riemar/flpit)** | [📦 View on PyPI](https://pypi.org/project/flpit/)
|
|
@@ -133,8 +161,9 @@ print(list(backend_engineers))
|
|
|
133
161
|
|
|
134
162
|
## JSON Serialization
|
|
135
163
|
|
|
136
|
-
FlpIt provides typed JSON serialization and deserialization through `flpit.json.JsonConvert
|
|
137
|
-
|
|
164
|
+
FlpIt provides typed JSON serialization and deserialization through `flpit.json.JsonConvert`.
|
|
165
|
+
It uses [`msgspec`](https://github.com/jcrist/msgspec) when available and falls back to a
|
|
166
|
+
pure-Python backend on the standard library `json` module everywhere else (see *Backends* below).
|
|
138
167
|
|
|
139
168
|
It supports dataclasses, nested models, generic containers, configurable property naming, and explicit field metadata.
|
|
140
169
|
|
|
@@ -175,7 +204,35 @@ people: FlpList[Person] = FlpList.from_json(people_json, Person)
|
|
|
175
204
|
|
|
176
205
|
For large outputs, `JsonConvert.serialize_to()` writes a JSON array to a file-like stream without first materializing the entire serialized document.
|
|
177
206
|
|
|
178
|
-
By default, deserialization returns instances of the requested model type. Setting `native=True` opts into the generated `msgspec.Struct` representation instead, trading the original model type for the native representation and its performance characteristics.
|
|
207
|
+
By default, deserialization returns instances of the requested model type. Setting `native=True` opts into the generated `msgspec.Struct` representation instead, trading the original model type for the native representation and its performance characteristics (msgspec backend only; the native backend ignores it).
|
|
208
|
+
|
|
209
|
+
### Custom types
|
|
210
|
+
|
|
211
|
+
`FlpList[T]` fields work out of the box. Other types are added through the type registry:
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
from flpit.json import register_type, register_collection
|
|
215
|
+
|
|
216
|
+
register_type(Money, decode=Money.parse, encode=Money.format) # stored as one JSON value
|
|
217
|
+
register_collection(Bag, base=set) # Bag[T] stored as a JSON array
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
When [`whenever`](https://github.com/ariebovenberg/whenever) is installed, its date/time types
|
|
221
|
+
(`Instant`, `ZonedDateTime`, `Date`, `Time`, `TimeDelta`, `ItemizedDelta`, ...) are registered
|
|
222
|
+
automatically and use whenever's ISO 8601 parsing and formatting.
|
|
223
|
+
|
|
224
|
+
### Backends
|
|
225
|
+
|
|
226
|
+
| Backend | Used when | Notes |
|
|
227
|
+
|-----------|-----------------------------------------------|---------------------------------------------|
|
|
228
|
+
| `msgspec` | msgspec is installed (default on CPython) | fastest |
|
|
229
|
+
| `native` | msgspec is not available (PyPy, Pyodide, ...) | stdlib `json`, roughly 2x slower, no deps |
|
|
230
|
+
|
|
231
|
+
Both backends implement the same contract and run the same test suite. Choose explicitly with
|
|
232
|
+
`flpit.json.set_backend("native")` or the `FLPIT_JSON_BACKEND` environment variable; `get_backend()`
|
|
233
|
+
reports the active one. Float output may differ in exponent spelling (`1e16` vs `1e+16`); the values are identical.
|
|
234
|
+
|
|
235
|
+
`import flpit` does not load the JSON support at all; it is loaded on first use.
|
|
179
236
|
|
|
180
237
|
## 🔬 LINQ Semantics, Python Runtime
|
|
181
238
|
|
|
@@ -526,6 +583,10 @@ flp.ait(range(10)).count().result() # from sync code: block on the Task
|
|
|
526
583
|
uv add flpit
|
|
527
584
|
```
|
|
528
585
|
|
|
586
|
+
msgspec is installed automatically on CPython. On other interpreters (PyPy, Pyodide) flpit
|
|
587
|
+
installs without it and uses the native JSON backend. Free-threaded CPython 3.13t is not
|
|
588
|
+
supported by msgspec: install there with `--no-deps`, or use 3.14t.
|
|
589
|
+
|
|
529
590
|
## 📜 License
|
|
530
591
|
|
|
531
592
|
Distributed under the MIT License. See `LICENSE` for more information.
|
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.5
|
|
2
|
-
Name: flpit
|
|
3
|
-
Version: 0.4.0.dev2
|
|
4
|
-
Summary: Fluent LINQ for Python — flip your iterables
|
|
5
|
-
Project-URL: Homepage, https://github.com/riemar/flpit
|
|
6
|
-
Project-URL: Repository, https://github.com/riemar/flpit
|
|
7
|
-
Project-URL: Issues, https://github.com/riemar/flpit/issues
|
|
8
|
-
License: MIT
|
|
9
|
-
License-File: LICENSE
|
|
10
|
-
Keywords: fluent,generators,iterable,lazy-evaluation,linq,pipeline,pyrefly,type-safe
|
|
11
|
-
Classifier: Development Status :: 3 - Alpha
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.15
|
|
19
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
-
Classifier: Typing :: Typed
|
|
21
|
-
Requires-Python: >=3.12
|
|
22
|
-
Requires-Dist: msgspec>=0.22.0
|
|
23
|
-
Description-Content-Type: text/markdown
|
|
24
|
-
|
|
25
1
|
# FlpIt
|
|
26
2
|
|
|
27
3
|
**[🌐 View on GitHub](https://github.com/riemar/flpit)** | [📦 View on PyPI](https://pypi.org/project/flpit/)
|
|
@@ -157,8 +133,9 @@ print(list(backend_engineers))
|
|
|
157
133
|
|
|
158
134
|
## JSON Serialization
|
|
159
135
|
|
|
160
|
-
FlpIt provides typed JSON serialization and deserialization through `flpit.json.JsonConvert
|
|
161
|
-
|
|
136
|
+
FlpIt provides typed JSON serialization and deserialization through `flpit.json.JsonConvert`.
|
|
137
|
+
It uses [`msgspec`](https://github.com/jcrist/msgspec) when available and falls back to a
|
|
138
|
+
pure-Python backend on the standard library `json` module everywhere else (see *Backends* below).
|
|
162
139
|
|
|
163
140
|
It supports dataclasses, nested models, generic containers, configurable property naming, and explicit field metadata.
|
|
164
141
|
|
|
@@ -199,7 +176,35 @@ people: FlpList[Person] = FlpList.from_json(people_json, Person)
|
|
|
199
176
|
|
|
200
177
|
For large outputs, `JsonConvert.serialize_to()` writes a JSON array to a file-like stream without first materializing the entire serialized document.
|
|
201
178
|
|
|
202
|
-
By default, deserialization returns instances of the requested model type. Setting `native=True` opts into the generated `msgspec.Struct` representation instead, trading the original model type for the native representation and its performance characteristics.
|
|
179
|
+
By default, deserialization returns instances of the requested model type. Setting `native=True` opts into the generated `msgspec.Struct` representation instead, trading the original model type for the native representation and its performance characteristics (msgspec backend only; the native backend ignores it).
|
|
180
|
+
|
|
181
|
+
### Custom types
|
|
182
|
+
|
|
183
|
+
`FlpList[T]` fields work out of the box. Other types are added through the type registry:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from flpit.json import register_type, register_collection
|
|
187
|
+
|
|
188
|
+
register_type(Money, decode=Money.parse, encode=Money.format) # stored as one JSON value
|
|
189
|
+
register_collection(Bag, base=set) # Bag[T] stored as a JSON array
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
When [`whenever`](https://github.com/ariebovenberg/whenever) is installed, its date/time types
|
|
193
|
+
(`Instant`, `ZonedDateTime`, `Date`, `Time`, `TimeDelta`, `ItemizedDelta`, ...) are registered
|
|
194
|
+
automatically and use whenever's ISO 8601 parsing and formatting.
|
|
195
|
+
|
|
196
|
+
### Backends
|
|
197
|
+
|
|
198
|
+
| Backend | Used when | Notes |
|
|
199
|
+
|-----------|-----------------------------------------------|---------------------------------------------|
|
|
200
|
+
| `msgspec` | msgspec is installed (default on CPython) | fastest |
|
|
201
|
+
| `native` | msgspec is not available (PyPy, Pyodide, ...) | stdlib `json`, roughly 2x slower, no deps |
|
|
202
|
+
|
|
203
|
+
Both backends implement the same contract and run the same test suite. Choose explicitly with
|
|
204
|
+
`flpit.json.set_backend("native")` or the `FLPIT_JSON_BACKEND` environment variable; `get_backend()`
|
|
205
|
+
reports the active one. Float output may differ in exponent spelling (`1e16` vs `1e+16`); the values are identical.
|
|
206
|
+
|
|
207
|
+
`import flpit` does not load the JSON support at all; it is loaded on first use.
|
|
203
208
|
|
|
204
209
|
## 🔬 LINQ Semantics, Python Runtime
|
|
205
210
|
|
|
@@ -550,6 +555,10 @@ flp.ait(range(10)).count().result() # from sync code: block on the Task
|
|
|
550
555
|
uv add flpit
|
|
551
556
|
```
|
|
552
557
|
|
|
558
|
+
msgspec is installed automatically on CPython. On other interpreters (PyPy, Pyodide) flpit
|
|
559
|
+
installs without it and uses the native JSON backend. Free-threaded CPython 3.13t is not
|
|
560
|
+
supported by msgspec: install there with `--no-deps`, or use 3.14t.
|
|
561
|
+
|
|
553
562
|
## 📜 License
|
|
554
563
|
|
|
555
564
|
Distributed under the MIT License. See `LICENSE` for more information.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "flpit"
|
|
3
|
-
version = "0.4.0.
|
|
3
|
+
version = "0.4.0.dev6"
|
|
4
4
|
description = "Fluent LINQ for Python — flip your iterables"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
@@ -19,9 +19,17 @@ classifiers = [
|
|
|
19
19
|
"Typing :: Typed"
|
|
20
20
|
]
|
|
21
21
|
dependencies = [
|
|
22
|
-
|
|
22
|
+
# Fast JSON/CSV backend. Optional at runtime: without it flpit.json uses its
|
|
23
|
+
# pure-Python backend (PyPy, Pyodide and platforms without msgspec wheels).
|
|
24
|
+
"msgspec>=0.22.0; platform_python_implementation == 'CPython' and sys_platform != 'emscripten'",
|
|
23
25
|
]
|
|
24
26
|
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
# Ensure the fast backend explicitly, e.g. `pip install flpit[msgspec]`.
|
|
29
|
+
msgspec = ["msgspec>=0.22.0"]
|
|
30
|
+
# Typed date/time values (whenever) are picked up automatically when installed.
|
|
31
|
+
whenever = ["whenever>=0.11"]
|
|
32
|
+
|
|
25
33
|
[project.urls]
|
|
26
34
|
Homepage = "https://github.com/riemar/flpit"
|
|
27
35
|
Repository = "https://github.com/riemar/flpit"
|
|
@@ -36,6 +44,7 @@ dev = [
|
|
|
36
44
|
"pytest-benchmark>=5.3.0",
|
|
37
45
|
"mypy>=2.4.0",
|
|
38
46
|
"httpx>=0.28.1",
|
|
47
|
+
"whenever>=0.11.0",
|
|
39
48
|
]
|
|
40
49
|
|
|
41
50
|
|
|
@@ -15,6 +15,7 @@ from itertools import islice, chain, compress
|
|
|
15
15
|
from numbers import Real as _Real
|
|
16
16
|
|
|
17
17
|
from typing import (
|
|
18
|
+
TYPE_CHECKING,
|
|
18
19
|
Any,
|
|
19
20
|
Callable,
|
|
20
21
|
Iterable,
|
|
@@ -35,7 +36,9 @@ from typing import (
|
|
|
35
36
|
Sized
|
|
36
37
|
)
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
# imported lazily at runtime: JSON support must not be loaded for plain LINQ use
|
|
41
|
+
from flpit.json import JsonSerializerOptions
|
|
39
42
|
from flpit import ZipTuple
|
|
40
43
|
from flpit.core._join import JoinTuple
|
|
41
44
|
from flpit.core._index import IndexTuple
|
|
@@ -290,8 +293,9 @@ def dotnet_context() -> AbstractContextManager[decimal.Context]:
|
|
|
290
293
|
# 1. Create and configure pure Context object
|
|
291
294
|
ctx = decimal.getcontext().copy()
|
|
292
295
|
ctx.prec = max(ctx.prec, 29)
|
|
296
|
+
ctx.Emax = ctx.prec - 1
|
|
293
297
|
ctx.traps[Overflow] = True
|
|
294
|
-
ctx.traps[Inexact] =
|
|
298
|
+
ctx.traps[Inexact] = False
|
|
295
299
|
|
|
296
300
|
return decimal.localcontext(ctx)
|
|
297
301
|
|
|
@@ -1314,12 +1318,17 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
1314
1318
|
else:
|
|
1315
1319
|
try:
|
|
1316
1320
|
total += item
|
|
1317
|
-
except
|
|
1321
|
+
except Overflow:
|
|
1318
1322
|
raise OverflowError(
|
|
1319
1323
|
"System.OverflowException: Value was either too large or too small for a Decimal."
|
|
1320
1324
|
)
|
|
1321
1325
|
count += 1
|
|
1322
1326
|
|
|
1327
|
+
if isinstance(total, Decimal) and total.adjusted() >= decimal.getcontext().prec:
|
|
1328
|
+
raise OverflowError(
|
|
1329
|
+
"System.OverflowException: Value was either too large or too small for a Decimal."
|
|
1330
|
+
)
|
|
1331
|
+
|
|
1323
1332
|
return total, count
|
|
1324
1333
|
|
|
1325
1334
|
|
|
@@ -1504,14 +1513,17 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
1504
1513
|
|
|
1505
1514
|
@classmethod
|
|
1506
1515
|
def from_json[T](cls, data: str | bytes, item_type: type[T], jso: JsonSerializerOptions|None=None) -> FlpIt[T]:
|
|
1516
|
+
from flpit.json import JsonConvert
|
|
1507
1517
|
return FlpIt[T](JsonConvert.deserialize(data, list[item_type], jso))
|
|
1508
1518
|
|
|
1509
1519
|
def to_json_bytes[T](self, item_type: type[T], jso: JsonSerializerOptions|None=None) -> bytes:
|
|
1520
|
+
from flpit.json import JsonConvert
|
|
1510
1521
|
writer = BytesIO()
|
|
1511
1522
|
JsonConvert.serialize_to(self, item_type, writer, jso)
|
|
1512
1523
|
return writer.getvalue()
|
|
1513
1524
|
|
|
1514
1525
|
def to_json[T](self, item_type: type[T], jso: JsonSerializerOptions|None=None) -> str:
|
|
1526
|
+
from flpit.json import JsonConvert
|
|
1515
1527
|
writer = StringIO()
|
|
1516
1528
|
JsonConvert.serialize_to(self, item_type, writer, jso)
|
|
1517
1529
|
return writer.getvalue()
|
|
@@ -1522,6 +1534,7 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
1522
1534
|
output: BinaryIO,
|
|
1523
1535
|
jso: JsonSerializerOptions | None = None,
|
|
1524
1536
|
) -> None:
|
|
1537
|
+
from flpit.json import JsonConvert
|
|
1525
1538
|
JsonConvert.serialize_to(self, item_type, output, jso)
|
|
1526
1539
|
|
|
1527
1540
|
|
|
@@ -2315,12 +2328,15 @@ class FlpList[TItem](Collection[TItem]):
|
|
|
2315
2328
|
|
|
2316
2329
|
@classmethod
|
|
2317
2330
|
def from_json[T](cls, data: str | bytes, item_type: type[T], jso: JsonSerializerOptions|None=None) -> FlpList[T]:
|
|
2331
|
+
from flpit.json import JsonConvert
|
|
2318
2332
|
return FlpList[T](JsonConvert.deserialize(data, list[item_type], jso))
|
|
2319
2333
|
|
|
2320
2334
|
def to_json_bytes[T](self, item_type: type[T], jso: JsonSerializerOptions|None=None) -> bytes:
|
|
2335
|
+
from flpit.json import JsonConvert
|
|
2321
2336
|
return JsonConvert.serialize_bytes(self.__list.data, list[item_type], jso)
|
|
2322
2337
|
|
|
2323
2338
|
def to_json[T](self, item_type: type[T], jso: JsonSerializerOptions|None=None) -> str:
|
|
2339
|
+
from flpit.json import JsonConvert
|
|
2324
2340
|
return JsonConvert.serialize(self.__list.data, list[item_type], jso)
|
|
2325
2341
|
|
|
2326
2342
|
def write_json[T](
|
|
@@ -2329,6 +2345,7 @@ class FlpList[TItem](Collection[TItem]):
|
|
|
2329
2345
|
output: BinaryIO,
|
|
2330
2346
|
jso: JsonSerializerOptions | None = None,
|
|
2331
2347
|
) -> None:
|
|
2348
|
+
from flpit.json import JsonConvert
|
|
2332
2349
|
JsonConvert.serialize_to(self, item_type, output, jso)
|
|
2333
2350
|
|
|
2334
2351
|
# I hate it, but Python being Python
|