flpit 0.4.0.dev6__tar.gz → 0.4.2.dev1__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.dev6 → flpit-0.4.2.dev1}/.gitignore +3 -1
- flpit-0.4.2.dev1/PKG-INFO +274 -0
- flpit-0.4.2.dev1/README.md +243 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/pyproject.toml +13 -4
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/__init__.py +17 -1
- flpit-0.4.2.dev1/src/flpit/channels.py +1224 -0
- flpit-0.4.2.dev1/src/flpit/concurrent.py +856 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/core/async_linq.py +247 -52
- flpit-0.4.2.dev1/src/flpit/core/comparers.py +97 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/core/linq.py +124 -2
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/json/_core.py +3 -2
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/task.py +873 -73
- flpit-0.4.2.dev1/src/flpit/threading.py +883 -0
- flpit-0.4.0.dev6/PKG-INFO +0 -720
- flpit-0.4.0.dev6/README.md +0 -692
- flpit-0.4.0.dev6/src/flpit/threading.py +0 -215
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/LICENSE +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flp/__init__.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/core/__init__.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/core/_grouping.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/core/_index.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/core/_join.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/core/_lookup.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/core/_zip.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/csv.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/flp.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/json/__init__.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/json/_msgspec.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/json/_native.py +0 -0
- {flpit-0.4.0.dev6 → flpit-0.4.2.dev1}/src/flpit/py.typed +0 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: flpit
|
|
3
|
+
Version: 0.4.2.dev1
|
|
4
|
+
Summary: Fluent LINQ for Python — flip your iterables
|
|
5
|
+
Project-URL: Homepage, https://github.com/riemar/flpit
|
|
6
|
+
Project-URL: Documentation, https://riemar.github.io/flpit/
|
|
7
|
+
Project-URL: Changelog, https://riemar.github.io/flpit/changelog/
|
|
8
|
+
Project-URL: Repository, https://github.com/riemar/flpit
|
|
9
|
+
Project-URL: Issues, https://github.com/riemar/flpit/issues
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: async,async-enumerable,channels,concurrency,csv,dotnet,fluent,free-threaded,generators,iterable,json,lazy-evaluation,linq,pipeline,pyrefly,task,type-safe
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
21
|
+
Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.12
|
|
25
|
+
Requires-Dist: msgspec>=0.22.0; platform_python_implementation == 'CPython' and sys_platform != 'emscripten'
|
|
26
|
+
Provides-Extra: msgspec
|
|
27
|
+
Requires-Dist: msgspec>=0.22.0; extra == 'msgspec'
|
|
28
|
+
Provides-Extra: whenever
|
|
29
|
+
Requires-Dist: whenever>=0.11; extra == 'whenever'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# FlpIt
|
|
33
|
+
|
|
34
|
+
**[📖 Documentation](https://riemar.github.io/flpit/)** | **[🌐 GitHub](https://github.com/riemar/flpit)** | **[📦 PyPI](https://pypi.org/project/flpit/)**
|
|
35
|
+
|
|
36
|
+
> **Fluent LINQ for Python — LINQ semantics, Python-native execution**
|
|
37
|
+
|
|
38
|
+
`FlpIt` brings a strongly typed, LINQ-style API to standard Python iterables. It combines the fluent query model and semantics of .NET LINQ with Python's native iterable and generator model.
|
|
39
|
+
|
|
40
|
+
If you know C# LINQ, you already know most of FlpIt. Existing LINQ examples, query patterns and documentation can generally be translated directly, which makes the .NET LINQ ecosystem a valuable reference for developers and AI coding assistants alike.
|
|
41
|
+
|
|
42
|
+
Queries are the doorway. Around them FlpIt carries over other parts of the .NET programming model: async streams
|
|
43
|
+
(`AsyncFlpIt`), typed JSON and CSV serialization, an `asyncio`-free task runtime, channels and concurrent collections. It is
|
|
44
|
+
tested on free-threaded Python (>=3.14t) in CI.
|
|
45
|
+
|
|
46
|
+
> **Semantic goal:** `flp` strives to faithfully reproduce .NET LINQ semantics.
|
|
47
|
+
> Where Python's language or type system requires a different API contract, the contract is adapted accordingly,
|
|
48
|
+
> and [each deviation is documented](https://riemar.github.io/flpit/semantics/differences/).
|
|
49
|
+
> The implementation is actively developed, and further deviations may still exist.
|
|
50
|
+
|
|
51
|
+
## 💡 Quick Start
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
uv add flpit # or: pip install flpit
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from flpit import flp, FlpIt, FlpList
|
|
59
|
+
|
|
60
|
+
# A lazy, streaming pipeline: nothing has run yet.
|
|
61
|
+
query: FlpIt[int] = (
|
|
62
|
+
flp.it(range(1, 11))
|
|
63
|
+
.where(lambda x: x % 2 == 0)
|
|
64
|
+
.select(lambda x: x * 10)
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# Explicit materialization.
|
|
68
|
+
result: FlpList[int] = query.to_list()
|
|
69
|
+
# [20, 40, 60, 80, 100]
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 🤸 Flipping the Pipeline
|
|
73
|
+
|
|
74
|
+
Native Python functional operations read inside-out. A FlpIt pipeline reads in the order things happen:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
# 🔁 Native built-ins
|
|
78
|
+
result = list(map(lambda x: x * 10, filter(lambda x: x % 2 == 0, range(1, 11))))
|
|
79
|
+
|
|
80
|
+
# 🤸 FlpIt pipeline
|
|
81
|
+
result = (
|
|
82
|
+
flp.it(range(1, 11))
|
|
83
|
+
.where(lambda x: x % 2 == 0)
|
|
84
|
+
.select(lambda x: x * 10)
|
|
85
|
+
.to_list()
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## ⚡ What's in the Box
|
|
90
|
+
|
|
91
|
+
* **Lazy queries (`FlpIt`)** and **materialized lists (`FlpList`)**: deferred, streaming execution over any `Iterable[T]`, with `where`, `select`, `select_many`, `order_by`, `group_by`, joins and the rest of `System.Linq.Enumerable`. [Guide](https://riemar.github.io/flpit/guide/getting-started/)
|
|
92
|
+
* **Async queries (`AsyncFlpIt`)**: the `IAsyncEnumerable<T>` counterpart, with async callbacks, cancellation and cleanup. [Docs](https://riemar.github.io/flpit/async/)
|
|
93
|
+
* **Faithful semantics**: when work happens, how much is read, what comes out and how it fails match .NET, also when operators are chained. Derived queries never affect each other. [Semantics](https://riemar.github.io/flpit/semantics/)
|
|
94
|
+
* **Typed JSON and CSV**: dataclasses to and from JSON and CSV, with `msgspec` or a pure-Python backend. [JSON](https://riemar.github.io/flpit/guide/json/), [CSV](https://riemar.github.io/flpit/guide/csv/)
|
|
95
|
+
* **Task runtime**: an `asyncio`-free runtime modelled on the .NET thread pool, built for free-threaded Python, with `Task.when_all`, `when_each`, continuations and cooperative cancellation. Blocking and `async def` functions mix freely. [Docs](https://riemar.github.io/flpit/task/), [sync and async](https://riemar.github.io/flpit/task/sync-and-async/)
|
|
96
|
+
* **Channels, concurrent collections and threading primitives**: `Channel[T]`, `ConcurrentDictionary`, `SemaphoreSlim` and friends. [Docs](https://riemar.github.io/flpit/concurrency/channels/)
|
|
97
|
+
* **Static-first typing**: designed for precise `pyrefly` inference without plugins (mypy and pyright may give varying results).
|
|
98
|
+
|
|
99
|
+
FlpIt models in-memory LINQ (`IEnumerable`). It does not model `IQueryable` or expression trees.
|
|
100
|
+
|
|
101
|
+
## ⚙️ Installation
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
uv add flpit
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
msgspec is installed automatically on CPython. On other interpreters (PyPy, Pyodide) flpit
|
|
108
|
+
installs without it and uses the native JSON backend. Free-threaded CPython 3.13t is not
|
|
109
|
+
supported by msgspec: install there with `--no-deps`, or use 3.14t.
|
|
110
|
+
|
|
111
|
+
## 💬 Feedback
|
|
112
|
+
|
|
113
|
+
FlpIt is in beta. Bug reports and questions are welcome as [GitHub issues](https://github.com/riemar/flpit/issues).
|
|
114
|
+
|
|
115
|
+
## 🧭 Like FlpIt? Give .NET a try.
|
|
116
|
+
|
|
117
|
+
Enjoying FlpIt's .NET-inspired programming model? [Here's where it comes from](https://riemar.github.io/flpit/dotnet/): try C# in your browser, explore LINQ, or keep your Python and call it from .NET.
|
|
118
|
+
|
|
119
|
+
## 📜 License
|
|
120
|
+
|
|
121
|
+
Distributed under the MIT License. See `LICENSE` for more information.
|
|
122
|
+
|
|
123
|
+
## Migrated .NET Unit Tests
|
|
124
|
+
|
|
125
|
+
> Migrated from the official .NET Runtime LINQ Tests.
|
|
126
|
+
> Note: The test cases exercise both core types, `FlpIt` and `FlpList`, with transitions between lazy and eager execution occurring as part of the individual test cases.
|
|
127
|
+
> `async_linq/` is migrated from the .NET 10 `System.Linq.AsyncEnumerable` tests and exercises `AsyncFlpIt` on the flpit task runtime.
|
|
128
|
+
> `channels/` is migrated from the `System.Threading.Channels` tests; `concurrent/` from the `System.Collections.Concurrent` tests, including the shared `IEnumerable` / `ICollection` / `IDictionary` suites of `Common/tests` (ported to `common/`).
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
================================================================================
|
|
132
|
+
| Test Module File | Test Cases |
|
|
133
|
+
--------------------------------------------------------------------------------
|
|
134
|
+
| tests/nettests/ | |
|
|
135
|
+
| ├── async_linq/ | |
|
|
136
|
+
| │ ├── test_aggregate.py | 11 |
|
|
137
|
+
| │ ├── test_all.py | 7 |
|
|
138
|
+
| │ ├── test_any.py | 8 |
|
|
139
|
+
| │ ├── test_append.py | 20 |
|
|
140
|
+
| │ ├── test_average.py | 10 |
|
|
141
|
+
| │ ├── test_cast.py | 6 |
|
|
142
|
+
| │ ├── test_chunk.py | 5 |
|
|
143
|
+
| │ ├── test_concat.py | 24 |
|
|
144
|
+
| │ ├── test_contains.py | 11 |
|
|
145
|
+
| │ ├── test_count.py | 8 |
|
|
146
|
+
| │ ├── test_default_if_empty.py | 7 |
|
|
147
|
+
| │ ├── test_distinct.py | 10 |
|
|
148
|
+
| │ ├── test_distinct_by.py | 11 |
|
|
149
|
+
| │ ├── test_element_at.py | 8 |
|
|
150
|
+
| │ ├── test_empty.py | 2 |
|
|
151
|
+
| │ ├── test_except.py | 12 |
|
|
152
|
+
| │ ├── test_except_by.py | 13 |
|
|
153
|
+
| │ ├── test_first.py | 8 |
|
|
154
|
+
| │ ├── test_first_or_default.py | 8 |
|
|
155
|
+
| │ ├── test_full_join.py | 11 |
|
|
156
|
+
| │ ├── test_group_by.py | 5 |
|
|
157
|
+
| │ ├── test_group_join.py | 9 |
|
|
158
|
+
| │ ├── test_index.py | 8 |
|
|
159
|
+
| │ ├── test_intersect.py | 12 |
|
|
160
|
+
| │ ├── test_join.py | 9 |
|
|
161
|
+
| │ ├── test_last.py | 8 |
|
|
162
|
+
| │ ├── test_last_or_default.py | 8 |
|
|
163
|
+
| │ ├── test_left_join.py | 10 |
|
|
164
|
+
| │ ├── test_max.py | 11 |
|
|
165
|
+
| │ ├── test_max_by.py | 13 |
|
|
166
|
+
| │ ├── test_min.py | 11 |
|
|
167
|
+
| │ ├── test_min_by.py | 13 |
|
|
168
|
+
| │ ├── test_of_type.py | 5 |
|
|
169
|
+
| │ ├── test_order_by.py | 18 |
|
|
170
|
+
| │ ├── test_prepend.py | 19 |
|
|
171
|
+
| │ ├── test_range.py | 3 |
|
|
172
|
+
| │ ├── test_repeat.py | 3 |
|
|
173
|
+
| │ ├── test_reverse.py | 8 |
|
|
174
|
+
| │ ├── test_select.py | 9 |
|
|
175
|
+
| │ ├── test_select_await.py | 10 |
|
|
176
|
+
| │ ├── test_select_many.py | 5 |
|
|
177
|
+
| │ ├── test_single.py | 9 |
|
|
178
|
+
| │ ├── test_single_or_default.py | 9 |
|
|
179
|
+
| │ ├── test_skip.py | 9 |
|
|
180
|
+
| │ ├── test_skip_last.py | 9 |
|
|
181
|
+
| │ ├── test_sum.py | 10 |
|
|
182
|
+
| │ ├── test_take.py | 9 |
|
|
183
|
+
| │ ├── test_take_last.py | 9 |
|
|
184
|
+
| │ ├── test_to_async_enumerable.py | 10 |
|
|
185
|
+
| │ ├── test_to_dictionary.py | 5 |
|
|
186
|
+
| │ ├── test_to_list.py | 9 |
|
|
187
|
+
| │ ├── test_to_lookup.py | 4 |
|
|
188
|
+
| │ ├── test_union.py | 12 |
|
|
189
|
+
| │ ├── test_where.py | 9 |
|
|
190
|
+
| │ ├── test_where_await.py | 6 |
|
|
191
|
+
| │ └── test_zip.py | 12 |
|
|
192
|
+
| ├── channels/ | |
|
|
193
|
+
| │ ├── test_bounded_channel.py | 139 |
|
|
194
|
+
| │ ├── test_channel.py | 16 |
|
|
195
|
+
| │ ├── test_channel_closed_exception.py | 2 |
|
|
196
|
+
| │ ├── test_debug_attribute.py | 0 |
|
|
197
|
+
| │ ├── test_priority_unbounded_channel.py | 85 |
|
|
198
|
+
| │ ├── test_rendezvous_channel.py | 104 |
|
|
199
|
+
| │ └── test_unbounded_channel.py | 338 |
|
|
200
|
+
| ├── concurrent/ | |
|
|
201
|
+
| │ ├── test_concurrent_bag.py | 130 |
|
|
202
|
+
| │ ├── test_concurrent_dictionary.py | 56 |
|
|
203
|
+
| │ ├── test_concurrent_dictionary_generic.py | 1236 |
|
|
204
|
+
| │ ├── test_concurrent_queue.py | 130 |
|
|
205
|
+
| │ ├── test_concurrent_stack.py | 124 |
|
|
206
|
+
| │ └── test_etw.py | 0 |
|
|
207
|
+
| ├── linq/ | |
|
|
208
|
+
| │ ├── test_aggregate.py | 42 |
|
|
209
|
+
| │ ├── test_all.py | 80 |
|
|
210
|
+
| │ ├── test_any.py | 90 |
|
|
211
|
+
| │ ├── test_append_prepend.py | 36 |
|
|
212
|
+
| │ ├── test_average.py | 572 |
|
|
213
|
+
| │ ├── test_cast.py | 45 |
|
|
214
|
+
| │ ├── test_chunk.py | 22 |
|
|
215
|
+
| │ ├── test_concat.py | 64 |
|
|
216
|
+
| │ ├── test_contains.py | 108 |
|
|
217
|
+
| │ ├── test_count.py | 37 |
|
|
218
|
+
| │ ├── test_default_if_empty.py | 37 |
|
|
219
|
+
| │ ├── test_distinct.py | 87 |
|
|
220
|
+
| │ ├── test_element_at.py | 43 |
|
|
221
|
+
| │ ├── test_except.py | 68 |
|
|
222
|
+
| │ ├── test_first.py | 29 |
|
|
223
|
+
| │ ├── test_first_or_default.py | 50 |
|
|
224
|
+
| │ ├── test_full_join.py | 37 |
|
|
225
|
+
| │ ├── test_generic_list.py | 95 |
|
|
226
|
+
| │ ├── test_group_by.py | 23 |
|
|
227
|
+
| │ ├── test_group_join.py | 53 |
|
|
228
|
+
| │ ├── test_index.py | 6 |
|
|
229
|
+
| │ ├── test_intersect.py | 42 |
|
|
230
|
+
| │ ├── test_join.py | 47 |
|
|
231
|
+
| │ ├── test_last.py | 29 |
|
|
232
|
+
| │ ├── test_last_or_default.py | 45 |
|
|
233
|
+
| │ ├── test_left_join.py | 47 |
|
|
234
|
+
| │ ├── test_max.py | 1100 |
|
|
235
|
+
| │ ├── test_min.py | 968 |
|
|
236
|
+
| │ ├── test_of_type.py | 38 |
|
|
237
|
+
| │ ├── test_order_by.py | 100 |
|
|
238
|
+
| │ ├── test_order_descending_by.py | 45 |
|
|
239
|
+
| │ ├── test_reverse.py | 35 |
|
|
240
|
+
| │ ├── test_select.py | 140 |
|
|
241
|
+
| │ ├── test_select_many.py | 85 |
|
|
242
|
+
| │ ├── test_single.py | 34 |
|
|
243
|
+
| │ ├── test_single_or_default.py | 48 |
|
|
244
|
+
| │ ├── test_skip.py | 75 |
|
|
245
|
+
| │ ├── test_skip_last.py | 1221 |
|
|
246
|
+
| │ ├── test_sum.py | 134 |
|
|
247
|
+
| │ ├── test_take.py | 39 |
|
|
248
|
+
| │ ├── test_take_last.py | 1221 |
|
|
249
|
+
| │ ├── test_then_by.py | 40 |
|
|
250
|
+
| │ ├── test_then_descending_by.py | 34 |
|
|
251
|
+
| │ ├── test_to_dictionary.py | 32 |
|
|
252
|
+
| │ ├── test_to_list.py | 40 |
|
|
253
|
+
| │ ├── test_to_lookup.py | 26 |
|
|
254
|
+
| │ ├── test_union.py | 62 |
|
|
255
|
+
| │ ├── test_where.py | 76 |
|
|
256
|
+
| │ └── test_zip.py | 101 |
|
|
257
|
+
| ├── task/ | |
|
|
258
|
+
| │ ├── test_cancellation.py | 69 |
|
|
259
|
+
| │ ├── test_task_completion_source.py | 26 |
|
|
260
|
+
| │ ├── test_task_continue_with.py | 15 |
|
|
261
|
+
| │ ├── test_task_continue_with_func_and_action.py | 16 |
|
|
262
|
+
| │ ├── test_task_continue_with_func_and_action_args.py | 20 |
|
|
263
|
+
| │ ├── test_task_factory.py | 3 |
|
|
264
|
+
| │ ├── test_task_rt.py | 13 |
|
|
265
|
+
| │ ├── test_task_rt_core.py | 27 |
|
|
266
|
+
| │ └── test_task_wait_all_any.py | 62 |
|
|
267
|
+
| └── threading/ | |
|
|
268
|
+
| ├── test_semaphore_slim.py | 39 |
|
|
269
|
+
| ├── test_semaphore_slim_cancellation.py | 4 |
|
|
270
|
+
| └── test_thread_local.py | 15 |
|
|
271
|
+
--------------------------------------------------------------------------------
|
|
272
|
+
| GRAND TOTALS | 10725 |
|
|
273
|
+
================================================================================
|
|
274
|
+
```
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# FlpIt
|
|
2
|
+
|
|
3
|
+
**[📖 Documentation](https://riemar.github.io/flpit/)** | **[🌐 GitHub](https://github.com/riemar/flpit)** | **[📦 PyPI](https://pypi.org/project/flpit/)**
|
|
4
|
+
|
|
5
|
+
> **Fluent LINQ for Python — LINQ semantics, Python-native execution**
|
|
6
|
+
|
|
7
|
+
`FlpIt` brings a strongly typed, LINQ-style API to standard Python iterables. It combines the fluent query model and semantics of .NET LINQ with Python's native iterable and generator model.
|
|
8
|
+
|
|
9
|
+
If you know C# LINQ, you already know most of FlpIt. Existing LINQ examples, query patterns and documentation can generally be translated directly, which makes the .NET LINQ ecosystem a valuable reference for developers and AI coding assistants alike.
|
|
10
|
+
|
|
11
|
+
Queries are the doorway. Around them FlpIt carries over other parts of the .NET programming model: async streams
|
|
12
|
+
(`AsyncFlpIt`), typed JSON and CSV serialization, an `asyncio`-free task runtime, channels and concurrent collections. It is
|
|
13
|
+
tested on free-threaded Python (>=3.14t) in CI.
|
|
14
|
+
|
|
15
|
+
> **Semantic goal:** `flp` strives to faithfully reproduce .NET LINQ semantics.
|
|
16
|
+
> Where Python's language or type system requires a different API contract, the contract is adapted accordingly,
|
|
17
|
+
> and [each deviation is documented](https://riemar.github.io/flpit/semantics/differences/).
|
|
18
|
+
> The implementation is actively developed, and further deviations may still exist.
|
|
19
|
+
|
|
20
|
+
## 💡 Quick Start
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
uv add flpit # or: pip install flpit
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from flpit import flp, FlpIt, FlpList
|
|
28
|
+
|
|
29
|
+
# A lazy, streaming pipeline: nothing has run yet.
|
|
30
|
+
query: FlpIt[int] = (
|
|
31
|
+
flp.it(range(1, 11))
|
|
32
|
+
.where(lambda x: x % 2 == 0)
|
|
33
|
+
.select(lambda x: x * 10)
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# Explicit materialization.
|
|
37
|
+
result: FlpList[int] = query.to_list()
|
|
38
|
+
# [20, 40, 60, 80, 100]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 🤸 Flipping the Pipeline
|
|
42
|
+
|
|
43
|
+
Native Python functional operations read inside-out. A FlpIt pipeline reads in the order things happen:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
# 🔁 Native built-ins
|
|
47
|
+
result = list(map(lambda x: x * 10, filter(lambda x: x % 2 == 0, range(1, 11))))
|
|
48
|
+
|
|
49
|
+
# 🤸 FlpIt pipeline
|
|
50
|
+
result = (
|
|
51
|
+
flp.it(range(1, 11))
|
|
52
|
+
.where(lambda x: x % 2 == 0)
|
|
53
|
+
.select(lambda x: x * 10)
|
|
54
|
+
.to_list()
|
|
55
|
+
)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## ⚡ What's in the Box
|
|
59
|
+
|
|
60
|
+
* **Lazy queries (`FlpIt`)** and **materialized lists (`FlpList`)**: deferred, streaming execution over any `Iterable[T]`, with `where`, `select`, `select_many`, `order_by`, `group_by`, joins and the rest of `System.Linq.Enumerable`. [Guide](https://riemar.github.io/flpit/guide/getting-started/)
|
|
61
|
+
* **Async queries (`AsyncFlpIt`)**: the `IAsyncEnumerable<T>` counterpart, with async callbacks, cancellation and cleanup. [Docs](https://riemar.github.io/flpit/async/)
|
|
62
|
+
* **Faithful semantics**: when work happens, how much is read, what comes out and how it fails match .NET, also when operators are chained. Derived queries never affect each other. [Semantics](https://riemar.github.io/flpit/semantics/)
|
|
63
|
+
* **Typed JSON and CSV**: dataclasses to and from JSON and CSV, with `msgspec` or a pure-Python backend. [JSON](https://riemar.github.io/flpit/guide/json/), [CSV](https://riemar.github.io/flpit/guide/csv/)
|
|
64
|
+
* **Task runtime**: an `asyncio`-free runtime modelled on the .NET thread pool, built for free-threaded Python, with `Task.when_all`, `when_each`, continuations and cooperative cancellation. Blocking and `async def` functions mix freely. [Docs](https://riemar.github.io/flpit/task/), [sync and async](https://riemar.github.io/flpit/task/sync-and-async/)
|
|
65
|
+
* **Channels, concurrent collections and threading primitives**: `Channel[T]`, `ConcurrentDictionary`, `SemaphoreSlim` and friends. [Docs](https://riemar.github.io/flpit/concurrency/channels/)
|
|
66
|
+
* **Static-first typing**: designed for precise `pyrefly` inference without plugins (mypy and pyright may give varying results).
|
|
67
|
+
|
|
68
|
+
FlpIt models in-memory LINQ (`IEnumerable`). It does not model `IQueryable` or expression trees.
|
|
69
|
+
|
|
70
|
+
## ⚙️ Installation
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
uv add flpit
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
msgspec is installed automatically on CPython. On other interpreters (PyPy, Pyodide) flpit
|
|
77
|
+
installs without it and uses the native JSON backend. Free-threaded CPython 3.13t is not
|
|
78
|
+
supported by msgspec: install there with `--no-deps`, or use 3.14t.
|
|
79
|
+
|
|
80
|
+
## 💬 Feedback
|
|
81
|
+
|
|
82
|
+
FlpIt is in beta. Bug reports and questions are welcome as [GitHub issues](https://github.com/riemar/flpit/issues).
|
|
83
|
+
|
|
84
|
+
## 🧭 Like FlpIt? Give .NET a try.
|
|
85
|
+
|
|
86
|
+
Enjoying FlpIt's .NET-inspired programming model? [Here's where it comes from](https://riemar.github.io/flpit/dotnet/): try C# in your browser, explore LINQ, or keep your Python and call it from .NET.
|
|
87
|
+
|
|
88
|
+
## 📜 License
|
|
89
|
+
|
|
90
|
+
Distributed under the MIT License. See `LICENSE` for more information.
|
|
91
|
+
|
|
92
|
+
## Migrated .NET Unit Tests
|
|
93
|
+
|
|
94
|
+
> Migrated from the official .NET Runtime LINQ Tests.
|
|
95
|
+
> Note: The test cases exercise both core types, `FlpIt` and `FlpList`, with transitions between lazy and eager execution occurring as part of the individual test cases.
|
|
96
|
+
> `async_linq/` is migrated from the .NET 10 `System.Linq.AsyncEnumerable` tests and exercises `AsyncFlpIt` on the flpit task runtime.
|
|
97
|
+
> `channels/` is migrated from the `System.Threading.Channels` tests; `concurrent/` from the `System.Collections.Concurrent` tests, including the shared `IEnumerable` / `ICollection` / `IDictionary` suites of `Common/tests` (ported to `common/`).
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
================================================================================
|
|
101
|
+
| Test Module File | Test Cases |
|
|
102
|
+
--------------------------------------------------------------------------------
|
|
103
|
+
| tests/nettests/ | |
|
|
104
|
+
| ├── async_linq/ | |
|
|
105
|
+
| │ ├── test_aggregate.py | 11 |
|
|
106
|
+
| │ ├── test_all.py | 7 |
|
|
107
|
+
| │ ├── test_any.py | 8 |
|
|
108
|
+
| │ ├── test_append.py | 20 |
|
|
109
|
+
| │ ├── test_average.py | 10 |
|
|
110
|
+
| │ ├── test_cast.py | 6 |
|
|
111
|
+
| │ ├── test_chunk.py | 5 |
|
|
112
|
+
| │ ├── test_concat.py | 24 |
|
|
113
|
+
| │ ├── test_contains.py | 11 |
|
|
114
|
+
| │ ├── test_count.py | 8 |
|
|
115
|
+
| │ ├── test_default_if_empty.py | 7 |
|
|
116
|
+
| │ ├── test_distinct.py | 10 |
|
|
117
|
+
| │ ├── test_distinct_by.py | 11 |
|
|
118
|
+
| │ ├── test_element_at.py | 8 |
|
|
119
|
+
| │ ├── test_empty.py | 2 |
|
|
120
|
+
| │ ├── test_except.py | 12 |
|
|
121
|
+
| │ ├── test_except_by.py | 13 |
|
|
122
|
+
| │ ├── test_first.py | 8 |
|
|
123
|
+
| │ ├── test_first_or_default.py | 8 |
|
|
124
|
+
| │ ├── test_full_join.py | 11 |
|
|
125
|
+
| │ ├── test_group_by.py | 5 |
|
|
126
|
+
| │ ├── test_group_join.py | 9 |
|
|
127
|
+
| │ ├── test_index.py | 8 |
|
|
128
|
+
| │ ├── test_intersect.py | 12 |
|
|
129
|
+
| │ ├── test_join.py | 9 |
|
|
130
|
+
| │ ├── test_last.py | 8 |
|
|
131
|
+
| │ ├── test_last_or_default.py | 8 |
|
|
132
|
+
| │ ├── test_left_join.py | 10 |
|
|
133
|
+
| │ ├── test_max.py | 11 |
|
|
134
|
+
| │ ├── test_max_by.py | 13 |
|
|
135
|
+
| │ ├── test_min.py | 11 |
|
|
136
|
+
| │ ├── test_min_by.py | 13 |
|
|
137
|
+
| │ ├── test_of_type.py | 5 |
|
|
138
|
+
| │ ├── test_order_by.py | 18 |
|
|
139
|
+
| │ ├── test_prepend.py | 19 |
|
|
140
|
+
| │ ├── test_range.py | 3 |
|
|
141
|
+
| │ ├── test_repeat.py | 3 |
|
|
142
|
+
| │ ├── test_reverse.py | 8 |
|
|
143
|
+
| │ ├── test_select.py | 9 |
|
|
144
|
+
| │ ├── test_select_await.py | 10 |
|
|
145
|
+
| │ ├── test_select_many.py | 5 |
|
|
146
|
+
| │ ├── test_single.py | 9 |
|
|
147
|
+
| │ ├── test_single_or_default.py | 9 |
|
|
148
|
+
| │ ├── test_skip.py | 9 |
|
|
149
|
+
| │ ├── test_skip_last.py | 9 |
|
|
150
|
+
| │ ├── test_sum.py | 10 |
|
|
151
|
+
| │ ├── test_take.py | 9 |
|
|
152
|
+
| │ ├── test_take_last.py | 9 |
|
|
153
|
+
| │ ├── test_to_async_enumerable.py | 10 |
|
|
154
|
+
| │ ├── test_to_dictionary.py | 5 |
|
|
155
|
+
| │ ├── test_to_list.py | 9 |
|
|
156
|
+
| │ ├── test_to_lookup.py | 4 |
|
|
157
|
+
| │ ├── test_union.py | 12 |
|
|
158
|
+
| │ ├── test_where.py | 9 |
|
|
159
|
+
| │ ├── test_where_await.py | 6 |
|
|
160
|
+
| │ └── test_zip.py | 12 |
|
|
161
|
+
| ├── channels/ | |
|
|
162
|
+
| │ ├── test_bounded_channel.py | 139 |
|
|
163
|
+
| │ ├── test_channel.py | 16 |
|
|
164
|
+
| │ ├── test_channel_closed_exception.py | 2 |
|
|
165
|
+
| │ ├── test_debug_attribute.py | 0 |
|
|
166
|
+
| │ ├── test_priority_unbounded_channel.py | 85 |
|
|
167
|
+
| │ ├── test_rendezvous_channel.py | 104 |
|
|
168
|
+
| │ └── test_unbounded_channel.py | 338 |
|
|
169
|
+
| ├── concurrent/ | |
|
|
170
|
+
| │ ├── test_concurrent_bag.py | 130 |
|
|
171
|
+
| │ ├── test_concurrent_dictionary.py | 56 |
|
|
172
|
+
| │ ├── test_concurrent_dictionary_generic.py | 1236 |
|
|
173
|
+
| │ ├── test_concurrent_queue.py | 130 |
|
|
174
|
+
| │ ├── test_concurrent_stack.py | 124 |
|
|
175
|
+
| │ └── test_etw.py | 0 |
|
|
176
|
+
| ├── linq/ | |
|
|
177
|
+
| │ ├── test_aggregate.py | 42 |
|
|
178
|
+
| │ ├── test_all.py | 80 |
|
|
179
|
+
| │ ├── test_any.py | 90 |
|
|
180
|
+
| │ ├── test_append_prepend.py | 36 |
|
|
181
|
+
| │ ├── test_average.py | 572 |
|
|
182
|
+
| │ ├── test_cast.py | 45 |
|
|
183
|
+
| │ ├── test_chunk.py | 22 |
|
|
184
|
+
| │ ├── test_concat.py | 64 |
|
|
185
|
+
| │ ├── test_contains.py | 108 |
|
|
186
|
+
| │ ├── test_count.py | 37 |
|
|
187
|
+
| │ ├── test_default_if_empty.py | 37 |
|
|
188
|
+
| │ ├── test_distinct.py | 87 |
|
|
189
|
+
| │ ├── test_element_at.py | 43 |
|
|
190
|
+
| │ ├── test_except.py | 68 |
|
|
191
|
+
| │ ├── test_first.py | 29 |
|
|
192
|
+
| │ ├── test_first_or_default.py | 50 |
|
|
193
|
+
| │ ├── test_full_join.py | 37 |
|
|
194
|
+
| │ ├── test_generic_list.py | 95 |
|
|
195
|
+
| │ ├── test_group_by.py | 23 |
|
|
196
|
+
| │ ├── test_group_join.py | 53 |
|
|
197
|
+
| │ ├── test_index.py | 6 |
|
|
198
|
+
| │ ├── test_intersect.py | 42 |
|
|
199
|
+
| │ ├── test_join.py | 47 |
|
|
200
|
+
| │ ├── test_last.py | 29 |
|
|
201
|
+
| │ ├── test_last_or_default.py | 45 |
|
|
202
|
+
| │ ├── test_left_join.py | 47 |
|
|
203
|
+
| │ ├── test_max.py | 1100 |
|
|
204
|
+
| │ ├── test_min.py | 968 |
|
|
205
|
+
| │ ├── test_of_type.py | 38 |
|
|
206
|
+
| │ ├── test_order_by.py | 100 |
|
|
207
|
+
| │ ├── test_order_descending_by.py | 45 |
|
|
208
|
+
| │ ├── test_reverse.py | 35 |
|
|
209
|
+
| │ ├── test_select.py | 140 |
|
|
210
|
+
| │ ├── test_select_many.py | 85 |
|
|
211
|
+
| │ ├── test_single.py | 34 |
|
|
212
|
+
| │ ├── test_single_or_default.py | 48 |
|
|
213
|
+
| │ ├── test_skip.py | 75 |
|
|
214
|
+
| │ ├── test_skip_last.py | 1221 |
|
|
215
|
+
| │ ├── test_sum.py | 134 |
|
|
216
|
+
| │ ├── test_take.py | 39 |
|
|
217
|
+
| │ ├── test_take_last.py | 1221 |
|
|
218
|
+
| │ ├── test_then_by.py | 40 |
|
|
219
|
+
| │ ├── test_then_descending_by.py | 34 |
|
|
220
|
+
| │ ├── test_to_dictionary.py | 32 |
|
|
221
|
+
| │ ├── test_to_list.py | 40 |
|
|
222
|
+
| │ ├── test_to_lookup.py | 26 |
|
|
223
|
+
| │ ├── test_union.py | 62 |
|
|
224
|
+
| │ ├── test_where.py | 76 |
|
|
225
|
+
| │ └── test_zip.py | 101 |
|
|
226
|
+
| ├── task/ | |
|
|
227
|
+
| │ ├── test_cancellation.py | 69 |
|
|
228
|
+
| │ ├── test_task_completion_source.py | 26 |
|
|
229
|
+
| │ ├── test_task_continue_with.py | 15 |
|
|
230
|
+
| │ ├── test_task_continue_with_func_and_action.py | 16 |
|
|
231
|
+
| │ ├── test_task_continue_with_func_and_action_args.py | 20 |
|
|
232
|
+
| │ ├── test_task_factory.py | 3 |
|
|
233
|
+
| │ ├── test_task_rt.py | 13 |
|
|
234
|
+
| │ ├── test_task_rt_core.py | 27 |
|
|
235
|
+
| │ └── test_task_wait_all_any.py | 62 |
|
|
236
|
+
| └── threading/ | |
|
|
237
|
+
| ├── test_semaphore_slim.py | 39 |
|
|
238
|
+
| ├── test_semaphore_slim_cancellation.py | 4 |
|
|
239
|
+
| └── test_thread_local.py | 15 |
|
|
240
|
+
--------------------------------------------------------------------------------
|
|
241
|
+
| GRAND TOTALS | 10725 |
|
|
242
|
+
================================================================================
|
|
243
|
+
```
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "flpit"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.2.dev1"
|
|
4
4
|
description = "Fluent LINQ for Python — flip your iterables"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
7
7
|
license = { text = "MIT" }
|
|
8
|
-
keywords = ["linq", "fluent", "iterable", "pipeline", "lazy-evaluation", "
|
|
8
|
+
keywords = ["linq", "dotnet", "fluent", "iterable", "pipeline", "lazy-evaluation", "generators", "async", "async-enumerable", "task", "concurrency", "channels", "free-threaded", "json", "csv", "type-safe", "pyrefly"]
|
|
9
9
|
classifiers = [
|
|
10
|
-
"Development Status ::
|
|
10
|
+
"Development Status :: 4 - Beta",
|
|
11
11
|
"Intended Audience :: Developers",
|
|
12
12
|
"License :: OSI Approved :: MIT License",
|
|
13
13
|
"Programming Language :: Python :: 3",
|
|
@@ -15,6 +15,7 @@ classifiers = [
|
|
|
15
15
|
"Programming Language :: Python :: 3.13",
|
|
16
16
|
"Programming Language :: Python :: 3.14",
|
|
17
17
|
"Programming Language :: Python :: 3.15",
|
|
18
|
+
"Programming Language :: Python :: Free Threading :: 2 - Beta",
|
|
18
19
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
19
20
|
"Typing :: Typed"
|
|
20
21
|
]
|
|
@@ -32,6 +33,8 @@ whenever = ["whenever>=0.11"]
|
|
|
32
33
|
|
|
33
34
|
[project.urls]
|
|
34
35
|
Homepage = "https://github.com/riemar/flpit"
|
|
36
|
+
Documentation = "https://riemar.github.io/flpit/"
|
|
37
|
+
Changelog = "https://riemar.github.io/flpit/changelog/"
|
|
35
38
|
Repository = "https://github.com/riemar/flpit"
|
|
36
39
|
Issues = "https://github.com/riemar/flpit/issues"
|
|
37
40
|
|
|
@@ -46,6 +49,11 @@ dev = [
|
|
|
46
49
|
"httpx>=0.28.1",
|
|
47
50
|
"whenever>=0.11.0",
|
|
48
51
|
]
|
|
52
|
+
docs = [
|
|
53
|
+
"mkdocs>=1.6,<2",
|
|
54
|
+
"mkdocs-material>=9.6,<10",
|
|
55
|
+
"mkdocstrings[python]>=0.30",
|
|
56
|
+
]
|
|
49
57
|
|
|
50
58
|
|
|
51
59
|
[build-system]
|
|
@@ -73,9 +81,10 @@ pythonpath = [
|
|
|
73
81
|
"tests"
|
|
74
82
|
]
|
|
75
83
|
|
|
76
|
-
addopts = "-m 'not benchmark and not stress'"
|
|
84
|
+
addopts = "-m 'not benchmark and not stress and not task_examples'"
|
|
77
85
|
markers = [
|
|
78
86
|
"benchmark: performance benchmarks",
|
|
79
87
|
"stress: multi-core stress tests, run manually on a many-core machine",
|
|
88
|
+
"task_examples: slow Task runtime examples (run with: pytest -m task_examples)",
|
|
80
89
|
]
|
|
81
90
|
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Fluent LINQ for Python — flip your iterables.
|
|
3
3
|
"""
|
|
4
|
+
|
|
5
|
+
# flpit is an extensible package: sub-packages under ``flpit.*`` may be installed by other
|
|
6
|
+
# distributions (e.g. flpit-stoop -> ``flpit.stoop``), also from editable/dev installs.
|
|
7
|
+
# The ``flpit.*`` namespace is reserved for official flpit packages; third-party extensions
|
|
8
|
+
# should use their own top-level package (e.g. ``flpit_<name>`` or ``<name>_flpit``).
|
|
9
|
+
from pkgutil import extend_path as _extend_path
|
|
10
|
+
|
|
11
|
+
__path__ = _extend_path(__path__, __name__)
|
|
12
|
+
del _extend_path
|
|
13
|
+
|
|
4
14
|
from importlib.metadata import version
|
|
5
15
|
__version__ = version("flpit")
|
|
6
16
|
|
|
@@ -24,6 +34,8 @@ from flpit.core.linq import (
|
|
|
24
34
|
NoMatchError,
|
|
25
35
|
MultipleElementsError,
|
|
26
36
|
MultipleMatchesError,
|
|
37
|
+
NotSupportedError,
|
|
38
|
+
KeyNotFoundError,
|
|
27
39
|
|
|
28
40
|
#====================
|
|
29
41
|
# ArgumentExceptions
|
|
@@ -48,7 +60,7 @@ from flpit.core.linq import (
|
|
|
48
60
|
|
|
49
61
|
from flpit.core._grouping import Grouping
|
|
50
62
|
from flpit.core._lookup import Lookup
|
|
51
|
-
from flpit.core.async_linq import AsyncFlpIt, OrderedAsyncIt
|
|
63
|
+
from flpit.core.async_linq import AsyncEnumerator, AsyncFlpIt, OrderedAsyncIt, async_flpit
|
|
52
64
|
|
|
53
65
|
__all__ = [
|
|
54
66
|
"flp",
|
|
@@ -57,14 +69,18 @@ __all__ = [
|
|
|
57
69
|
"Grouping",
|
|
58
70
|
"Lookup",
|
|
59
71
|
"OrderedIt",
|
|
72
|
+
"AsyncEnumerator",
|
|
60
73
|
"AsyncFlpIt",
|
|
61
74
|
"OrderedAsyncIt",
|
|
75
|
+
"async_flpit",
|
|
62
76
|
|
|
63
77
|
"InvalidOperationError",
|
|
64
78
|
"EmptySequenceError",
|
|
65
79
|
"NoMatchError",
|
|
66
80
|
"MultipleElementsError",
|
|
67
81
|
"MultipleMatchesError",
|
|
82
|
+
"NotSupportedError",
|
|
83
|
+
"KeyNotFoundError",
|
|
68
84
|
|
|
69
85
|
"ArgumentError",
|
|
70
86
|
"ArgumentNullError",
|