A pure Python prefix tree (trie) for fast in-memory prefix search and filtering
Project description
📦 prefix_tree
A lightweight, pure-Python prefix tree (trie) implementation for fast in-memory prefix search, autocomplete, and filtering based on metadata. Useful for building autocomplete engines, suggestion systems, and efficient word lookups.
✨ Features
- In-memory key-value storage using a prefix tree (trie)
- Fast search by prefix
- Sortable results by dictionary key
- Query filtering by field values (exact match)
- Pure Python, no dependencies
- Compatible with Python 3.10+
📅 Installation
pip install prefix-tree==0.0.7
🚀 Usage Example
from prefix_tree import Trie
# Create a new trie
trie = Trie()
# Insert words with associated metadata
trie.insert("hello", {"name": "hello", "amount": 10, "gender": "t", "type": "t"})
trie.insert("help", {"name": "help", "amount": 5, "gender": "f", "type": "f"})
trie.insert("hell", {"name": "hell", "amount": 7, "gender": "t", "type": "f"})
# Search by prefix and sort by amount (descending)
results = trie.get_by_prefix_sort_desc_by("hel", "amount")
print(results)
# Output:
# [{'name': 'hello', 'amount': 10, ...}, {'name': 'hell', 'amount': 7, ...}, {'name': 'help', 'amount': 5, ...}]
# Search by prefix and filter by query
filtered = trie.get_by_prefix_and_query("hel", {"gender": "t"})
print(filtered)
# Output:
# [{'name': 'hello', 'amount': 10, ...}, {'name': 'hell', 'amount': 7, ...}]
🔧 Build & Upload to PyPI
python3 -m build
twine upload dist/*
🧠 Use Cases
- Autocomplete and typeahead suggestions
- Named entity lookup with filters
- Efficient in-memory keyword searches
- Building simple text-based databases
🔗 Related Projects
📚 Keywords
autocomplete, trie, prefix search, in-memory database, suggestions, python trie, word search, autocompletion, fast lookup, filtering
📝 License
MIT License (see LICENSE for details)
✨ Author
Created by ilia iakhin
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prefix_tree-0.0.8.tar.gz.
File metadata
- Download URL: prefix_tree-0.0.8.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8845c3da08eea61d11b5bb7a9210db915ddc45e8e80636c03d62f4a83d715db1
|
|
| MD5 |
84267932a368cd6a7873822b92a4d9a3
|
|
| BLAKE2b-256 |
6baf9e22fb819c7ec50948e775a49d2e2e1dce9b60ea0aa0b6e70e4d6c642aea
|
File details
Details for the file prefix_tree-0.0.8-py3-none-any.whl.
File metadata
- Download URL: prefix_tree-0.0.8-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37e8b1d39c769b8ee4488556550ca0df9051eebbcad5013473e35f2044ae0108
|
|
| MD5 |
8d87e062da1eee7089418659dbfb32f7
|
|
| BLAKE2b-256 |
39f50872d315b1eb0166ab42d09b2616dfd1593f071a037767b670abe7ee6a19
|