Skip to main content

Python object index for fast, declarative retrieval

Project description

odex

Python object index for fast, declarative retrieval.

Install

pip install odex

Usage

Odex provides a set-like collection called IndexedSet:

from odex import IndexedSet, HashIndex, attr, and_

class X:
    def __init__(self, a, b):
        self.a = a
        self.b = b

objs = [
    X(a=1, b=4),
    X(a=2, b=5),
    X(a=2, b=6),
    X(a=3, b=7),
]
        
iset = IndexedSet(objs, indexes=[HashIndex("a")])

# Filter objects with SQL-like expressions:
assert iset.filter("a = 2 AND b = 5") == {objs[1]}

# Or, using the fluent interface:
assert iset.filter(
    and_(
        attr("a").eq(2),
        attr("b").eq(5)
    )
) == {objs[1]}

Related projects

  • sqlglot - odex uses sqlglot for expression parsing
  • ducks - similar project with different tradeoffs

Benchmarks

See comparisons.ipynb for more.

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

odex-0.0.1.tar.gz (9.7 kB view hashes)

Uploaded Source

Built Distribution

odex-0.0.1-py3-none-any.whl (12.2 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