Skip to main content

Container for finding Python objects using database-like indexes.

Project description

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

FilterBox

Container that stores objects in database-like indexes for fast lookup.

Install:

pip install filterbox

Usage:

from filterbox import FilterBox

objects = [{'x': 4, 'y': 1}, {'x': 6, 'y': 2}, {'x': 8, 'y': 5}]

# create a FilterBox containing objects, indexed on x and y
fb = FilterBox(objects, ['x', 'y'])  

# find the ones you want
fb[{
    'x': {'>': 5, '<': 10},     # find objects where x is between 5 and 10
    'y': {'in': [1, 2, 3]}      # and y is 1, 2, or 3
}]
# result: [{'x': 6, 'y': 2}]

Valid operators are ==, !=, <, <=, >, >=, in, not in.

Is FilterBox a database?

No. But like a database, FilterBox builds B-tree indexes and uses them to find results very quickly. It does not any do other database things like SQL, tables, etc. This keeps FilterBox simple, light, and performant.

Is FilterBox fast?

Yes. Here's how FilterBox compares to other object-finders on an example task.

Example benchmark

Benchmark code

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

Class APIs

There are three containers.

  • FilterBox: Can add, remove, and update objects after creation.
  • ConcurrentFilterBox: Same as FilterBox, but thread-safe.
  • FrozenFilterBox: Cannot be changed after creation, it's read-only. But it's super fast, and of course thread-safe.

All three can be pickled using the special functions filterbox.save() / filterbox.load().

Part 2

Readme Part 2 has lots more examples, including handling of nested data and missing attributes.

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

filterbox-1.0.0.tar.gz (20.0 kB view hashes)

Uploaded Source

Built Distribution

filterbox-1.0.0-py3-none-any.whl (26.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