Registry / data / dawg-python

dawg-python

JSON →
library0.7.2pypypi✓ verified 88d ago

Pure-python reader for DAWGs (Directed Acyclic Word Graphs / Deterministic Acyclic Finite State Automata). It's designed to load and query existing DAWG files, often created by the dawgdic C++ library or the DAWG Python C extension, but can also build small DAWGs from sorted word lists. The current version is 0.7.2, with releases occurring infrequently as needed.

pip install dawg-python
INSTALL
IMPORT
SIG · DAWG-PYTHON
D
dawg-python
datapythonv0.7.2
Install
1.5s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.7.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.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

DAWG
✓ from dawg_python import DAWG
✗ from dawg import DAWG
BytesDAWG
✓ from dawg_python import BytesDAWG
Dictionary
✓ from dawg_python import Dictionary

This quickstart demonstrates how to create a DAWG (for illustration), save it to a file, and then load and query it. It also shows basic usage of `IntDAWG` for words with associated integer payloads. The core use case is loading and querying, with file creation typically handled by other, more performant tools for large datasets.

import os from dawg import DAWG, IntDAWG # 1. Create a sample DAWG file (in a real scenario, this might come from dawgdic) words_to_build = ['apple', 'apricot', 'banana', 'cat', 'dog'] # For large sets, words should be pre-sorted for performance. temp_dawg = DAWG(words_to_build) dawg_file_path = 'sample_data.dawg' temp_dawg.save(dawg_file_path) # 2. Load the DAWG from a file (primary use case) loaded_dawg = DAWG().load(dawg_file_path) # 3. Query the loaded DAWG print(f"Is 'apple' in DAWG? {'apple' in loaded_dawg}") print(f"Words starting with 'a': {list(loaded_dawg.keys('a'))}") print(f"Longest prefix for 'apricot': {loaded_dawg.longest_prefix('apricot')}") # Clean up the temporary file os.remove(dawg_file_path) # Example with IntDAWG for words with integer payloads int_data = [('hello', 10), ('world', 20)] int_dawg_obj = IntDAWG(int_data) print(f"Value for 'world': {int_dawg_obj['world']}")
Debug
Known issues
gotchaThe `dawg-python` library is primarily a *reader* for DAWG files. While it can build DAWGs from Python lists, for very large dictionaries, the C++ `dawgdic` library or the `DAWG-Python C extension` are recommended for efficient DAWG construction.
fix
For large-scale DAWG construction, consider using `dawgdic` or its Python C extension bindings, and then loading the resulting `.dawg` files with `dawg-python`.
affects: All versions
gotchaDAWG objects (both `DAWG` and `IntDAWG`) are immutable once created or loaded from a file. You cannot add, remove, or modify words/payloads in place.
fix
To modify a DAWG, you must build a new DAWG object from the desired set of words and payloads.
affects: All versions
gotchaWhen building a DAWG using `DAWG(iterable_of_words)` or `IntDAWG(iterable_of_tuples)`, the input iterable should be *sorted alphabetically* for optimal performance. If not sorted, the library will sort it internally, which can be slow for large inputs.
fix
Pre-sort your list of words/tuples before passing them to the DAWG constructor: `DAWG(sorted(my_words_list))`.
affects: All versions
gotcha`IntDAWG` is specifically designed for string keys with *integer* payloads. Passing non-integer values as payloads will result in a `TypeError`.
fix
Ensure that all payloads provided to `IntDAWG` are integers.
affects: All versions
Upgrade
Version history
0.7.2latest on PyPI · released Apr 18, 2015
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
dawg-python — pip install dawg-python · libregistry