Skip to main content

Linq for Python with full type annotions. Fluent interface to query and transform any built in Iterable or one of the queryable collections that are drop in replacements for standard collections.

Project description

Typed Linq Collections

Linq for Python with full type annotions. Query any built in Iterable or use one of the queryable collections that are drop in replacements for standard collections. Name collisions with the standard library are resolved by prefixing the built in with q. qcount etc.

  • Rich Query API: Almost the full Enumerable set of operators form .net gives excellent support for filtering, mapping, grouping, and more in a fluent API
  • Comprehensive type annotions: Gives you full autocomplete and static error analysis if using pyright with vscode or PyCharm. In vscode refactoring within the lambdas work like a charm
  • Lazy Evaluation: Memory efficient query execution with deferred evaluation for every operation other than the to_* methods which create new collections
  • Drop-in compatible collection types: Collection types that seamlessly replace and interoperate with standard Python collections
  • Numeric Specializations: Dedicated types for int, float, Decimal, and Fraction collections
  • Extensible Design: QIterable is an abstract class/mixin that can be subclassed by any Iterable type to add full querying capabilities

Quick Start

from typed_linq_collections.collections.q_list import QList
from typed_linq_collections.q_iterable import query


fruits = ("apple", "apricot", "mango", "melon", "peach", "pineapple")
def test_querying_built_in_collections() -> None:
    fruits_by_first_character = (query(fruits)
                                 .group_by(lambda fruit: fruit[0])
                                 .where(lambda group: group.key in {"a", "p"})
                                 .to_list())

    assert fruits_by_first_character == [['apple', 'apricot'], ['peach', 'pineapple']]

def test_querying_with_queryable_collections() -> None:
    fruits_by_first_character = (QList(fruits)
                                 .group_by(lambda fruit: fruit[0])
                                 .where(lambda group: group.key in {"a", "p"})
                                 .to_list())

    assert fruits_by_first_character == [['apple', 'apricot'], ['peach', 'pineapple']]

def test_numeric_operations() -> None:
    total_lenght_of_fruits = (query(fruits)
                              .select(len)
                              .as_ints() # get's you a QIntIterable with numeric operations support. typed so that it is only available on a QIterable[int]
                              .sum())

    assert total_lenght_of_fruits == 36

Collection Types

Core Collections

Drop in replacements for the built in collections.

  • QList[T] - Queryable list (mutable sequence)
  • QSequence[T] - Queryable immutable sequence
  • QSet[T] - Queryable set (mutable)
  • QFrozenSet[T] - Queryable frozen set (immutable)
  • QDict[K, V] - Queryable dictionary
  • QDefaultDict[K, V] - Queryable default dictionary

Numeric Collections

Specialized collections with additional numeric operations:

  • QIntIterable - For integer collections
  • QFloatIterable - For float collections
  • QDecimalIterable - For Decimal collections
  • QFractionIterable - For Fraction collections

and so on with equivalents for QList, QSet, QDict, QFrozenSet, QDefaultDict.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typed_linq_collections-0.8.0.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typed_linq_collections-0.8.0-py3-none-any.whl (57.1 kB view details)

Uploaded Python 3

File details

Details for the file typed_linq_collections-0.8.0.tar.gz.

File metadata

  • Download URL: typed_linq_collections-0.8.0.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for typed_linq_collections-0.8.0.tar.gz
Algorithm Hash digest
SHA256 a03ae2328ff164b5b6be1eff07a4780939d9650fc6f917984d7d0021aa179c84
MD5 bb1fadea25b1dff5e8872bb8ff17a8bd
BLAKE2b-256 cb9e2f5000547ed83b074025d605b54582030acf6618cd21ba552ac599d1ef91

See more details on using hashes here.

File details

Details for the file typed_linq_collections-0.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for typed_linq_collections-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e13b0179abfe21f584491eeb54f6d3af763b6ecef4ba0a6ed758cc06fb27718d
MD5 5137ab723b99394cff4a466c85266594
BLAKE2b-256 d15f3047fa036750983712d00ef533de04656f521e105ef6148f3882b40078f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page