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

A Python wrapper for the MiniZinc tool pipeline.

Project Description

PyMzn is a Python library that wraps and enhances the MiniZinc tools for CSP modelling and solving. It is built on top of the libminizinc library and provides a number of off-the-shelf functions to readily solve problems encoded in MiniZinc and parse the solutions into Python objects.


First, you need a MiniZinc model encoding the problem you want to solve. Here is a simple 0-1 knapsack problem encoded with MiniZinc::

%% test.mzn %%
int: n;                     % number of objects
set of int: OBJ = 1..n;
int: capacity;              % the capacity of the knapsack
array[OBJ] of int: profit;  % the profit of each object
array[OBJ] of int: size;    % the size of each object

var set of OBJ: x;
constraint sum(i in x)(size[i]) <= capacity;
var int: obj = sum(i in x)(profit[i]);
solve maximize obj;

%% test.dzn %%
n = 5;
profit = [10, 3, 9, 4, 8];
size = [14, 4, 10, 6, 9];

You can solve the above problem using the pymzn.minizinc function::

import pymzn
pymzn.minizinc('test.mzn', 'test.dzn', data={'capacity': 20})

The result will be::

[{'x': {3, 5}}]

The minizinc function automatically flattens the MiniZinc model, using the provided mzn and dzn files, and the inline data provided. It executes the solver on the flattened model and parses the solution stream to get the solutions as Python dictionaries.

PyMzn is also able to:

For a follow-up of this example, read the Quick Start guide.

For more information on the PyMzn functions read the reference manual.


PyMzn can be installed via Pip::

pip3 install pymzn

or from the source code available on GitHub::

python3 install

Currently, PyMzn is developed and maintained in Python v3.5 with a porting to Python v2.7 at every release (the python2 branch does not contain the most recent changes).


PyMzn requires some additional software to be installed on your system before you can use it properly, namely:

You can use any solver you like, but the default one for PyMzn is Gecode. If you use the Gecode solver, PyMzn will work out-of-the-box, otherwise it will need some little configuration (see the Solvers section).

Detailed instructions on how to install libminizinc and Gecode can be found in the Install section of the documentation.


If you find a bug or think of a useful feature, please submit an issue on the GitHub page of PyMzn.

Pull requests are very welcome too. If you are interested in contributing to the PyMzn source code, read about its implementation details. Some things that would be very useful are:

  • Implement specific interfaces for not yet supported solvers;
  • Enhance existing ones.

Heads up on future changes

Be aware that this project is still currently under development and thus it is not in a stable version yet. Things in the future will certainly change. This is especially due to recent changes in the minizinc library, which are introducing lots of new features that could make some of PyMzn’s features obsolete. At any rate, PyMzn will stay updated to the most recent changes in MiniZinc and keep enhancing its python interface.


Paolo Dragone, PhD student at the University of Trento.

Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pymzn-0.13.0.linux-x86_64.tar.gz (48.8 kB) Copy SHA256 Checksum SHA256 any Dumb Binary May 10, 2017
pymzn-0.13.0.tar.gz (25.5 kB) Copy SHA256 Checksum SHA256 Source May 10, 2017

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