Skip to main content

Search in list of dictionaries with lookups! Like in ORM!

Project description

About

Search in list of dictionaries with lookups! Like in ORM!
Say goodbye to complicated loops and conditions when searching through lists of dictionaries!
With this simple Python tool, you can easily filter and find what you need using ORM-style lookups, making data searches feel smooth and intuitive.

How to install

pip install list_search

How to use

You can search non-complex types like int, string, bool, etc. in list

from list_search import search

lst = [1, 2, 3, 'apple', 'banana', True, False]
result = search(lst, 'apple')

Output

['apple']

Or you can search complex objects - list or dict. If list - finds full match. If dict - finds by fields
The advantage of this approach is that you can put ONLY the fields you need, NOT the whole dict!
Lookups: ["__in","__any","__gt","__gte","__lt","__lte","__isnull"]. Up to date lookups you can find in SUPPORTED_FILTERING_LOOKUPS

from list_search import search

lst = [
    {
        "author": {
            "name": "John",
            "last_name": "Wick",
        },
        "books": [
            "Book 1",
            "Book 2"
        ],
        "birth_year": 1950
    },
    {
        "author": {
            "name": "Jack",
            "last_name": "Thompson",
        },
        "books": [
            "Another Book 1",
            "Another Book 2"
        ],
        "birth_year": 1930
    }
]

# search by the fields you need WITH LOOKUPS! 
# You can put only one field, and the elements will be filtered out.
query = {
    "author.name": "John",
    "books__in": ["Book 2"],
    "birth_year__gte": 1945
}
result = search(lst, query)

Output

{
    "author": {
        "name": "John",
        "last_name": "Wick",
    },
    "books": [
        "Book 1",
        "Book 2"
    ],
    "birth_year": 1950
}

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

list_search-0.1.4.tar.gz (2.0 kB view details)

Uploaded Source

File details

Details for the file list_search-0.1.4.tar.gz.

File metadata

  • Download URL: list_search-0.1.4.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for list_search-0.1.4.tar.gz
Algorithm Hash digest
SHA256 d2e8969f7608ee64e30acd407f59082ed0b4126b47bb2725ac735c20cc73f37a
MD5 fb5b91bf2eb1002d8c52f602bfe9b384
BLAKE2b-256 3fec9b1a7d3a5a70a1b8c11de390d7f9be1f9b3446f5619ec9eeb01676941e5f

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