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/or .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()
solution = puz.Grid(p.solution, p.width, p.height)

print('Across')
for clue in clues.across:
    answer = solution.get_string_for_clue(clue)
    print(clue['num'], clue['clue'], '-', answer)

print('Down')
for clue in clues.down:
    answer = solution.get_string_for_clue(clue)
    print(clue['num'], clue['clue'], '-', answer)

#
# Print the puzzle grid
#
grid = puz.Grid(p.fill, p.width, p.height)
for row in range(p.height):
    print(' '.join(grid.get_row(row)))

#
# Unlock a puzzle that has a locked solution
#
p.unlock_solution(7844)

# Now 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

Build and run tests

Unit tests

pytest -v

lint

flake8 . --show-source --statistics

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.4.2.tar.gz (14.6 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.4.2-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for puzpy-0.4.2.tar.gz
Algorithm Hash digest
SHA256 3ec8a16f193df9d031600c241e5bbe06fdab6a4154af3d70c87f4dd0c2d3cd31
MD5 0d09d1c463bc57db0bdf8b89e0ca5318
BLAKE2b-256 4be4b51880d86fb314f94ef65139a393fa0e287ca07534f7a4657d55a4a22563

See more details on using hashes here.

Provenance

The following attestation bundles were made for puzpy-0.4.2.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.4.2-py3-none-any.whl.

File metadata

  • Download URL: puzpy-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for puzpy-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f4f3d770b3572f9064bc0c8dbadc6d5f2f7b61f6079ab034f670e4d23b063f0d
MD5 874f76767c1ee2f49268f18a2f6e79c8
BLAKE2b-256 6a22cb199ef67d924e6f5adff132a8e5cc511c5cb4295c4f6b520c9b5f2fd168

See more details on using hashes here.

Provenance

The following attestation bundles were made for puzpy-0.4.2-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