mongo-pipebuilder 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,6 @@ Author: seligoroff
9
9
 
10
10
  from mongo_pipebuilder.builder import PipelineBuilder
11
11
 
12
- __version__ = "0.4.0"
12
+ __version__ = "0.5.0"
13
13
  __all__ = ["PipelineBuilder"]
14
14
 
@@ -10,9 +10,9 @@ import copy
10
10
  import difflib
11
11
  import json
12
12
  from pathlib import Path
13
- from typing import Any, Dict, List, Optional, Union
13
+ from typing import Any, Dict, Iterable, List, Optional, Union
14
14
 
15
- # For compatibility with Python < 3.11 and mypy with python_version 3.8
15
+ # For compatibility with Python < 3.11 (Self is in typing from 3.11)
16
16
  from typing_extensions import Self
17
17
 
18
18
 
@@ -686,6 +686,35 @@ class PipelineBuilder:
686
686
  self._stages.append(stage)
687
687
  return self
688
688
 
689
+ def add_stages(self, stages: Iterable[Dict[str, Any]]) -> Self:
690
+ """
691
+ Add multiple pipeline stages at once (e.g. a subpipeline from another builder).
692
+
693
+ Empty dict stages are skipped, as with add_stage. Each element must be a
694
+ dictionary.
695
+
696
+ Args:
697
+ stages: Iterable of stage dictionaries (e.g. list, or result of .build()).
698
+
699
+ Returns:
700
+ Self for method chaining.
701
+
702
+ Raises:
703
+ TypeError: If stages is None or any element is not a dictionary.
704
+
705
+ Example:
706
+ >>> builder.add_stages([{"$match": {"x": 1}}, {"$limit": 10}])
707
+ >>> builder.add_stages(other_builder.build())
708
+ """
709
+ if stages is None:
710
+ raise TypeError("stages must not be None")
711
+ for stage in stages:
712
+ if not isinstance(stage, dict):
713
+ raise TypeError("All stages must be dictionaries")
714
+ if stage:
715
+ self._stages.append(stage)
716
+ return self
717
+
689
718
  def __len__(self) -> int:
690
719
  """
691
720
  Return the number of stages in the pipeline.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mongo-pipebuilder
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Type-safe, fluent MongoDB aggregation pipeline builder
5
5
  Author-email: seligoroff <seligoroff@gmail.com>
6
6
  License-Expression: MIT
@@ -12,14 +12,13 @@ Keywords: mongodb,aggregation,pipeline,builder,query
12
12
  Classifier: Development Status :: 3 - Alpha
13
13
  Classifier: Intended Audience :: Developers
14
14
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.8
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
18
17
  Classifier: Programming Language :: Python :: 3.11
19
18
  Classifier: Programming Language :: Python :: 3.12
20
19
  Classifier: Topic :: Database
21
20
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
- Requires-Python: >=3.8
21
+ Requires-Python: >=3.9
23
22
  Description-Content-Type: text/markdown
24
23
  License-File: LICENSE
25
24
  Requires-Dist: typing_extensions>=4.0.0; python_version < "3.11"
@@ -28,7 +27,7 @@ Dynamic: license-file
28
27
  # mongo-pipebuilder
29
28
 
30
29
  [![PyPI version](https://badge.fury.io/py/mongo-pipebuilder.svg)](https://badge.fury.io/py/mongo-pipebuilder)
31
- [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
30
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
32
31
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
33
32
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
34
33
  [![Test Coverage](https://img.shields.io/badge/coverage-96%25-green.svg)](https://github.com/seligoroff/mongo-pipebuilder)
@@ -282,6 +281,19 @@ Adds a custom stage for advanced use cases.
282
281
  }})
283
282
  ```
284
283
 
284
+ ##### `add_stages(stages: Iterable[Dict[str, Any]]) -> Self`
285
+
286
+ Adds multiple stages at once (e.g. a subpipeline from another builder). Empty dicts are skipped. Useful to avoid loops when inserting a ready-made list of stages.
287
+
288
+ ```python
289
+ # From a list
290
+ .add_stages([{"$match": {"level": "error"}}, {"$limit": 100}])
291
+
292
+ # From another builder
293
+ sub = PipelineBuilder().match({"source": "api"}).project({"name": 1})
294
+ .add_stages(sub.build())
295
+ ```
296
+
285
297
  ##### `prepend(stage: Dict[str, Any]) -> Self`
286
298
 
287
299
  Adds a stage at the beginning of the pipeline.
@@ -0,0 +1,7 @@
1
+ mongo_pipebuilder/__init__.py,sha256=cn4_tymz00r4iA4ES-qe6lP3k9K6TvuUsagf6_Ajaxc,336
2
+ mongo_pipebuilder/builder.py,sha256=r_umLKj79j7dmBDKoauo5GC2h7ZFRrc1uYd3_aKcwO0,39834
3
+ mongo_pipebuilder-0.5.0.dist-info/licenses/LICENSE,sha256=-ZkZpDLHDQAc-YBIojJ6eDsMwxwx5pRuQz3RHnl9Y8w,1104
4
+ mongo_pipebuilder-0.5.0.dist-info/METADATA,sha256=aUjgx7ENKyXI3eNyv2gt3YmgL2HeRDpUCav-ucJGBFg,20389
5
+ mongo_pipebuilder-0.5.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
6
+ mongo_pipebuilder-0.5.0.dist-info/top_level.txt,sha256=wLn7H_v-qaNIws5FeBbKPZBCmYFYgFEhPaLjoCWcisc,18
7
+ mongo_pipebuilder-0.5.0.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- mongo_pipebuilder/__init__.py,sha256=3iWmQvRAT2QZHXURN9AHoMPn-7FjwH9ig8QyTUCVLh4,336
2
- mongo_pipebuilder/builder.py,sha256=_c-5uuNwWJigKzzIcOXXkPY9oD_UOC0lomhx03yJz9U,38834
3
- mongo_pipebuilder-0.4.0.dist-info/licenses/LICENSE,sha256=-ZkZpDLHDQAc-YBIojJ6eDsMwxwx5pRuQz3RHnl9Y8w,1104
4
- mongo_pipebuilder-0.4.0.dist-info/METADATA,sha256=IAtv0lDGEIiQ-OlFLn1LR6fDFtgC1xj_PSH3Ak31lE4,20002
5
- mongo_pipebuilder-0.4.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
6
- mongo_pipebuilder-0.4.0.dist-info/top_level.txt,sha256=wLn7H_v-qaNIws5FeBbKPZBCmYFYgFEhPaLjoCWcisc,18
7
- mongo_pipebuilder-0.4.0.dist-info/RECORD,,