python crossword puzzle library
Project description
puz.py: Python parser for .puz files
Python library to read and write crossword puzzle files in Across Lite .puz and/or .txt formats.
Example Usage
import puz
# Load a puzzle file:
p = puz.read('testfiles/washpost.puz')
# Print clues with answers:
numbering = p.clue_numbering()
solution = puz.Grid(p.solution, p.width, p.height)
print('Across')
for clue in numbering.across:
answer = solution.get_string_for_clue(clue)
print(clue['num'], clue['clue'], '-', answer)
print('Down')
for clue in numbering.down:
answer = solution.get_string_for_clue(clue)
print(clue['num'], clue['clue'], '-', answer)
# Print the grid:
grid = puz.Grid(p.fill, p.width, p.height)
for row in range(p.height):
print(' '.join(grid.get_row(row)))
# Unlock a scrambled solution:
p.unlock_solution(7844)
# Print the unscrambed solution grid:
solution = puz.Grid(p.solution, p.width, p.height)
for row in range(p.height):
print(' '.join(solution.get_row(row)))
# Save a puzzle with modifications:
p.fill = 'LAMB' + p.fill[4:]
p.save('example.puz')
# New! Convert from Across Lite text format to .puz:
p2 = puz.read_text('testfiles/text_format_v1.txt')
p2.save('example2.puz')
Notes
The parser is as strict as Across Lite, enforcing internal checksums and magic strings. The parser is designed to round-trip all data in the file, even fields whose utility is unknown. This makes testing easier. It is resilient to garbage at the beginning and end of the file (for example some publishers put the filename on the first line and some files have a rn at the end).
In addition to the handful of tests checked in here, the library has been tested on over 9700 crossword puzzles in .puz format drawn from the archives of several publications including The New York Times, The Washington Post, The Onion, and, the Wall Street Journal. As of writing, it can round-trip 100% of them with full fidelity.
Running tests
To run the full suite of tests:
tox
To run tests using the currently installed version:
pytest
To run a subset of tests on python 2.7:
python2 -m unittest tests
Python version support
All currently supported python3 versions are supported. Python 2.7 was supported, and may still work, though ongoing support is not guaranteed.
Resources
.puzfile format.txtfile format- Archive of NYT daily puzzles 1993 - August 2021
.puzto.pdffile converter
License
MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file puzpy-0.3.2.tar.gz.
File metadata
- Download URL: puzpy-0.3.2.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35eac8d8ef3f745d6aa457df8a6f12bde832c4a6bc02827a01ff466f9d552c62
|
|
| MD5 |
e72a241bf97953ae8c08ea52574f8e0a
|
|
| BLAKE2b-256 |
0630b57c5519e2ff3ec26606922158cf1dc2aafe992292a4bae0fb1756dffa27
|
Provenance
The following attestation bundles were made for puzpy-0.3.2.tar.gz:
Publisher:
publish.yml on alexdej/puzpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
puzpy-0.3.2.tar.gz -
Subject digest:
35eac8d8ef3f745d6aa457df8a6f12bde832c4a6bc02827a01ff466f9d552c62 - Sigstore transparency entry: 635377811
- Sigstore integration time:
-
Permalink:
alexdej/puzpy@c56936bed618bef1a3674355f852bfec16b5cda0 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/alexdej
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c56936bed618bef1a3674355f852bfec16b5cda0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file puzpy-0.3.2-py3-none-any.whl.
File metadata
- Download URL: puzpy-0.3.2-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
429187aad6baf234b73aa368e843071b06a3ed479b12fabfbeeefbce143a2e98
|
|
| MD5 |
dd36af8e905ad96ba51248054e3bc3f6
|
|
| BLAKE2b-256 |
68fec45acdf97ad2fcc3f42274bad7dcedf342f7102bfb55a1705599837a0c62
|
Provenance
The following attestation bundles were made for puzpy-0.3.2-py3-none-any.whl:
Publisher:
publish.yml on alexdej/puzpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
puzpy-0.3.2-py3-none-any.whl -
Subject digest:
429187aad6baf234b73aa368e843071b06a3ed479b12fabfbeeefbce143a2e98 - Sigstore transparency entry: 635377831
- Sigstore integration time:
-
Permalink:
alexdej/puzpy@c56936bed618bef1a3674355f852bfec16b5cda0 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/alexdej
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c56936bed618bef1a3674355f852bfec16b5cda0 -
Trigger Event:
release
-
Statement type: