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.4-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: queryable_list-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ec647fbba85bad2291c213f5b4482591625807d074af5c058dc147ebc875b73c
MD5 26febb5bfb175592853fd94fbbd3ea3b
BLAKE2b-256 83bf0703064107968d1a9a5df3ebbaedc96f9016adb7b427571f9381f8dd4677

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