Python-GMP
==========
Python extension module providing safe bindings to the GNU GMP. This module
shouldn't crash the interpreter!
It can be used as a gmpy2/python-flint replacement to provide
CPython-compatible integer (mpz) and rational (mpq) types. The module includes
also few functions (factorial, gcd and isqrt), compatible with the stdlib's
module math.
Motivation
----------
The CPython (and most other Python implementations, like PyPy) is optimized to
work with small integers. Algorithms used here for "big enough" integers
usually aren't best known in the field. Fortunately, it's possible to use
bindings (for example, the `gmpy2 <https://pypi.org/project/gmpy2/>`_ package)
to the GNU Multiple Precision Arithmetic Library (GMP), which aims to be faster
than any other bignum library for all operand sizes.
But such extension modules usually rely on default GMP's memory allocation
functions and can't recover from errors such as out of memory. So, it's easy
to crash the Python interpreter during the interactive session. Following
example with the gmpy2 should work on most Unix systems:
.. code:: pycon
>>> import gmpy2, resource
>>> gmpy2.__version__
'2.2.1'
>>> resource.setrlimit(resource.RLIMIT_AS, (1024*32*1024, -1))
>>> z = gmpy2.mpz(29925959575501)
>>> while True: # this loop will crash interpter
... z = z*z
...
GNU MP: Cannot allocate memory (size=2949160)
Aborted
The gmp module handles such errors correctly:
.. code:: pycon
>>> import gmp, resource
>>> resource.setrlimit(resource.RLIMIT_AS, (1024*32*1024, -1))
>>> z = gmp.mpz(29925959575501)
>>> while True:
... z = z*z
...
Traceback (most recent call last):
File "<python-input-3>", line 2, in <module>
z = z*z
~^~
MemoryError
>>> # interpreter still works, all variables in
>>> # the current scope are available,
>>> z.bit_length() # including pre-failure value of z
mpz(5867630)
Raw data
{
"_id": null,
"home_page": null,
"name": "python-gmp",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "Sergey B Kirpichev <skirpichev@gmail.com>",
"keywords": "gmp, multiple-precision, arbitrary-precision, bignum",
"author": null,
"author_email": "Sergey B Kirpichev <skirpichev@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/4c/ca/7c8ac47db957d89ef57d2694c3c863d800c8d6b2c5f881bc077f4a653250/python_gmp-0.2.2.tar.gz",
"platform": null,
"description": "Python-GMP\n==========\n\nPython extension module providing safe bindings to the GNU GMP. This module\nshouldn't crash the interpreter!\n\nIt can be used as a gmpy2/python-flint replacement to provide\nCPython-compatible integer (mpz) and rational (mpq) types. The module includes\nalso few functions (factorial, gcd and isqrt), compatible with the stdlib's\nmodule math.\n\n\nMotivation\n----------\n\nThe CPython (and most other Python implementations, like PyPy) is optimized to\nwork with small integers. Algorithms used here for \"big enough\" integers\nusually aren't best known in the field. Fortunately, it's possible to use\nbindings (for example, the `gmpy2 <https://pypi.org/project/gmpy2/>`_ package)\nto the GNU Multiple Precision Arithmetic Library (GMP), which aims to be faster\nthan any other bignum library for all operand sizes.\n\nBut such extension modules usually rely on default GMP's memory allocation\nfunctions and can't recover from errors such as out of memory. So, it's easy\nto crash the Python interpreter during the interactive session. Following\nexample with the gmpy2 should work on most Unix systems:\n\n.. code:: pycon\n\n >>> import gmpy2, resource\n >>> gmpy2.__version__\n '2.2.1'\n >>> resource.setrlimit(resource.RLIMIT_AS, (1024*32*1024, -1))\n >>> z = gmpy2.mpz(29925959575501)\n >>> while True: # this loop will crash interpter\n ... z = z*z\n ...\n GNU MP: Cannot allocate memory (size=2949160)\n Aborted\n\nThe gmp module handles such errors correctly:\n\n.. code:: pycon\n\n >>> import gmp, resource\n >>> resource.setrlimit(resource.RLIMIT_AS, (1024*32*1024, -1))\n >>> z = gmp.mpz(29925959575501)\n >>> while True:\n ... z = z*z\n ...\n Traceback (most recent call last):\n File \"<python-input-3>\", line 2, in <module>\n z = z*z\n ~^~\n MemoryError\n >>> # interpreter still works, all variables in\n >>> # the current scope are available,\n >>> z.bit_length() # including pre-failure value of z\n mpz(5867630)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Safe bindings to the GNU GMP library",
"version": "0.2.2",
"project_urls": {
"Bug Tracker": "https://github.com/diofant/python-gmp/issues",
"Documentation": "https://python-gmp.readthedocs.io/en/latest/",
"Homepage": "https://github.com/diofant/python-gmp",
"Source Code": "https://github.com/diofant/python-gmp"
},
"split_keywords": [
"gmp",
" multiple-precision",
" arbitrary-precision",
" bignum"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "af1cf765cb24a96bddb01492ebeb18c4bcc08de35ae36b6173de4d7519335683",
"md5": "f481877d648125519f49bac1d59e91d1",
"sha256": "4417c1bce9541dd5bff31d5ee6d67f48a8314c0789fe804982f853a8f743cb3a"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp310-cp310-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "f481877d648125519f49bac1d59e91d1",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": ">=3.9",
"size": 270862,
"upload_time": "2025-01-21T07:47:11",
"upload_time_iso_8601": "2025-01-21T07:47:11.548813Z",
"url": "https://files.pythonhosted.org/packages/af/1c/f765cb24a96bddb01492ebeb18c4bcc08de35ae36b6173de4d7519335683/python_gmp-0.2.2-cp310-cp310-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f18a899c9a5a65398404392a43c5e315d14d215955a95daf810a1634312a705d",
"md5": "9e8f6bc66c2eb59d4417113f1432fda7",
"sha256": "db4aea032762804b74449c6a2a1b3aa4b370f98ddf6b2bcd3b44f600ae2ba9b0"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp310-cp310-win_amd64.whl",
"has_sig": false,
"md5_digest": "9e8f6bc66c2eb59d4417113f1432fda7",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": ">=3.9",
"size": 453601,
"upload_time": "2025-01-21T07:47:14",
"upload_time_iso_8601": "2025-01-21T07:47:14.540791Z",
"url": "https://files.pythonhosted.org/packages/f1/8a/899c9a5a65398404392a43c5e315d14d215955a95daf810a1634312a705d/python_gmp-0.2.2-cp310-cp310-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7f1990c08ab44348a22ecd5d4f91ac93e4c3d2531d09035244bad1a4ebdb928f",
"md5": "ba393f9971fe3d1f5c09936134ee6c9a",
"sha256": "d0cac5aedf404d49fbd9bc5bf774ddcb3b2b60ee56a158f1d1ab255cbc03a140"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp311-cp311-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "ba393f9971fe3d1f5c09936134ee6c9a",
"packagetype": "bdist_wheel",
"python_version": "cp311",
"requires_python": ">=3.9",
"size": 270858,
"upload_time": "2025-01-21T07:47:17",
"upload_time_iso_8601": "2025-01-21T07:47:17.335229Z",
"url": "https://files.pythonhosted.org/packages/7f/19/90c08ab44348a22ecd5d4f91ac93e4c3d2531d09035244bad1a4ebdb928f/python_gmp-0.2.2-cp311-cp311-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4803134bf8f652caae1cada16fd2e16346696c753b1b3366a805db7cb916d99c",
"md5": "a2e2c24d45f0ae3bf4053813589f3618",
"sha256": "57fea0c45f1f07baeb6d2dd89317ffd67151155c51f327ee0ba086872bea4191"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp311-cp311-win_amd64.whl",
"has_sig": false,
"md5_digest": "a2e2c24d45f0ae3bf4053813589f3618",
"packagetype": "bdist_wheel",
"python_version": "cp311",
"requires_python": ">=3.9",
"size": 453602,
"upload_time": "2025-01-21T07:47:19",
"upload_time_iso_8601": "2025-01-21T07:47:19.821962Z",
"url": "https://files.pythonhosted.org/packages/48/03/134bf8f652caae1cada16fd2e16346696c753b1b3366a805db7cb916d99c/python_gmp-0.2.2-cp311-cp311-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "64c8788724e03f554bd949c051cc137400cc46070c316a8d82a586b73334271f",
"md5": "dfa83d03fc24b9c5043783698ccd9132",
"sha256": "35e5e4b510482444fdbff4bcab6903ad89c4779ff1fcdf2c2c27af48beeb846d"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp312-cp312-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "dfa83d03fc24b9c5043783698ccd9132",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": ">=3.9",
"size": 270845,
"upload_time": "2025-01-21T07:47:22",
"upload_time_iso_8601": "2025-01-21T07:47:22.213514Z",
"url": "https://files.pythonhosted.org/packages/64/c8/788724e03f554bd949c051cc137400cc46070c316a8d82a586b73334271f/python_gmp-0.2.2-cp312-cp312-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c031d1e9d29c1a4d8e6c1fd88d4ba0b775c7493f7d0093380490c324cf3fb5c2",
"md5": "9b292d67873478a24a631c6f16b82fb0",
"sha256": "c0295bb58eef74a3d235d8e23611c44812b3c26d2ac5b7d2987ca8b013eb20f3"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp312-cp312-win_amd64.whl",
"has_sig": false,
"md5_digest": "9b292d67873478a24a631c6f16b82fb0",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": ">=3.9",
"size": 454117,
"upload_time": "2025-01-21T07:47:24",
"upload_time_iso_8601": "2025-01-21T07:47:24.780594Z",
"url": "https://files.pythonhosted.org/packages/c0/31/d1e9d29c1a4d8e6c1fd88d4ba0b775c7493f7d0093380490c324cf3fb5c2/python_gmp-0.2.2-cp312-cp312-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "33180e1fc5a9de6caa9ed6a1a55e1f00b37ceafcd97531ca90221549b066b856",
"md5": "42ca2944dd6a2c950814ab34121b9ecd",
"sha256": "d63c711bd9858b40d8d95a4c6ac4dc313d202b730411e711fb27a9f7eb668f19"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp313-cp313-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "42ca2944dd6a2c950814ab34121b9ecd",
"packagetype": "bdist_wheel",
"python_version": "cp313",
"requires_python": ">=3.9",
"size": 270860,
"upload_time": "2025-01-21T07:47:28",
"upload_time_iso_8601": "2025-01-21T07:47:28.159213Z",
"url": "https://files.pythonhosted.org/packages/33/18/0e1fc5a9de6caa9ed6a1a55e1f00b37ceafcd97531ca90221549b066b856/python_gmp-0.2.2-cp313-cp313-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "128e441f35ea2fe0d557e2fbe23c4d5688ba0f29318beab12cd9b716286dffd4",
"md5": "5cfe97fd4ca6730ee0ef867d9a1b7558",
"sha256": "af795cc9255570be6102e2b7c174ee98cd09eb01ff90891398ae6610d1e7f614"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp313-cp313t-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "5cfe97fd4ca6730ee0ef867d9a1b7558",
"packagetype": "bdist_wheel",
"python_version": "cp313",
"requires_python": ">=3.9",
"size": 273403,
"upload_time": "2025-01-21T07:47:32",
"upload_time_iso_8601": "2025-01-21T07:47:32.231271Z",
"url": "https://files.pythonhosted.org/packages/12/8e/441f35ea2fe0d557e2fbe23c4d5688ba0f29318beab12cd9b716286dffd4/python_gmp-0.2.2-cp313-cp313t-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "114202e59b530dd67859d964b95d0ef5746f5e9ea542d85d2b445262eae920b6",
"md5": "41a581956fb8a78437cb424d90eac153",
"sha256": "55c61c456603e500b2654844d2fe0488e7b4905f799ca478612f2e6d9cc5e234"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp313-cp313t-win_amd64.whl",
"has_sig": false,
"md5_digest": "41a581956fb8a78437cb424d90eac153",
"packagetype": "bdist_wheel",
"python_version": "cp313",
"requires_python": ">=3.9",
"size": 456650,
"upload_time": "2025-01-21T07:47:33",
"upload_time_iso_8601": "2025-01-21T07:47:33.708068Z",
"url": "https://files.pythonhosted.org/packages/11/42/02e59b530dd67859d964b95d0ef5746f5e9ea542d85d2b445262eae920b6/python_gmp-0.2.2-cp313-cp313t-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d8c7235dd930b9eb6f89318b7c92d2d0c0a8c0b531f01972f405152a6a903347",
"md5": "e396e9dd3dcbf699c722eb143c0fbf58",
"sha256": "acac5e3a15881e8ddbba928085b872ba942d5446ac6ccbe6b4629eaae0c04ef1"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp313-cp313-win_amd64.whl",
"has_sig": false,
"md5_digest": "e396e9dd3dcbf699c722eb143c0fbf58",
"packagetype": "bdist_wheel",
"python_version": "cp313",
"requires_python": ">=3.9",
"size": 454158,
"upload_time": "2025-01-21T07:47:30",
"upload_time_iso_8601": "2025-01-21T07:47:30.589418Z",
"url": "https://files.pythonhosted.org/packages/d8/c7/235dd930b9eb6f89318b7c92d2d0c0a8c0b531f01972f405152a6a903347/python_gmp-0.2.2-cp313-cp313-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c1ff2ffc34f146f8a2a7ba4d3625e504f2ef7c1b7a34848dd1f2269d1e1e4fc8",
"md5": "98ac0bdc71830235a0f8631ae1923c9a",
"sha256": "82d70aa7e3aa36fe56f272c50824534b77b0a7a6a2ab24f2bb15fcc7e1409b49"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp39-cp39-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "98ac0bdc71830235a0f8631ae1923c9a",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 270558,
"upload_time": "2025-01-21T07:47:36",
"upload_time_iso_8601": "2025-01-21T07:47:36.100698Z",
"url": "https://files.pythonhosted.org/packages/c1/ff/2ffc34f146f8a2a7ba4d3625e504f2ef7c1b7a34848dd1f2269d1e1e4fc8/python_gmp-0.2.2-cp39-cp39-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5a5bbbadcfc90e902168201814fffcd57f6d7c8ed847dd60320ae2d99a0da76a",
"md5": "846e033af03bd0919e17db0bb37b7ac5",
"sha256": "95904f45922f527e6dbba82945f411dcb1e17db8127526d1c10e24e52c7d42e6"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-cp39-cp39-win_amd64.whl",
"has_sig": false,
"md5_digest": "846e033af03bd0919e17db0bb37b7ac5",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 453795,
"upload_time": "2025-01-21T07:47:38",
"upload_time_iso_8601": "2025-01-21T07:47:38.581123Z",
"url": "https://files.pythonhosted.org/packages/5a/5b/bbadcfc90e902168201814fffcd57f6d7c8ed847dd60320ae2d99a0da76a/python_gmp-0.2.2-cp39-cp39-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4c0b609462e85356306b3eebb8aa145162debeae3782e61e7e79bec25f4adb71",
"md5": "e6e3691bddac01ffec4aef5ad86d300b",
"sha256": "7fffb0c518bc0fdcd540b32d3e4f4d5c496fca2ba542ba8388563849774f2dca"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-pp310-pypy310_pp73-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "e6e3691bddac01ffec4aef5ad86d300b",
"packagetype": "bdist_wheel",
"python_version": "pp310",
"requires_python": ">=3.9",
"size": 267967,
"upload_time": "2025-01-21T07:47:41",
"upload_time_iso_8601": "2025-01-21T07:47:41.015532Z",
"url": "https://files.pythonhosted.org/packages/4c/0b/609462e85356306b3eebb8aa145162debeae3782e61e7e79bec25f4adb71/python_gmp-0.2.2-pp310-pypy310_pp73-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bbfb0974449bbd7e6bfcfa8705d433e75aa248bdb5e4d0e25f2a15fa9155a8e5",
"md5": "fd9299ad891748035144ba3ce2c4d495",
"sha256": "da877098993223b1a100125c665e0a0d5f3062b59d89383ef4a6c54cfd19ba5f"
},
"downloads": -1,
"filename": "python_gmp-0.2.2-pp310-pypy310_pp73-win_amd64.whl",
"has_sig": false,
"md5_digest": "fd9299ad891748035144ba3ce2c4d495",
"packagetype": "bdist_wheel",
"python_version": "pp310",
"requires_python": ">=3.9",
"size": 452724,
"upload_time": "2025-01-21T07:47:43",
"upload_time_iso_8601": "2025-01-21T07:47:43.384941Z",
"url": "https://files.pythonhosted.org/packages/bb/fb/0974449bbd7e6bfcfa8705d433e75aa248bdb5e4d0e25f2a15fa9155a8e5/python_gmp-0.2.2-pp310-pypy310_pp73-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4cca7c8ac47db957d89ef57d2694c3c863d800c8d6b2c5f881bc077f4a653250",
"md5": "8277960ad4314e44bb43e2593a845f93",
"sha256": "045811bc00299f9796eaff17610d7ec261ac764f404ae06d232b104c0d64d5f7"
},
"downloads": -1,
"filename": "python_gmp-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "8277960ad4314e44bb43e2593a845f93",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 55128,
"upload_time": "2025-01-21T07:47:45",
"upload_time_iso_8601": "2025-01-21T07:47:45.048033Z",
"url": "https://files.pythonhosted.org/packages/4c/ca/7c8ac47db957d89ef57d2694c3c863d800c8d6b2c5f881bc077f4a653250/python_gmp-0.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-21 07:47:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "diofant",
"github_project": "python-gmp",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "python-gmp"
}