Skip to main content

A Python interface to the number theory library PARI/GP

Project description Documentation Status

A Python interface to the number theory library PARI/GP.

This library supports both Python 2 and Python 3.



A package python-cypari2 or python2-cypari2 or python3-cypari2 might be available in your package manager.

Using pip


  • PARI/GP >= 2.9.4 (header files and library)
  • Python 2.7 or Python >= 3.4
  • pip
  • cysignals >= 1.7
  • Cython >= 0.28

Install cypari2 via the Python Package Index (PyPI) via

$ pip install cypari2 [--user]

(the optional option –user allows to install cypari2 for a single user and avoids using pip with administrator rights). Depending on your operating system the pip command might also be called pip2 or pip3.

If you want to try the development version use

$ pip install git+ [--user]

If you have an error saying libpari-gmp*.so* is missing and have all requirements already installed, try to reinstall cysignals and cypari2

$ pip install cysignals --upgrade [--user]
$ pip install cypari2 --upgrade [--user]


Any other way to install cypari2 is not supported. In particular, python install will produce an error.


The interface as been kept as close as possible from PARI/GP. The following computation in GP

? zeta(2)
%1 = 1.6449340668482264364724151666460251892

? p = x^3 + x^2 + x - 1;
? modulus = t^3 + t^2 + t - 1;
? fq = factorff(p, 3, modulus);
? centerlift(lift(fq))
%5 =
[            x - t 1]

[x + (t^2 + t - 1) 1]

[   x + (-t^2 - 1) 1]

translates into

>>> import cypari2
>>> pari = cypari2.Pari()

>>> pari(2).zeta()

>>> p = pari("x^3 + x^2 + x - 1")
>>> modulus = pari("t^3 + t^2 + t - 1")
>>> fq = p.factorff(3, modulus)
>>> fq.lift().centerlift()
[x - t, 1; x + (t^2 + t - 1), 1; x + (-t^2 - 1), 1]

The object pari above is the object for the interface and acts as a constructor. It can be called with basic Python objects like integer or floating point. When called with a string as in the last example the corresponding string is interpreted as if it was executed in a GP shell.

Beyond the interface object pari of type Pari, any object you get a handle on is of type Gen (that is a wrapper around the GEN type from libpari). All PARI/GP functions are then available in their original names as methods like zeta, factorff, lift or centerlift above.

Alternatively, the pari functions are accessible as methods of pari. The same computations be done via

>>> import cypari2
>>> pari = cypari2.Pari()

>>> pari.zeta(2)

>>> p = pari("x^3 + x^2 + x - 1")
>>> modulus = pari("t^3 + t^2 + t - 1")
>>> fq = pari.factorff(p, 3, modulus)
>>> pari.centerlift(pari.lift(fq))
[x - t, 1; x + (t^2 + t - 1), 1; x + (-t^2 - 1), 1]

The complete documentation of cypari2 is available at and the PARI/GP documentation at


Submit pull request or get in touch with the SageMath developers.

Project details

Download files

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

Files for cypari2, version 2.1.2
Filename, size File type Python version Upload date Hashes
Filename, size cypari2-2.1.2.tar.gz (2.2 MB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page