Skip to main content

A Python implementation of .NET's Language Integrated Query (LINQ), providing a functional, fluent API for querying and manipulating collections.

Project description

jetq - Python LINQ

A Python implementation of .NET's Language Integrated Query (LINQ), providing a functional, fluent API for querying and manipulating collections.

Overview

jetq brings the power and elegance of C# LINQ to Python, allowing you to write expressive, chainable queries over any iterable collection.

Key Features

  • Fluent API: Method chaining for readable, composable queries
  • Deferred Execution: Lazy evaluation for better performance
  • Rich Operators: 50+ query operators covering filtering, projection, aggregation, and more
  • Type-Safe: Full type hints for IDE support and type checking
  • Provider Architecture: Extensible design supporting different data sources

Installation

pip install jetq

Quick Start

from jetq import Queryable

# Basic filtering and projection
numbers = Queryable([1, 2, 3, 4, 5])
result = numbers.where(lambda x: x > 2).select(lambda x: x * 2).to_list()
# Output: [6, 8, 10]

# Grouping and aggregation
data = Queryable([
    {'name': 'Alice', 'age': 30},
    {'name': 'Bob', 'age': 25},
    {'name': 'Charlie', 'age': 30}
])
grouped = data.group_by(lambda x: x['age']).to_list()

# Ordering
sorted_data = numbers.order_by(lambda x: -x).to_list()
# Output: [5, 4, 3, 2, 1]

Provider Examples

CSV Queryable

from jetq import CsvQueryable

results = (
    CsvQueryable("employees.csv", type_converters={"age": int, "salary": float})
    .where(lambda r: r["age"] > 30)
    .where(lambda r: r["salary"] > 80000)
    .take(5)
    .to_list()
)

Full CSV examples are in examples/csv_examples.py.

REST Queryable

from jetq import RestQueryable

posts = RestQueryable("https://jsonplaceholder.typicode.com", "posts")
result = posts.where(lambda p: p["userId"] == 1).take(3).to_list()

REST query translation details are documented in EXPRESSION_TREES.md.

Core Concepts

Queryable vs Enumerable

  • Queryable: Works with any iterable, supports custom query providers
  • Enumerable: In-memory extension methods for simple queries

Deferred Execution

Queries are not executed until you enumerate the results:

query = Queryable([1, 2, 3]).where(lambda x: x > 1)  # Not executed yet
result = query.to_list()  # Executed here

Supported Operators

Filtering

  • where() - Filter elements based on predicate
  • distinct() - Remove duplicates
  • skip() - Skip first N elements
  • take() - Take first N elements

Projection

  • select() - Project each element
  • select_many() - Flatten nested collections

Ordering

  • order_by() - Sort ascending
  • order_by_descending() - Sort descending
  • then_by() - Secondary sort
  • then_by_descending() - Secondary sort descending

Grouping & Joining

  • group_by() - Group elements by key
  • join() - Inner join
  • group_join() - Left join with grouped results

Aggregation

  • count() - Count elements
  • sum() - Sum values
  • average() - Average value
  • min() - Minimum value
  • max() - Maximum value
  • aggregate() - Custom aggregation

Set Operations

  • union() - Combine sequences
  • intersect() - Common elements
  • except_() - Difference

Element Access

  • first() - First element
  • first_or_default() - First or default
  • last() - Last element
  • single() - Single element (throws if != 1)
  • element_at() - Element at index

Quantifiers

  • any() - Check if any element matches
  • all() - Check if all elements match
  • contains() - Check if contains element

Conversion

  • to_list() - Convert to list
  • to_dict() - Convert to dictionary
  • to_set() - Convert to set

Contributing

Contributions are welcome! Areas for improvement:

  • Additional query operators
  • Performance optimizations
  • Custom provider implementations
  • More comprehensive tests

License

MIT License - See LICENSE file for details

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

jetq-0.2.0.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

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

jetq-0.2.0-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file jetq-0.2.0.tar.gz.

File metadata

  • Download URL: jetq-0.2.0.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jetq-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1ab60dcbded04163ece4df82bd1f1e583eed9d4b52a88b1a4b125d1af5954965
MD5 9299c3bcac4204bd9a1fbe8a37f10d90
BLAKE2b-256 3351a8397a119f48136a156a2e9a780b1fabe8f307966eace42b2bd4f882fbaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for jetq-0.2.0.tar.gz:

Publisher: publish.yml on zoranmax/jetq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jetq-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: jetq-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jetq-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72d8489a9f3e88e16aa380bf6879bf552467248a4fd59908b6b401a44bdd061a
MD5 f19536cce7fb05fce135d26ecb12e49f
BLAKE2b-256 067ab9632f4d4321278a76f528ccd852b314ce4ddf3cd2658248363f9714dc2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for jetq-0.2.0-py3-none-any.whl:

Publisher: publish.yml on zoranmax/jetq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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