{"id":8071,"library":"dawg-python","title":"DAWG-Python","description":"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.","status":"active","version":"0.7.2","language":"python","source_language":"en","source_url":"https://github.com/kmike/DAWG-Python/","tags":["DAWG","DAFSA","data structure","dictionary","trie","immutable","nlp"],"install":[{"cmd":"pip install dawg-python","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"wrong":"from dawg import DAWG","symbol":"DAWG","correct":"from dawg_python import DAWG"},{"symbol":"BytesDAWG","correct":"from dawg_python import BytesDAWG"},{"symbol":"Dictionary","correct":"from dawg_python import Dictionary"}],"quickstart":{"code":"import os\nfrom dawg import DAWG, IntDAWG\n\n# 1. Create a sample DAWG file (in a real scenario, this might come from dawgdic)\nwords_to_build = ['apple', 'apricot', 'banana', 'cat', 'dog']\n# For large sets, words should be pre-sorted for performance.\ntemp_dawg = DAWG(words_to_build)\ndawg_file_path = 'sample_data.dawg'\ntemp_dawg.save(dawg_file_path)\n\n# 2. Load the DAWG from a file (primary use case)\nloaded_dawg = DAWG().load(dawg_file_path)\n\n# 3. Query the loaded DAWG\nprint(f\"Is 'apple' in DAWG? {'apple' in loaded_dawg}\")\nprint(f\"Words starting with 'a': {list(loaded_dawg.keys('a'))}\")\nprint(f\"Longest prefix for 'apricot': {loaded_dawg.longest_prefix('apricot')}\")\n\n# Clean up the temporary file\nos.remove(dawg_file_path)\n\n# Example with IntDAWG for words with integer payloads\nint_data = [('hello', 10), ('world', 20)]\nint_dawg_obj = IntDAWG(int_data)\nprint(f\"Value for 'world': {int_dawg_obj['world']}\")","lang":"python","description":"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."},"warnings":[{"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`.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To modify a DAWG, you must build a new DAWG object from the desired set of words and payloads.","message":"DAWG objects (both `DAWG` and `IntDAWG`) are immutable once created or loaded from a file. You cannot add, remove, or modify words/payloads in place.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Pre-sort your list of words/tuples before passing them to the DAWG constructor: `DAWG(sorted(my_words_list))`.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that all payloads provided to `IntDAWG` are integers.","message":"`IntDAWG` is specifically designed for string keys with *integer* payloads. Passing non-integer values as payloads will result in a `TypeError`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.7.2':56 'acycl':11,15 'also':44 'automata':18 'build':45 'c':34,40 'creat':30 'current':53 'dafsa':64 'data':65 'dawg':2,9,27,38,47,63 'dawg-python':1 'dawgdic':33 'design':21 'determinist':14 'dictionari':67 'direct':10 'exist':26 'extens':41 'file':28 'finit':16 'graph':13 'immut':69 'infrequ':60 'librari':35 'list':51 'load':23 'need':62 'nlp':70 'occur':59 'often':29 'pure':5 'pure-python':4 'python':3,6,39 'queri':25 'reader':7 'releas':58 'small':46 'sort':49 'state':17 'structur':66 'trie':68 'version':54 'word':12,50","created_at":"2026-04-16T17:00:16.699691+00:00","updated_at":"2026-04-16T17:00:16.699691+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.7.2","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/kmike/DAWG-Python","docs":null,"changelog":null,"pypi":"https://pypi.org/project/dawg-python/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-06-30","next_check":"2026-07-30","install_tag":null}}