flpit 0.3.2__tar.gz → 0.3.4.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: flpit
3
- Version: 0.3.2
3
+ Version: 0.3.4.dev1
4
4
  Summary: Fluent LINQ for Python — flip your iterables
5
5
  Project-URL: Homepage, https://github.com/riemar/flpit
6
6
  Project-URL: Repository, https://github.com/riemar/flpit
@@ -47,6 +47,7 @@ This makes the extensive .NET LINQ ecosystem a valuable reference for developers
47
47
  ## ⚡ Key Features
48
48
 
49
49
  * **⚡ Lazy Evaluation (`FlpIt`):** Deferred, streaming execution wrapping any standard Python `Iterable[T]`.
50
+ * **🌊 Async Queries (`AsyncFlpIt`):** The `IAsyncEnumerable<T>` counterpart: a lazy async pipeline consumed with `async for`, terminal operators return a `Task`, and a `CancellationToken` flows through the pipeline (.NET 10 `System.Linq.AsyncEnumerable`).
50
51
  * **📦 Materialized Container (`FlpList`):** Eager collection implementing Python's `Collection` protocol (with indexing and slicing), retaining familiar collection access while providing .NET `List<T>`-style semantics and fluent LINQ query operations.
51
52
  * **🎯 LINQ Semantics:** Familiar operators like `.any()`, `.first()`, `.single()`, `.order_by()`, and `.then_by()` with predictable, composable behavior.
52
53
  * **🔀 Independent Query Pipelines:** Derived queries are independent and never mutate or retroactively affect separately created queries.
@@ -496,6 +497,53 @@ The runtime starts lazily and manages its own lifecycle. Cancellation of running
496
497
 
497
498
  See the [Task Runtime examples](https://github.com/riemar/flpit/tree/main/examples/task) for usage examples.
498
499
 
500
+ ## 🌊 Async Queries (`AsyncFlpIt`)
501
+ ⚠️ **Experimental, pre-release only.** Added in `0.3.4.dev1`; not in the current stable release.
502
+
503
+ `AsyncFlpIt` is the `IAsyncEnumerable<T>` counterpart to `FlpIt`, modelled on .NET 10's `System.Linq.AsyncEnumerable`. It wraps any async iterable (an async generator, another `AsyncFlpIt`) or sync iterable, runs on the flpit task runtime and is consumed with `async for`.
504
+
505
+ ```python
506
+ from flpit import AsyncFlpIt, flp
507
+ from flpit.task import CancellationToken, CancellationTokenSource, Task
508
+
509
+
510
+ async def fetch_pages(token: CancellationToken):
511
+ for page in range(1, 4):
512
+ await Task.delay(0.1, token=token) # the enumeration's token reaches the producer
513
+ yield page
514
+
515
+
516
+ async def is_valid(page: int, token: CancellationToken) -> bool: # async callback
517
+ return page != 2
518
+
519
+
520
+ async def main():
521
+ query = (
522
+ AsyncFlpIt.create(fetch_pages) # or flp.ait(any async / sync iterable)
523
+ .where(is_valid) # deferred, like every intermediate operator
524
+ .select(lambda page: page * 10) # sync callbacks work too
525
+ )
526
+
527
+ async for item in query: # Python's `await foreach`
528
+ print(item)
529
+
530
+ pages = await query.to_list() # terminal operators return a Task
531
+ first = await query.first(token=CancellationTokenSource().token)
532
+
533
+
534
+ Task.run(main).result()
535
+ flp.ait(range(10)).count().result() # from sync code: block on the Task
536
+ ```
537
+
538
+ - **Deferred & lazy:** intermediate operators never touch the source; each enumeration enumerates it again, and one-shot sources stay one-shot.
539
+ - **Terminal operators return a `Task`** (`to_list`, `first`, `single`, `count`, `any`, `sum`, `min_by`, `to_dictionary`, `to_lookup`, `aggregate`, …): `await` them inside the runtime or call `.result()` from synchronous code. Argument errors are raised eagerly, before the `Task` is created.
540
+ - **Sync or async callbacks:** every predicate, selector and key selector can be a plain function or an `async def` taking the `CancellationToken` as its last argument, mirroring .NET's `Func<T, CancellationToken, ValueTask<TResult>>` overloads.
541
+ - **Cancellation:** `with_cancellation(token)` binds a token for `async for`, terminal operators take `token=`, and `AsyncFlpIt.create(factory)` hands the token to the producer (the counterpart of `[EnumeratorCancellation]`). As in .NET, operators pass the token on rather than polling it.
542
+ - **Disposal:** every enumerator an operator opens is closed (`aclose()`, .NET `DisposeAsync`) when it completes, fails or short-circuits. Python's `async for` itself does not close an enumerator on `break`; drive `get_async_enumerator()` with `aclose()` when you need `await foreach` semantics.
543
+ - **Bridges:** `flp.ait(source)`, `FlpIt.to_async_enumerable()`, `AsyncFlpIt.empty() / range() / repeat()`.
544
+
545
+ `AsyncFlpIt` implements the operators `FlpIt` has; overloads `FlpIt` does not have (index-based selectors, comparers, `Range` / `Index` arguments) are not provided yet.
546
+
499
547
  ## ⚙️ Installation
500
548
 
501
549
  ```bash
@@ -511,12 +559,68 @@ Distributed under the MIT License. See `LICENSE` for more information.
511
559
 
512
560
  > Migrated from the official .NET Runtime LINQ Tests.
513
561
  > 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.
562
+ > `async_linq/` is migrated from the .NET 10 `System.Linq.AsyncEnumerable` tests and exercises `AsyncFlpIt` on the flpit task runtime.
514
563
 
515
564
  ```
516
565
  ================================================================================
517
566
  | Test Module File | Test Cases |
518
567
  --------------------------------------------------------------------------------
519
568
  | tests/nettests/ | |
569
+ | ├── async_linq/ | |
570
+ | │ ├── test_aggregate.py | 11 |
571
+ | │ ├── test_all.py | 7 |
572
+ | │ ├── test_any.py | 8 |
573
+ | │ ├── test_append.py | 20 |
574
+ | │ ├── test_average.py | 10 |
575
+ | │ ├── test_cast.py | 6 |
576
+ | │ ├── test_chunk.py | 5 |
577
+ | │ ├── test_concat.py | 24 |
578
+ | │ ├── test_contains.py | 11 |
579
+ | │ ├── test_count.py | 8 |
580
+ | │ ├── test_default_if_empty.py | 7 |
581
+ | │ ├── test_distinct.py | 10 |
582
+ | │ ├── test_distinct_by.py | 11 |
583
+ | │ ├── test_element_at.py | 8 |
584
+ | │ ├── test_empty.py | 2 |
585
+ | │ ├── test_except.py | 12 |
586
+ | │ ├── test_except_by.py | 13 |
587
+ | │ ├── test_first.py | 8 |
588
+ | │ ├── test_first_or_default.py | 8 |
589
+ | │ ├── test_full_join.py | 11 |
590
+ | │ ├── test_group_by.py | 5 |
591
+ | │ ├── test_group_join.py | 9 |
592
+ | │ ├── test_index.py | 8 |
593
+ | │ ├── test_intersect.py | 12 |
594
+ | │ ├── test_join.py | 9 |
595
+ | │ ├── test_last.py | 8 |
596
+ | │ ├── test_last_or_default.py | 8 |
597
+ | │ ├── test_left_join.py | 10 |
598
+ | │ ├── test_max.py | 11 |
599
+ | │ ├── test_max_by.py | 13 |
600
+ | │ ├── test_min.py | 11 |
601
+ | │ ├── test_min_by.py | 13 |
602
+ | │ ├── test_of_type.py | 5 |
603
+ | │ ├── test_order_by.py | 18 |
604
+ | │ ├── test_prepend.py | 19 |
605
+ | │ ├── test_range.py | 3 |
606
+ | │ ├── test_repeat.py | 3 |
607
+ | │ ├── test_reverse.py | 8 |
608
+ | │ ├── test_select.py | 9 |
609
+ | │ ├── test_select_many.py | 5 |
610
+ | │ ├── test_single.py | 9 |
611
+ | │ ├── test_single_or_default.py | 9 |
612
+ | │ ├── test_skip.py | 9 |
613
+ | │ ├── test_skip_last.py | 9 |
614
+ | │ ├── test_sum.py | 10 |
615
+ | │ ├── test_take.py | 9 |
616
+ | │ ├── test_take_last.py | 9 |
617
+ | │ ├── test_to_async_enumerable.py | 10 |
618
+ | │ ├── test_to_dictionary.py | 5 |
619
+ | │ ├── test_to_list.py | 9 |
620
+ | │ ├── test_to_lookup.py | 4 |
621
+ | │ ├── test_union.py | 12 |
622
+ | │ ├── test_where.py | 9 |
623
+ | │ └── test_zip.py | 12 |
520
624
  | ├── linq/ | |
521
625
  | │ ├── test_aggregate.py | 42 |
522
626
  | │ ├── test_all.py | 80 |
@@ -574,6 +678,6 @@ Distributed under the MIT License. See `LICENSE` for more information.
574
678
  | ├── test_task_rt.py | 12 |
575
679
  | └── test_task_rt_core.py | 22 |
576
680
  --------------------------------------------------------------------------------
577
- | GRAND TOTALS | 7660 |
681
+ | GRAND TOTALS | 8172 |
578
682
  ================================================================================
579
683
  ```
@@ -23,6 +23,7 @@ This makes the extensive .NET LINQ ecosystem a valuable reference for developers
23
23
  ## ⚡ Key Features
24
24
 
25
25
  * **⚡ Lazy Evaluation (`FlpIt`):** Deferred, streaming execution wrapping any standard Python `Iterable[T]`.
26
+ * **🌊 Async Queries (`AsyncFlpIt`):** The `IAsyncEnumerable<T>` counterpart: a lazy async pipeline consumed with `async for`, terminal operators return a `Task`, and a `CancellationToken` flows through the pipeline (.NET 10 `System.Linq.AsyncEnumerable`).
26
27
  * **📦 Materialized Container (`FlpList`):** Eager collection implementing Python's `Collection` protocol (with indexing and slicing), retaining familiar collection access while providing .NET `List<T>`-style semantics and fluent LINQ query operations.
27
28
  * **🎯 LINQ Semantics:** Familiar operators like `.any()`, `.first()`, `.single()`, `.order_by()`, and `.then_by()` with predictable, composable behavior.
28
29
  * **🔀 Independent Query Pipelines:** Derived queries are independent and never mutate or retroactively affect separately created queries.
@@ -472,6 +473,53 @@ The runtime starts lazily and manages its own lifecycle. Cancellation of running
472
473
 
473
474
  See the [Task Runtime examples](https://github.com/riemar/flpit/tree/main/examples/task) for usage examples.
474
475
 
476
+ ## 🌊 Async Queries (`AsyncFlpIt`)
477
+ ⚠️ **Experimental, pre-release only.** Added in `0.3.4.dev1`; not in the current stable release.
478
+
479
+ `AsyncFlpIt` is the `IAsyncEnumerable<T>` counterpart to `FlpIt`, modelled on .NET 10's `System.Linq.AsyncEnumerable`. It wraps any async iterable (an async generator, another `AsyncFlpIt`) or sync iterable, runs on the flpit task runtime and is consumed with `async for`.
480
+
481
+ ```python
482
+ from flpit import AsyncFlpIt, flp
483
+ from flpit.task import CancellationToken, CancellationTokenSource, Task
484
+
485
+
486
+ async def fetch_pages(token: CancellationToken):
487
+ for page in range(1, 4):
488
+ await Task.delay(0.1, token=token) # the enumeration's token reaches the producer
489
+ yield page
490
+
491
+
492
+ async def is_valid(page: int, token: CancellationToken) -> bool: # async callback
493
+ return page != 2
494
+
495
+
496
+ async def main():
497
+ query = (
498
+ AsyncFlpIt.create(fetch_pages) # or flp.ait(any async / sync iterable)
499
+ .where(is_valid) # deferred, like every intermediate operator
500
+ .select(lambda page: page * 10) # sync callbacks work too
501
+ )
502
+
503
+ async for item in query: # Python's `await foreach`
504
+ print(item)
505
+
506
+ pages = await query.to_list() # terminal operators return a Task
507
+ first = await query.first(token=CancellationTokenSource().token)
508
+
509
+
510
+ Task.run(main).result()
511
+ flp.ait(range(10)).count().result() # from sync code: block on the Task
512
+ ```
513
+
514
+ - **Deferred & lazy:** intermediate operators never touch the source; each enumeration enumerates it again, and one-shot sources stay one-shot.
515
+ - **Terminal operators return a `Task`** (`to_list`, `first`, `single`, `count`, `any`, `sum`, `min_by`, `to_dictionary`, `to_lookup`, `aggregate`, …): `await` them inside the runtime or call `.result()` from synchronous code. Argument errors are raised eagerly, before the `Task` is created.
516
+ - **Sync or async callbacks:** every predicate, selector and key selector can be a plain function or an `async def` taking the `CancellationToken` as its last argument, mirroring .NET's `Func<T, CancellationToken, ValueTask<TResult>>` overloads.
517
+ - **Cancellation:** `with_cancellation(token)` binds a token for `async for`, terminal operators take `token=`, and `AsyncFlpIt.create(factory)` hands the token to the producer (the counterpart of `[EnumeratorCancellation]`). As in .NET, operators pass the token on rather than polling it.
518
+ - **Disposal:** every enumerator an operator opens is closed (`aclose()`, .NET `DisposeAsync`) when it completes, fails or short-circuits. Python's `async for` itself does not close an enumerator on `break`; drive `get_async_enumerator()` with `aclose()` when you need `await foreach` semantics.
519
+ - **Bridges:** `flp.ait(source)`, `FlpIt.to_async_enumerable()`, `AsyncFlpIt.empty() / range() / repeat()`.
520
+
521
+ `AsyncFlpIt` implements the operators `FlpIt` has; overloads `FlpIt` does not have (index-based selectors, comparers, `Range` / `Index` arguments) are not provided yet.
522
+
475
523
  ## ⚙️ Installation
476
524
 
477
525
  ```bash
@@ -487,12 +535,68 @@ Distributed under the MIT License. See `LICENSE` for more information.
487
535
 
488
536
  > Migrated from the official .NET Runtime LINQ Tests.
489
537
  > 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.
538
+ > `async_linq/` is migrated from the .NET 10 `System.Linq.AsyncEnumerable` tests and exercises `AsyncFlpIt` on the flpit task runtime.
490
539
 
491
540
  ```
492
541
  ================================================================================
493
542
  | Test Module File | Test Cases |
494
543
  --------------------------------------------------------------------------------
495
544
  | tests/nettests/ | |
545
+ | ├── async_linq/ | |
546
+ | │ ├── test_aggregate.py | 11 |
547
+ | │ ├── test_all.py | 7 |
548
+ | │ ├── test_any.py | 8 |
549
+ | │ ├── test_append.py | 20 |
550
+ | │ ├── test_average.py | 10 |
551
+ | │ ├── test_cast.py | 6 |
552
+ | │ ├── test_chunk.py | 5 |
553
+ | │ ├── test_concat.py | 24 |
554
+ | │ ├── test_contains.py | 11 |
555
+ | │ ├── test_count.py | 8 |
556
+ | │ ├── test_default_if_empty.py | 7 |
557
+ | │ ├── test_distinct.py | 10 |
558
+ | │ ├── test_distinct_by.py | 11 |
559
+ | │ ├── test_element_at.py | 8 |
560
+ | │ ├── test_empty.py | 2 |
561
+ | │ ├── test_except.py | 12 |
562
+ | │ ├── test_except_by.py | 13 |
563
+ | │ ├── test_first.py | 8 |
564
+ | │ ├── test_first_or_default.py | 8 |
565
+ | │ ├── test_full_join.py | 11 |
566
+ | │ ├── test_group_by.py | 5 |
567
+ | │ ├── test_group_join.py | 9 |
568
+ | │ ├── test_index.py | 8 |
569
+ | │ ├── test_intersect.py | 12 |
570
+ | │ ├── test_join.py | 9 |
571
+ | │ ├── test_last.py | 8 |
572
+ | │ ├── test_last_or_default.py | 8 |
573
+ | │ ├── test_left_join.py | 10 |
574
+ | │ ├── test_max.py | 11 |
575
+ | │ ├── test_max_by.py | 13 |
576
+ | │ ├── test_min.py | 11 |
577
+ | │ ├── test_min_by.py | 13 |
578
+ | │ ├── test_of_type.py | 5 |
579
+ | │ ├── test_order_by.py | 18 |
580
+ | │ ├── test_prepend.py | 19 |
581
+ | │ ├── test_range.py | 3 |
582
+ | │ ├── test_repeat.py | 3 |
583
+ | │ ├── test_reverse.py | 8 |
584
+ | │ ├── test_select.py | 9 |
585
+ | │ ├── test_select_many.py | 5 |
586
+ | │ ├── test_single.py | 9 |
587
+ | │ ├── test_single_or_default.py | 9 |
588
+ | │ ├── test_skip.py | 9 |
589
+ | │ ├── test_skip_last.py | 9 |
590
+ | │ ├── test_sum.py | 10 |
591
+ | │ ├── test_take.py | 9 |
592
+ | │ ├── test_take_last.py | 9 |
593
+ | │ ├── test_to_async_enumerable.py | 10 |
594
+ | │ ├── test_to_dictionary.py | 5 |
595
+ | │ ├── test_to_list.py | 9 |
596
+ | │ ├── test_to_lookup.py | 4 |
597
+ | │ ├── test_union.py | 12 |
598
+ | │ ├── test_where.py | 9 |
599
+ | │ └── test_zip.py | 12 |
496
600
  | ├── linq/ | |
497
601
  | │ ├── test_aggregate.py | 42 |
498
602
  | │ ├── test_all.py | 80 |
@@ -550,6 +654,6 @@ Distributed under the MIT License. See `LICENSE` for more information.
550
654
  | ├── test_task_rt.py | 12 |
551
655
  | └── test_task_rt_core.py | 22 |
552
656
  --------------------------------------------------------------------------------
553
- | GRAND TOTALS | 7660 |
657
+ | GRAND TOTALS | 8172 |
554
658
  ================================================================================
555
659
  ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "flpit"
3
- version = "0.3.2"
3
+ version = "0.3.4.dev1"
4
4
  description = "Fluent LINQ for Python — flip your iterables"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -48,6 +48,7 @@ from flpit.core.linq import (
48
48
 
49
49
  from flpit.core._grouping import Grouping
50
50
  from flpit.core._lookup import Lookup
51
+ from flpit.core.async_linq import AsyncFlpIt, OrderedAsyncIt
51
52
 
52
53
  __all__ = [
53
54
  "flp",
@@ -56,6 +57,8 @@ __all__ = [
56
57
  "Grouping",
57
58
  "Lookup",
58
59
  "OrderedIt",
60
+ "AsyncFlpIt",
61
+ "OrderedAsyncIt",
59
62
 
60
63
  "InvalidOperationError",
61
64
  "EmptySequenceError",