Skip to main content

Fluent-based Lazily-evaluated Integrated Query for Python

Project description

drawing Fliq

Fluent-syntaxed Lazily-evaluated Integrated Query.

build lint coverage

Python Versions PyPI - Version Downloads Ruff

Fliq is a lightweight Python library for high-performance processing of iterables. Inspired by Django's ORM and LINQ, it provides a fluent syntax for lazily-evaluated operations on iterables, and it is tested to have on-par performance with the standard library.

Installation

pip install fliq
  • Fliq does not have any dependencies.
  • Fliq supports Python 3.9 and above.

Fliq is

  • 💡 Intuitive to use. Built for readability and usability.
  • 🪶 Lightweight wrapper for the standard library. No dependencies or bloat.
  • ⚡️ Efficient as the standard library. Abstraction overhead is kept to a minimum.
  • Lazy evaluated, executed only when needed and only as needed.
  • 🔗 Versatile by supporting any iterable type, including infinite iterables and data streams.
  • 🧩 Compatible with APIs consuming iterables. No integration or setup required.

Motivation

What is the output of the following code?

next(map(lambda x: x * 2, filter(lambda x: x % 2 == 0, [1, 2, 3, 4, 5])), -1)

And what about this?

from fliq import q

(q([1, 2, 3, 4, 5])
    .where(lambda x: x % 2 == 0)
    .select(lambda x: x * 2)
    .first_or_default(default=-1))

And this is just a simple example.

Python's standard library provides a rich set of functions for processing iterables. However, it is not always easy to read and use.

This is especially true when chaining multiple operations together. This is where Fliq comes in. Fliq provides a fluent, easy to read syntax for processing iterables, while keeping performance on-par with the standard library.

Efficiency

Memory

Fliq is lazy. It does not materialize the iterable, unless the operation requires it (e.g., reverse). This allows Fliq to make minimal use of memory.

Abstracting the (lazy) evaluation, reduces cognitive load from the user, thus implicitly opting in for a more efficient computation, which in turn improves efficiency compared to eager list processing code.

Performance

Fliq is designed to be a lightweight wrapper for the standard library. It keeps abstraction overhead to a minimum, and it is tested to have on-par performance with the standard library.

There are two mechanisms for checking Fliq's performance: Performance tests and benchmarking.

Performance Tests

These tests are ran on every commit, and they compare Fliq's performance to the standard library. They allow performance difference to be 1% or smaller, and they are ran on every Python version, 3.9 and above.

You can find the performance tests in Performance tests.

Benchmarking

Fliq is being benchmarked against the standard library. The list of benchmarked scenarios expands over time.

Currently, there are 2 scenarios tested with varying dataset sizes (100, 10K, 1M).

  • Scenario 1: zipping two iterables of Person objects, and taking the first 5 (by age asc) that are of different gender.
q(dataset).zip(shuffled).where(lambda ps: ps[0].gender != ps[1].gender).order(by=lambda ps: ps[0].age+ps[1].age).take(5).to_list()
  • Scenario 2: filtering prepending and appending a list of Person objects
q(dataset).where(lambda p: 0 <= p.age < 100).prepend_many(first).append_many(last).select(lambda p: p.name).to_list()

In both scenarios, Fliq is on-par with the standard library:

Benchmarking Benchmarking

You can find the full benchmarking code at Benchmark.

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

fliq-1.5.0.tar.gz (142.2 kB view details)

Uploaded Source

Built Distribution

fliq-1.5.0-py3-none-any.whl (38.1 kB view details)

Uploaded Python 3

File details

Details for the file fliq-1.5.0.tar.gz.

File metadata

  • Download URL: fliq-1.5.0.tar.gz
  • Upload date:
  • Size: 142.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for fliq-1.5.0.tar.gz
Algorithm Hash digest
SHA256 c74c7be17ba4ae868c575455c434297ce1d16fe2bb67ebf66054d1f0ad85fd94
MD5 4ff6c2a0c76a15a09b8e4e34ea14034e
BLAKE2b-256 73086cdf92acb5a12c6d8cec64d4853d3590a6fcc9b54e22d77aa575d07cdcbb

See more details on using hashes here.

File details

Details for the file fliq-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: fliq-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 38.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for fliq-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b652b9a1b32c0d62077c9fec24f295c277c1ba6421f5a9642675f164a73e748b
MD5 f8fffa206a55b70430a5805a0fdd5e61
BLAKE2b-256 c3f969d1254ca685a8854dea8c821aa90a62b549bb3a64ba3ccce55838867c02

See more details on using hashes here.

Supported by

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