Registry / serialization / dawg2-python

dawg2-python

JSON →
library0.9.0pypypi✓ verified 90d ago

DAWG2-Python is a pure-Python library providing read-only access to Directed Acyclic Word Graphs (DAWGs) or Deterministic Acyclic Finite State Automata (DAFSAs). It specifically works with `.dawg` files created by the `dawgdic` C++ library or the original `DAWG` Python extension. The current version is 0.9.0, with infrequent releases typically for minor updates or dependency adjustments, focusing on API and binary compatibility with the original `DAWG` library where possible.

pip install dawg2-python
INSTALL
IMPORT
SIG · DAWG2-PYTHON
D
dawg2-python
serializationpythonv0.9.0
Install
1.6s avg
Import
13ms
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.9.0 · 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.014s · 18.2MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.013s · 19MB
16MB installed
● package 16MB
Code
Verified usage

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

DAWG
✓ from dawg_python import DAWG
BytesDAWG
✓ from dawg_python import BytesDAWG
RecordDAWG
✓ from dawg_python import RecordDAWG

This quickstart demonstrates how to load and query a `.dawg` file using `dawg2-python`. Note that `dawg2-python` is a pure-Python *reader* and cannot create or save `.dawg` files. For creating the `.dawg` file in this example, the `dawg` (C-extension based) library is used. You would typically use existing `.dawg` files generated by `dawg` or `dawgdic`.

import os import tempfile import dawg # This is the *original* DAWG library, for creating the .dawg file import dawg_python # This is dawg2-python, for reading the .dawg file # Create a dummy .dawg file using the original 'dawg' library # (dawg2-python is for reading, not creating/saving) def create_dummy_dawg(filepath): words = ['apple', 'apricot', 'banana', 'bandana', 'cat'] d = dawg.DAWG(words) d.save(filepath) # Use a temporary file for demonstration with tempfile.NamedTemporaryFile(suffix='.dawg', delete=False) as tmp_file: dawg_filepath = tmp_file.name try: # 1. Create a DAWG file (requires the 'dawg' library installed) print(f"Creating a temporary DAWG file at {dawg_filepath}...") create_dummy_dawg(dawg_filepath) print("DAWG file created.") # 2. Load and query the DAWG file using dawg2-python print("Loading DAWG using dawg2-python...") reader = dawg_python.DAWG().load(dawg_filepath) print("DAWG loaded successfully.") # Querying words print(f"'apple' in DAWG: {'apple' in reader}") print(f"'banana' in DAWG: {'banana' in reader}") print(f"'orange' in DAWG: {'orange' in reader}") # Getting prefixes print(f"Prefixes for 'bandana': {list(reader.prefixes('bandana'))}") # Iterating through all words print("First 5 words:") for i, word in enumerate(reader.iterkeys()): if i >= 5: break print(f"- {word}") finally: # Clean up the temporary file if os.path.exists(dawg_filepath): os.remove(dawg_filepath) print(f"Cleaned up temporary file: {dawg_filepath}")
Debug
Known issues
gotchaDAWG2-Python is a pure-Python library for *reading* existing DAWG files. It does not support creating, modifying, or saving DAWG structures. Attempting to use methods like `save()` or passing data to the constructor will result in errors.
fix
Use the original `dawg` library (which has C extensions) or `dawgdic` C++ tools to create and save `.dawg` files. Then, use `dawg2-python` for read-only access.
affects: All versions
breakingStarting from version 0.8.0, the minimal Python version required has been updated to 3.8.
fix
Ensure your Python environment is running Python 3.8 or a newer compatible version (less than 4.0).
affects: >=0.8.0
gotchaThe `setup.py` build system was migrated to `poetry` in version 0.8.0. This primarily affects maintainers and those building from source, but it indicates a change in development tooling.
fix
No direct action required for end-users installing via `pip`. Developers should be aware of the shift to `poetry` for project management.
affects: >=0.8.0
Errors
Common errors & fixes
AttributeError: 'DAWG' object has no attribute 'save'
Attempting to save a DAWG created or loaded with `dawg_python` (dawg2-python). This library is read-only.
fix
Use the original `dawg` library (e.g., `import dawg; d = dawg.DAWG(words); d.save('file.dawg')`) to create and save DAWG files. `dawg_python` is only for loading and querying.
TypeError: DAWG() takes no arguments
Attempting to initialize `dawg_python.DAWG` with a list of words or other data. The constructor is intended for internal use or loading, not direct data input for building a DAWG.
fix
Initialize the `DAWG` object without arguments (e.g., `d = dawg_python.DAWG()`) and then call `.load('filepath.dawg')` to load an existing DAWG file. Creating DAWGs from data requires the original `dawg` library.
ModuleNotFoundError: No module named 'dawg'
This error likely occurs if you are following documentation that refers to the *original* `dawg` library (the C-extension version) for creating `.dawg` files, but you have only installed `dawg2-python`.
fix
If you intend to *create* `.dawg` files, you must install the `dawg` library (note the missing `_python`): `pip install dawg`. If you only intend to *read* existing `.dawg` files, ensure you are importing `dawg_python` correctly and loading an already saved file.
Upgrade
Version history
0.9.0latest on PyPI · released Feb 17, 2025
Audit
Dependencies
pythonrequiredRequires Python 3.8 or newer, but less than 4.0.
dawgoptionalWhile dawg2-python itself is pure-Python for reading, the .dawg files it consumes are typically created by the 'dawg' (C-extension) library or dawgdic C++ library.
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
dawg2-python — pip install dawg2-python · libregistry