Metadata-Version: 2.4
Name: webgraph
Version: 0.1.3
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Dist: numpy
Summary: Python bindings for the Rust version of the WebGraph framework
Keywords: graph,compression,webgraph,bvgraph,succinct
Author-email: Sebastiano Vigna <sebastiano.vigna@unimi.it>, Dario Moschetti <dariomos.dm@gmail.com>
License-Expression: Apache-2.0 OR LGPL-2.1-or-later
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Bug Tracker, https://github.com/vigna/webgraph-py/issues
Project-URL: Changelog, https://github.com/vigna/webgraph-py/releases
Project-URL: Documentation, https://vigna.github.io/webgraph-py/webgraph.html
Project-URL: Repository, https://github.com/vigna/webgraph-py

# webgraph

Python bindings for the [Rust version](https://crates.io/crates/webgraph) of the
[WebGraph](https://webgraph.di.unimi.it/) framework, built with
[PyO3](https://pyo3.rs/).

WebGraph is a framework for graph compression that allows very large graphs
(billions of nodes and arcs) to be stored in a compact representation while
providing fast random access to successors.

## Installation

```bash
pip install webgraph
```

## Building from source

Pre-built wheels are compiled for a generic target. You should however enable native optimizations (e.g., BMI2 for faster succinct data structures) by building the wheel from source:

```bash
pip install maturin
git clone https://github.com/vigna/webgraph-py.git
cd webgraph-py/webgraph
maturin build --release -o dist
pip install dist/*.whl
```

The repository's `.cargo/config.toml` sets `target-cpu=native`, so the
resulting wheel will be optimized for your CPU.

## Quick start

```python
import webgraph

# Load a compressed graph
g = webgraph.BvGraph("/PATH/TO/BASENAME")

print(f"Nodes: {g.num_nodes()}, Arcs: {g.num_arcs()}")

# Iterate over successors
for s in g.successors(42):
    print(s)

# Degree computation (returns a numpy array)
degrees = g.outdegrees()

# Top-k nodes by degree (returns a (k, 2) ndarray: column 0 = node, column 1 = degree)
top = g.top_k_out(10)
print(top[:, 0])  # node IDs

# Breadth-first search
for root, parent, node, distance in g.bfs_from_node(0):
    print(f"node={node} distance={distance}")
```

