Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Tools for generating solutions and starting grids for Sudoku.

Project Description

sudokulib is a collection of tools that are useful for generating solutions to Sudoku puzzles. It uses a recursive backtracking algorithm (originally written by Jeremy Brown, Cel Destept), and is capable of generating a 3x3 Sudoku in ~0.015 seconds. It can also generate 4x4 Sudokus in ~0.100 seconds (sometimes longer).

Some 5x5 grids have been generated in a matter of seconds using this library, but I’ve also seen the program run for hours without successfully generating a 5x5. Anything beyond 5x5 always seems to take a long time.

You can solve Sudoku puzzles using this library by calling the init_grid method of an instance of Sudoku. This method takes two types of values. Where n is the grid size:

  • a 1-dimensional list with n^4 values
  • a multi-dimensional list with n^2 lists with n^2 values each. Each list represents a row in the grid

The values in the list(s) provided to init_grid must be numeric and greater than 0 but less than n^2 in order to appear in the starting grid. Any other values will be ignored, and the puzzle will be solved with no consideration for such values.

The library also provides utilities for generating starting grids, so you can play Sudoku instead of just generating solutions. There are several difficulty levels to choose from.

Also included in the distribution is a sample class for generating “jigsaw” variations of Sudoku. This class will occasionally generate solvable grids within a second or two, but it takes much longer more often than not.

Release History

This version
History Node


History Node


Download Files

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

File Name & Hash SHA256 Hash Help Version File Type Upload Date
(40.0 kB) Copy SHA256 Hash SHA256
Source Jan 23, 2010

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting