Container for finding Python objects using database-like indexes.
Project description
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.
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
, andupdate
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for filterbox-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a89f9ddadccf3959f4d1c5f3c4e9e0ac3ac88030e6e3c389ee4d394cc6a8f005 |
|
MD5 | 8842c008f6303af4e77e059f4df76db3 |
|
BLAKE2b-256 | 8b9a4725e88ad5cd8a10d98dc91cae4ba9325ea0f48c23558754530d6da26946 |