Skip to main content

Forget classical list filtering and enjoy yourself by generating flexible and fluent list queries with QueryableList.

Project description

python-queryable-list

Forget classical list filtering and enjoy yourself by generating flexible and fluent list queries with QueryableList.

What is the purpose?

List filtering sometimes may be difficult and boring especially when you need to apply consecutive filters. This library is inspired by flexibility of Django ORM and LinQ. I also believe it looks more readable to write all filters in the same context.

Let's assume we have a list named numbers that contains duplicated numbers, and we need to use a filter that is so:

max(list(set(filter(lambda x: x > 20, numbers)))[11:])

Maybe you think I exaggerated but real life problems can even be more confusing.

Let's assume the number is a QueryableList. The above filter can be rewritten readable such that with QueryableList:

numbers.filter(lambda x: x > 20).distinct().skip(11).max()

Also your queries will be reusable because QueryableList works lazy:

persons = [{'first_name': 'John', 'last_name': 'Doe', 'age': 22}, 
           {'first_name': 'John', 'last_name': 'Smith', 'age': 33}, ...]
query = QueryableList(persons).select('last_name', 'age')
query2 = query.select_list('age', flat=True)
query3 = query.select_list('last_name')

print(list(query))
print(list(query2))
print(list(query3))

# Outputs
# [{'last_name': 'Doe', 'age': 22}, {'last_name': 'Smith', 'age': 33}]
# [22, 33]
# [['Doe'], ['Smith']]

All the queries don't work in their building step as you can see . They worked at the time they were called via list(). In this way query could be used to build query2 and query3 queries.

Which Python versions are supported?

Python 2.7 and Python 3.5+ versions are supported. A lot of unit tests are written to consider all the cases on different Python versions.

Installation

pip install queryable-list

Running Tests

Run this command by using your virtual environment.

python -m unittest discover tests

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

queryable_list-1.0.3-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file queryable_list-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: queryable_list-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for queryable_list-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 289239939b46e8cb889eea4506ead1d3f9f0b610c5d1fed935f3b76a19d1a613
MD5 e5473cf2a6ae7ccf4983a3cf7e1064b8
BLAKE2b-256 312f8417449b682c8d68c6cbb111977ea0c878f1745262c38ff33466d7db19a2

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