Registry / database / sqltrie

sqltrie

JSON →
library0.11.2pypypi✓ verified 22d ago

SQLTrie is a Python library that implements a SQL-based prefix tree (trie) data structure, drawing inspiration from `pygtrie` and `python-diskcache`. It enables efficient storage and retrieval of key-value pairs where keys are sequences (e.g., strings) and operations like prefix-based lookups are optimized. The current version, 0.11.2, was released in February 2025. Given its 'Development Status :: 1 - Planning', the release cadence is irregular and the API is evolving.

pip install sqltrie
INSTALL
IMPORT
SIG · SQLTRIE
S
sqltrie
databasepythonv0.11.2
Install
2.1s avg
Import
125ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.11.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.132s · 19MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.1s · import 0.118s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SQLiteTrie
from sqltrie import SQLiteTrie
from sqltrie import Trie
JSONTrie
from sqltrie import JSONTrie
SerializedTrie
from sqltrie import SerializedTrie

This quickstart demonstrates common `SQLTrie` operations, including storing and retrieving values by key, checking key existence, and iterating over items with a given prefix. It highlights the use of a context manager for proper database handling and implicitly showcases data persistence in the SQLite backend.

import os from sqltrie import Trie db_path = 'my_sqltrie.db' # Ensure a clean slate for the example if os.path.exists(db_path): os.remove(db_path) # Initialize a SQLTrie instance, typically taking a filename for SQLite storage. # Using a context manager ensures proper closing and data persistence. with Trie(filename=db_path) as trie: trie["apple"] = 100 trie["apricot"] = 200 trie["banana"] = 300 trie["bandana"] = 400 trie["applepie"] = 50 print(f"Value for 'apple': {trie['apple']}") print(f"'banana' exists: {'banana' in trie}") print(f"'grape' exists: {'grape' in trie}") print("\nItems with prefix 'ap':") for key, value in trie.items(prefix="ap"): print(f" {key}: {value}") print("\nAll items:") for key, value in trie.items(): print(f" {key}: {value}") # Data is persisted after exiting the 'with' block. # To verify, load the trie again from the same file. with Trie(filename=db_path) as loaded_trie: print(f"\nValue for 'apricot' after reload: {loaded_trie['apricot']}") print(f"'applepie' exists after reload: {'applepie' in loaded_trie}") # Clean up the database file os.remove(db_path) print(f"\nCleaned up database file '{db_path}'.")
Debug
Known issues
breakingThe library is currently in 'Development Status :: 1 - Planning' (Alpha) as per its PyPI classifier. This indicates a highly unstable API that is subject to frequent and significant breaking changes without prior notice. It is not recommended for production environments.
fix
Regularly monitor the project's GitHub repository for updates, changes, and potential discussions about API stability. Be prepared to adapt your code with each new release.
affects: All versions prior to 1.0.0
gotchaOfficial documentation, particularly for usage examples and API specifics, is minimal. The 'Usage' section in the PyPI description and GitHub README is marked as 'TODO'. Users will likely need to infer functionality from the source code or common patterns of similar trie implementations.
fix
Examine the library's source code on GitHub for detailed understanding of its classes and methods. Refer to the documentation of inspiration libraries like `pygtrie` for general trie interface expectations.
affects: All versions
gotchaAs `sqltrie` is backed by SQLite, ensuring data persistence requires proper closing of the trie instance. Failing to do so (e.g., due to unhandled exceptions or abrupt program termination outside of a context manager) may result in data loss or corruption. Always use a context manager (`with Trie(...)`) or explicitly call a `close()` method if available.
fix
Wrap `Trie` instantiation and operations within a `with` statement (e.g., `with Trie(filename='my_db.db') as trie:`) to ensure resources are properly managed and data is committed to disk.
affects: All versions
Upgrade
Version history
0.11.2latest on PyPI · released Feb 19, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
10
Meta
2
OpenAI (training)
1
Resources
sqltrie — pip install sqltrie · libregistry