📦 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
Metadata
Release files for prefix-tree 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| prefix_tree-0.0.8.tar.gz | 5.0 kB | Without provenance | Details for prefix_tree-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| prefix_tree-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for prefix_tree-0.0.8-py3-none-any.whl |
Total release size: 9.6 kB
Release files / prefix_tree-0.0.8.tar.gz
| Download URL | prefix_tree-0.0.8.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8845c3da08eea61d11b5bb7a9210db915ddc45e8e80636c03d62f4a83d715db1
|
|
BLAKE2b-256 checksum How to use checksums |
6baf9e22fb819c7ec50948e775a49d2e2e1dce9b60ea0aa0b6e70e4d6c642aea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / prefix_tree-0.0.8-py3-none-any.whl
| Download URL | prefix_tree-0.0.8-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37e8b1d39c769b8ee4488556550ca0df9051eebbcad5013473e35f2044ae0108
|
|
BLAKE2b-256 checksum How to use checksums |
39f50872d315b1eb0166ab42d09b2616dfd1593f071a037767b670abe7ee6a19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Security for prefix-tree 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.