Skip to main content

python crossword puzzle library

Project description

puz.py: Python parser for .puz files

PyPI - Version PyPI - Downloads PyPI - License GitHub branch check runs Coverage

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)

uv sync --extra dev

Or with pip:

pip install -e .[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

Build and run tests

Unit tests

uv run pytest

Lint

uv run ruff check

Type check

uv run pyright

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

PyPI - Python Version

Python >=3.9 required since 0.3.1. For older python versions including 2.x use puzpy==0.2.6

Resources

License

MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

puzpy-0.6.1.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

puzpy-0.6.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file puzpy-0.6.1.tar.gz.

File metadata

  • Download URL: puzpy-0.6.1.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for puzpy-0.6.1.tar.gz
Algorithm Hash digest
SHA256 7ec6b7e51f1a3a09af6ccd8f1b54c9e5cd95da347e340b88bac933c4d9fa7f63
MD5 210c91f41942b5dae04747725d8c0cfe
BLAKE2b-256 459f51f3bb801f8d0146ed6687861bf9323e59cf872b881ae5282c966f6fcd0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for puzpy-0.6.1.tar.gz:

Publisher: publish.yml on alexdej/puzpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file puzpy-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: puzpy-0.6.1-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.13

File hashes

Hashes for puzpy-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 445c14d881dc37a723eb3527dd9baa649ec309a87fddc874e94ddaedbe483ec1
MD5 8ac0a324955caa96685ac4ef26dcea5e
BLAKE2b-256 065e1fb75637f9889a948eca4012ddeff404c5962ab657d97aa18aea460e35a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for puzpy-0.6.1-py3-none-any.whl:

Publisher: publish.yml on alexdej/puzpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page