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 .txt formats.
Installing
From pypi (recommended)
pip install puzpy
From source (for development)
pip install .[dev]
Example Usage
import puz
#
# Load a puzzle file:
#
p = puz.read('testfiles/washpost.puz')
#
# Print all clues and their answers
#
clues = p.clue_numbering()
print('Across')
for clue in clues.across:
print(f'{clue.number}. {clue.text} - {clue.solution}')
print('Down')
for clue in clues.down:
print(f'{clue.number}. {clue.text} - {clue.solution}')
#
# Print the puzzle grid
#
for row in p.grid():
print(' '.join(row))
#
# Unlock a puzzle that has a locked solution
#
p.unlock_solution(7844)
# Now print the unscrambed solution grid:
for row in p.solution_grid():
print(' '.join(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('example.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
Unit tests
pytest -v
lint
flake8 . --show-source --statistics
Viewer
This repo includes a puz file viewer. The script renders a .puz or .txt file as a print-ready stand-alone HTML file. Its only dependency is puz.py. Examples: 15x15, 21x21, ...
$ python puz_viewer.py --help
usage: puz_viewer.py [-h] [-o OUTFILE] [--outdir OUTDIR] [-f {auto,puz,txt}] [--index] [puzzles ...]
Generate an HTML viewer for a crossword puzzle or puzzles
positional arguments:
puzzles Paths to .puz or .txt files (default: stdin)
options:
-h, --help show this help message and exit
-o, --outfile OUTFILE
Output HTML filename (default: stdout, or auto-generated from input filename in batch mode)
--outdir OUTDIR Output directory for HTML files (default: .)
-f, --format {auto,puz,txt}
Input format (default: auto-detect)
--index Generate index.html in output directory (batch mode)
Python version support
Python >=3.9 required since 0.3.1. For older python versions including 2.x use puzpy==0.2.6
Resources
- AcrossLite .puz file format (archived from http://code.google.com/p/puz/wiki/FileFormat)
- Across text format (archived from https://www.litsoft.com/across/docs/AcrossTextFormat.pdf)
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.6.0.tar.gz.
File metadata
- Download URL: puzpy-0.6.0.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba9e420cfd2a54d7e5b5d8f401cafec52d5a98df0435af9bc78378dd1056371e
|
|
| MD5 |
24a1f77eed78d07a1284481de0fddfd9
|
|
| BLAKE2b-256 |
554a58834ca428c42b9054ec89ce2cb1a75e1de26f472caf1492c595478aa07f
|
Provenance
The following attestation bundles were made for puzpy-0.6.0.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.6.0.tar.gz -
Subject digest:
ba9e420cfd2a54d7e5b5d8f401cafec52d5a98df0435af9bc78378dd1056371e - Sigstore transparency entry: 1175312297
- Sigstore integration time:
-
Permalink:
alexdej/puzpy@927d75e3579c549b307c64b65fa6018bf816aa87 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/alexdej
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@927d75e3579c549b307c64b65fa6018bf816aa87 -
Trigger Event:
push
-
Statement type:
File details
Details for the file puzpy-0.6.0-py3-none-any.whl.
File metadata
- Download URL: puzpy-0.6.0-py3-none-any.whl
- Upload date:
- Size: 16.2 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 |
ca374a3f0302867646f9546c0472680966b5a3ae6c796b1ba30e63ca0460cb75
|
|
| MD5 |
51d18049992c05cb3ce7dfc5e54c52d0
|
|
| BLAKE2b-256 |
51d96c51e63b2c56cfe91ef73c67426201b94b0b2e287aa4681c8067064b4f95
|
Provenance
The following attestation bundles were made for puzpy-0.6.0-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.6.0-py3-none-any.whl -
Subject digest:
ca374a3f0302867646f9546c0472680966b5a3ae6c796b1ba30e63ca0460cb75 - Sigstore transparency entry: 1175312301
- Sigstore integration time:
-
Permalink:
alexdej/puzpy@927d75e3579c549b307c64b65fa6018bf816aa87 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/alexdej
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@927d75e3579c549b307c64b65fa6018bf816aa87 -
Trigger Event:
push
-
Statement type: