Skip to main content

PyPI - Downloads PyPI License

📦 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


📚 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)

Source distribution for prefix-tree 0.0.8
File Size Uploaded
prefix_tree-0.0.8.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prefix-tree 0.0.8
File Interpreter ABI Platform
prefix_tree-0.0.8-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page