Skip to main content

Provides Dex, a Python container for indexing objects of any type.

Project description

Index your Python objects for fast lookup by their attributes.

tests Actions Status Coverage - 100% license - MIT python - 3.7+

Install

pip install ducks

Usage

The main container in ducks is called Dex.

from ducks import Dex

# make some objects
objects = [
    {'x': 3, 'y': 'a'},
    {'x': 6, 'y': 'b'},
    {'x': 9, 'y': 'c'}
]

# Create a Dex containing the objects.
# Index on x and y.
dex = Dex(objects, ['x', 'y'])

# match objects
dex[{
    'x': {'>': 5, '<': 10},  # where 5 < x < 10
    'y': {'in': ['a', 'b']}  # and y is 'a' or 'b'
}]
# result: [{'x': 6, 'y': 'b'}]

This is a Dex of dicts, but the objects can be any type.

Dex supports ==, !=, in, not in, <, <=, >, >=.

The indexes can be dict keys, object attributes, or custom functions.

Is Dex fast?

Yes. Here’s how Dex compares to other object-finders on an example task.

https://raw.githubusercontent.com/manimino/ducks/main/docs/img/perf_bench.png

Benchmark source

The closest thing to a Dex is an in-memory SQLite. While SQLite is a fantastic database, it requires more overhead. As such, Dex is generally faster.

Docs

There’s more to ducks than making a Dex of dicts. Continue in the docs.

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

ducks-0.5.1.tar.gz (15.7 kB view hashes)

Uploaded Source

Built Distribution

ducks-0.5.1-py3-none-any.whl (20.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page