コンテンツにスキップ

PNQ

CI pypi Downloads

PNQ is a Python implementation like Language Integrated Query (LINQ).

Danger

PNQはベータ版です。

  • 現在、ドキュメントとAPIが一致していません。
  • ライブラリが十分な品質に到達するまで、頻繁に内部実装やAPIが更新される恐れがあります。
  • 本番環境では利用しないでください。

Features

  • コレクション操作に関する多彩な操作
  • アクセシブルなインタフェース
  • 型ヒントの活用
  • 非同期ストリームに対応

Similar tools

Documentation

Dependencies

  • Python 3.7+

Installation

Install with pip:

shell $ pip install pnq

Getting Started

``` python import pnq

for x in pnq.query([1, 2, 3]).map(lambda x: x * 2): print(x)

=> 2, 4, 6

pnq.query([1, 2, 3]).map(lambda x: x * 2).result()

=> [2, 4, 6]

pnq.query([1, 2, 3]).filter(lambda x: x == 3).one()

=> 2

```

``` python import asyncio import pnq

async def aiter(): yield 1 yield 2 yield 3

async def main(): async for x in pnq.query(aiter()).map(lambda x: x * 2): print(x) # => 2, 4, 6

await pnq.query(aiter()).map(lambda x: x * 2)
# => [2, 4, 6]

await pnq.query(aiter()).filter(lambda x: x == 3)._.one()
# => 3

asyncio.run(main()) ```