{"id":32177423,"url":"https://github.com/python-graphblas/python-graphblas","last_synced_at":"2026-04-09T00:02:09.267Z","repository":{"id":37852472,"uuid":"221014819","full_name":"python-graphblas/python-graphblas","owner":"python-graphblas","description":"Python library for GraphBLAS: high-performance sparse linear algebra for scalable graph analytics","archived":false,"fork":false,"pushed_at":"2026-03-21T22:15:16.000Z","size":3938,"stargazers_count":153,"open_issues_count":69,"forks_count":16,"subscribers_count":9,"default_branch":"main","last_synced_at":"2026-03-26T16:54:40.902Z","etag":null,"topics":["complex-networks","graph-algorithms","graph-analysis","graph-datastructures","graph-theory","graphblas","linear-algebra","numba","pydata","python","python-wrapper","sparse","sparse-data","sparse-matrix","suitesparse"],"latest_commit_sha":null,"homepage":"https://python-graphblas.readthedocs.io/en/stable/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/python-graphblas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-11-11T15:47:33.000Z","updated_at":"2026-03-21T22:15:21.000Z","dependencies_parsed_at":"2026-02-15T22:06:58.676Z","dependency_job_id":null,"html_url":"https://github.com/python-graphblas/python-graphblas","commit_stats":{"total_commits":768,"total_committers":11,"mean_commits":69.81818181818181,"dds":"0.16276041666666663","last_synced_commit":"27b23e414a9a73daa9c3dda9698e227562d9a18c"},"previous_names":["metagraph-dev/grblas"],"tags_count":50,"template":false,"template_full_name":null,"purl":"pkg:github/python-graphblas/python-graphblas","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-graphblas%2Fpython-graphblas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-graphblas%2Fpython-graphblas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-graphblas%2Fpython-graphblas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-graphblas%2Fpython-graphblas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/python-graphblas","download_url":"https://codeload.github.com/python-graphblas/python-graphblas/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-graphblas%2Fpython-graphblas/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31314828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["complex-networks","graph-algorithms","graph-analysis","graph-datastructures","graph-theory","graphblas","linear-algebra","numba","pydata","python","python-wrapper","sparse","sparse-data","sparse-matrix","suitesparse"],"created_at":"2025-10-21T20:05:29.113Z","updated_at":"2026-04-09T00:02:09.259Z","avatar_url":"https://github.com/python-graphblas.png","language":"Jupyter Notebook","readme":"![Python-graphblas](https://raw.githubusercontent.com/python-graphblas/python-graphblas/main/docs/_static/img/logo-horizontal-medium-big.svg)\n\n[![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat\u0026colorA=E1523D\u0026colorB=007D8A)](https://numfocus.org)\n[![pyOpenSci](https://tinyurl.com/y22nb8up)](https://github.com/pyOpenSci/software-review/issues/81)\n[![Discord](https://img.shields.io/badge/Chat-Discord-Blue?color=5865f2)](https://discord.com/invite/vur45CbwMz)\n\u003cbr\u003e\n[![conda-forge](https://img.shields.io/conda/vn/conda-forge/python-graphblas.svg)](https://anaconda.org/conda-forge/python-graphblas)\n[![pypi](https://img.shields.io/pypi/v/python-graphblas.svg)](https://pypi.python.org/pypi/python-graphblas/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/python-graphblas)](https://pypi.python.org/pypi/python-graphblas/)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/python-graphblas/python-graphblas/blob/main/LICENSE)\n\u003cbr\u003e\n[![Tests](https://github.com/python-graphblas/python-graphblas/actions/workflows/test_and_build.yml/badge.svg?branch=main)](https://github.com/python-graphblas/python-graphblas/actions)\n[![Docs](https://readthedocs.org/projects/python-graphblas/badge/?version=latest)](https://python-graphblas.readthedocs.io/en/latest/)\n[![Coverage](https://codecov.io/gh/python-graphblas/python-graphblas/graph/badge.svg?token=D7HHLDPQ2Q)](https://codecov.io/gh/python-graphblas/python-graphblas)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7328791.svg)](https://doi.org/10.5281/zenodo.7328791)\n[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/python-graphblas/python-graphblas/HEAD?filepath=notebooks%2FIntro%20to%20GraphBLAS%20%2B%20SSSP%20example.ipynb)\n\nPython library for GraphBLAS: high-performance sparse linear algebra for scalable graph analytics.\nFor algorithms, see\n[`graphblas-algorithms`](https://github.com/python-graphblas/graphblas-algorithms).\n\n- **Documentation:** [https://python-graphblas.readthedocs.io/](https://python-graphblas.readthedocs.io/)\n  - **FAQ:** [https://python-graphblas.readthedocs.io/en/stable/getting_started/faq.html](https://python-graphblas.readthedocs.io/en/stable/getting_started/faq.html)\n  - **GraphBLAS C API:** [https://graphblas.org/docs/GraphBLAS_API_C_v2.0.0.pdf](https://graphblas.org/docs/GraphBLAS_API_C_v2.0.0.pdf)\n  - **SuiteSparse:GraphBLAS User Guide:** [https://github.com/DrTimothyAldenDavis/GraphBLAS/raw/stable/Doc/GraphBLAS_UserGuide.pdf](https://github.com/DrTimothyAldenDavis/GraphBLAS/raw/stable/Doc/GraphBLAS_UserGuide.pdf)\n- **Source:** [https://github.com/python-graphblas/python-graphblas](https://github.com/python-graphblas/python-graphblas)\n- **Bug reports:** [https://github.com/python-graphblas/python-graphblas/issues](https://github.com/python-graphblas/python-graphblas/issues)\n- **Github discussions:** [https://github.com/python-graphblas/python-graphblas/discussions](https://github.com/python-graphblas/python-graphblas/discussions)\n- **Weekly community call:** [python-graphblas#247](https://github.com/python-graphblas/python-graphblas/issues/247) or [https://scientific-python.org/calendars/](https://scientific-python.org/calendars/)\n- **Chat via Discord:** [https://discord.com/invite/vur45CbwMz](https://discord.com/invite/vur45CbwMz) in the [#graphblas channel](https://discord.com/channels/786703927705862175/1024732940233605190)\n\n\u003cp float=\"left\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/python-graphblas/python-graphblas/main/docs/_static/img/draw-example.png\" width=\"231\" align=\"top\" alt=\"Directed graph\", title=\"Directed graph\"/\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/python-graphblas/python-graphblas/main/docs/_static/img/repr-matrix.png\" width=\"231\" align=\"top\" alt=\"Adjacency matrix\" title=\"Adjacency matrix\"/\u003e\n\u003c/p\u003e\n\n## Install\n\nInstall the latest version of Python-graphblas via conda:\n\n```\n$ conda install -c conda-forge python-graphblas\n```\n\nor pip:\n\n```\n$ pip install 'python-graphblas[default]'\n```\n\nThis will also install the [SuiteSparse:GraphBLAS](https://github.com/DrTimothyAldenDavis/GraphBLAS) compiled C library.\nWe currently support the [GraphBLAS C API 2.0 specification](https://graphblas.org/docs/GraphBLAS_API_C_v2.0.0.pdf).\n\n### Optional Dependencies\n\nThe following are not required by python-graphblas, but may be needed for certain functionality to work.\n\n- `pandas` – required for nicer `__repr__`;\n- `matplotlib` – required for basic plotting of graphs;\n- `scipy` – used in `io` module to read/write `scipy.sparse` format;\n- `networkx` – used in `io` module to interface with `networkx` graphs;\n- `fast-matrix-market` - for faster read/write of Matrix Market files with `gb.io.mmread` and `gb.io.mmwrite`.\n\n## Description\n\nCurrently works with [SuiteSparse:GraphBLAS](https://github.com/DrTimothyAldenDavis/GraphBLAS), but the goal is to make it work with all implementations of the GraphBLAS spec.\n\nThe approach taken with this library is to follow the C-API 2.0 specification as closely as possible while making improvements\nallowed with the Python syntax. Because the spec always passes in the output object to be written to, we follow the same,\nwhich is very different from the way Python normally operates. In fact, many who are familiar with other Python data\nlibraries (numpy, pandas, etc) will find it strange to not create new objects for every call.\n\nAt the highest level, the goal is to separate output, mask, and accumulator on the left side of the assignment\noperator `=` and put the computation on the right side. Unfortunately, that approach doesn't always work very well\nwith how Python handles assignment, so instead we (ab)use the left-shift `\u003c\u003c` notation to give the same flavor of\nassignment. This opens up all kinds of nice possibilities.\n\nThis is an example of how the mapping works:\n\n```C\n// C call\nGrB_Matrix_mxm(M, mask, GrB_PLUS_INT64, GrB_MIN_PLUS_INT64, A, B, NULL)\n```\n\n```python\n# Python call\nM(mask.V, accum=binary.plus) \u003c\u003c A.mxm(B, semiring.min_plus)\n```\n\nThe expression on the right `A.mxm(B)` creates a delayed object which does no computation. Once it is used in the\n`\u003c\u003c` expression with `M`, the whole thing is translated into the equivalent GraphBLAS call.\n\nDelayed objects also have a `.new()` method which can be used to force computation and return a new\nobject. This is convenient and often appropriate, but will create many unnecessary objects if used in a loop. It\nalso loses the ability to perform accumulation with existing results. For best performance, following the standard\nGraphBLAS approach of (1) creating the object outside the loop and (2) using the object repeatedly within each loop\nis a much better approach, even if it doesn't feel very Pythonic.\n\nDescriptor flags are set on the appropriate elements to keep logic close to what it affects. Here is the same call\nwith descriptor bits set. `ttcsr` indicates transpose the first and second matrices, complement the structure of the mask,\nand do a replacement on the output.\n\n```C\n// C call\nGrB_Matrix_mxm(M, mask, GrB_PLUS_INT64, GrB_MIN_PLUS_INT64, A, B, desc.ttcsr)\n```\n\n```python\n# Python call\nM(~mask.S, accum=binary.plus, replace=True) \u003c\u003c A.T.mxm(B.T, semiring.min_plus)\n```\n\nThe objects receiving the flag operations (A.T, ~mask, etc) are also delayed objects. They hold on to the state but\ndo no computation, allowing the correct descriptor bits to be set in a single GraphBLAS call.\n\n**If no mask or accumulator is used, the call looks like this**:\n\n```python\nM \u003c\u003c A.mxm(B, semiring.min_plus)\n```\n\nThe use of `\u003c\u003c` to indicate updating is actually just syntactic sugar for a real `.update()` method. The above\nexpression could be written as:\n\n```python\nM.update(A.mxm(B, semiring.min_plus))\n```\n\n## Operations\n\n```python\nM(mask, accum) \u003c\u003c A.mxm(B, semiring)        # mxm\nw(mask, accum) \u003c\u003c A.mxv(v, semiring)        # mxv\nw(mask, accum) \u003c\u003c v.vxm(B, semiring)        # vxm\nM(mask, accum) \u003c\u003c A.ewise_add(B, binaryop)  # eWiseAdd\nM(mask, accum) \u003c\u003c A.ewise_mult(B, binaryop) # eWiseMult\nM(mask, accum) \u003c\u003c A.kronecker(B, binaryop)  # kronecker\nM(mask, accum) \u003c\u003c A.T                       # transpose\n```\n\n## Extract\n\n```python\nM(mask, accum) \u003c\u003c A[rows, cols]             # rows and cols are a list or a slice\nw(mask, accum) \u003c\u003c A[rows, col_index]        # extract column\nw(mask, accum) \u003c\u003c A[row_index, cols]        # extract row\ns = A[row_index, col_index].value           # extract single element\n```\n\n## Assign\n\n```python\nM(mask, accum)[rows, cols] \u003c\u003c A             # rows and cols are a list or a slice\nM(mask, accum)[rows, col_index] \u003c\u003c v        # assign column\nM(mask, accum)[row_index, cols] \u003c\u003c v        # assign row\nM(mask, accum)[rows, cols] \u003c\u003c s             # assign scalar to many elements\nM[row_index, col_index] \u003c\u003c s                # assign scalar to single element\n                                            # (mask and accum not allowed)\ndel M[row_index, col_index]                 # remove single element\n```\n\n## Apply\n\n```python\nM(mask, accum) \u003c\u003c A.apply(unaryop)\nM(mask, accum) \u003c\u003c A.apply(binaryop, left=s)   # bind-first\nM(mask, accum) \u003c\u003c A.apply(binaryop, right=s)  # bind-second\n```\n\n## Reduce\n\n```python\nv(mask, accum) \u003c\u003c A.reduce_rowwise(op)      # reduce row-wise\nv(mask, accum) \u003c\u003c A.reduce_columnwise(op)   # reduce column-wise\ns(accum) \u003c\u003c A.reduce_scalar(op)\ns(accum) \u003c\u003c v.reduce(op)\n```\n\n## Creating new Vectors / Matrices\n\n```python\nA = Matrix.new(dtype, num_rows, num_cols)   # new_type\nB = A.dup()                                 # dup\nA = Matrix.from_coo([row_indices], [col_indices], [values])  # build\n```\n\n## New from delayed\n\nDelayed objects can be used to create a new object using `.new()` method\n\n```python\nC = A.mxm(B, semiring).new()\n```\n\n## Properties\n\n```python\nsize = v.size                               # size\nnrows = M.nrows                             # nrows\nncols = M.ncols                             # ncols\nnvals = M.nvals                             # nvals\nrindices, cindices, vals = M.to_coo()       # extractTuples\n```\n\n## Initialization\n\nThere is a mechanism to initialize `graphblas` with a context prior to use. This allows for setting the backend to\nuse as well as the blocking/non-blocking mode. If the context is not initialized, a default initialization will\nbe performed automatically.\n\n```python\nimport graphblas as gb\n\n# Context initialization must happen before any other imports\ngb.init(\"suitesparse\", blocking=True)\n\n# Now we can import other items from graphblas\nfrom graphblas import binary, semiring\nfrom graphblas import Matrix, Vector, Scalar\n```\n\n## Performant User Defined Functions\n\nPython-graphblas requires `numba` which enables compiling user-defined Python functions to native C for use in GraphBLAS.\n\nExample customized UnaryOp:\n\n```python\nfrom graphblas import unary\n\ndef force_odd_func(x):\n    if x % 2 == 0:\n        return x + 1\n    return x\n\nunary.register_new(\"force_odd\", force_odd_func)\n\nv = Vector.from_coo([0, 1, 3], [1, 2, 3])\nw = v.apply(unary.force_odd).new()\nw  # indexes=[0, 1, 3], values=[1, 3, 3]\n```\n\nSimilar methods exist for BinaryOp, Monoid, and Semiring.\n\n## Relation to other network analysis libraries\n\nPython-graphblas aims to provide an efficient and consistent expression\nof graph operations using linear algebra. This allows the development of\nhigh-performance implementations of existing and new graph algorithms\n(also see [`graphblas-algorithms`](https://github.com/python-graphblas/graphblas-algorithms)).\n\nWhile end-to-end analysis can be done using `python-graphblas`, users\nmight find that other libraries in the Python ecosystem provide a more\nconvenient high-level interface for data pre-processing and transformation\n(e.g. `pandas`, `scipy.sparse`), visualization (e.g. `networkx`, `igraph`),\ninteractive exploration and analysis (e.g. `networkx`, `igraph`) or for\nalgorithms that are not (yet) implemented in `graphblas-algorithms` (e.g.\n`networkx`, `igraph`, `scipy.sparse.csgraph`). To facilitate communication with\nother libraries, `graphblas.io` contains multiple connectors, see the\nfollowing section.\n\n## Import/Export connectors to the Python ecosystem\n\n`graphblas.io` contains functions for converting to and from:\n\n```python\nimport graphblas as gb\n\n# scipy.sparse matrices\nA = gb.io.from_scipy_sparse(m)\nm = gb.io.to_scipy_sparse(m, format=\"csr\")\n\n# networkx graphs\nA = gb.io.from_networkx(g)\ng = gb.io.to_networkx(A)\n\n# numpy arrays can use `from_dense` and `to_dense` on Vector and Matrix\nv = gb.Vector.from_dense(m)\nm = v.to_dense()\n\nA = gb.Matrix.from_dense(m, missing_value=0)\nm = A.to_dense(fill_value=0)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-graphblas%2Fpython-graphblas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpython-graphblas%2Fpython-graphblas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-graphblas%2Fpython-graphblas/lists"}