Skip to main content

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
__contains
__contains_elements_from_list
__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__contains_elements_from_list": ["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
}

Metadata

Release files for list-search 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for list-search 0.2.0
File Size Uploaded Provenance Actions
list_search-0.2.0.tar.gz 2.0 kB Without provenance Details for list_search-0.2.0.tar.gz

Release files / list_search-0.2.0.tar.gz

Download URL list_search-0.2.0.tar.gz
Size 2.0 kB
Tags Source
SHA-256 checksum
How to use checksums
65cc4d3e3742eb3b8dfeccc91bcfb0f63ba160aed9144835bcdf38732f976069
BLAKE2b-256 checksum
How to use checksums
310e095546f93b3c420811f1c3943071084dfc78522792517aec419fce864974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Security for list-search 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page