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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file queryable_list-1.0.5-py3-none-any.whl.
File metadata
- Download URL: queryable_list-1.0.5-py3-none-any.whl
- Upload date:
- Size: 4.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d32e335e84a1b7c403d232d3673b66757512331a43d2bed7a48ea8ca36b02b9
|
|
| MD5 |
af612c54194f08f8676d0f646f3fffa9
|
|
| BLAKE2b-256 |
9945e49f0e3165fb8910a6147b8cb7a4b9721e1c68fa757fecb2107c1cb7c03a
|