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, attr, and_

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

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

# Filter objects with SQL-like expressions:
iset.filter("a = 2 AND b = 5") == {X(a=2, b=5)}

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

IndexedSet maintains indexes on the given attributes. There are three index types:

  • HashIndex - based on dict. Only supports exact value queries (e.g. a = 1).
  • SortedDictIndex - based on Sorted Containers. Supports exact value and range queries (e.g. a > 1), but has slower updates.
  • InvertedIndex - based on dict, but supports collection attributes and queries like 'foo' IN tags

When attribute names are given as indexes, the index type will be inferred from the given objects. Otherwise, explicit indexes can be given.

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.7.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

odex-0.0.7-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file odex-0.0.7.tar.gz.

File metadata

  • Download URL: odex-0.0.7.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for odex-0.0.7.tar.gz
Algorithm Hash digest
SHA256 f36a9d06dc18a44723221a615c05b79797237ce711ec08b49279836e7e74d456
MD5 e0572969f60bfa3796afa4b5b3095f73
BLAKE2b-256 8c0a007ce4514847e59f45c4aa637be7afbed388695dfbf63665e258ee35c7fe

See more details on using hashes here.

File details

Details for the file odex-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: odex-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for odex-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1292d35409f23f0fee5c72f66f0a3d3988a41eaf38f3a46f2c21d08f29b109ca
MD5 53b317d772b8969fb28bd88c22491322
BLAKE2b-256 4b0b372d76cde6f9dd2122a2df67beee1ea1aec5b78fc569021b635830734db3

See more details on using hashes here.

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