# Graphs

> UStore for Python

`graph_write_edges`, `graph_remove_edges`, `graph_write_vertices` and `graph_remove_vertices` edit a graph collection, while `graph_read_edges` answers `Neighborhoods` and `graph_degrees` the degree of every vertex, with `None` where a vertex is absent.
An edge is a source, a target and an optional identifier, so distinct identifiers let a pair of vertices share several edges, and one without an identifier takes `ustore.edge_id_default`.
`ustore.graph_view.DiGraph` and `Graph` mirror NetworkX over these verbs and over document collections holding the attributes of vertices and edges.

`import ustore`

`from ustore import Neighborhoods`

## Role

The role a vertex plays in an edge, valued as `ustore_vertex_role_t`.

```python
class Role(IntEnum)
```

- `UNKNOWN` = `0`
- `SOURCE` = `1`
- `TARGET` = `2`
- `ANY` = `3`

## Neighborhoods

The edges one batch read found around its vertices, viewing its [`Arena`](https://www.unum.cloud/docs/ustore/python/batches-and-arenas.md#Arena) until it rewinds.

```python
class Neighborhoods
```

## __dlpack__

A DLPack capsule over the memory the buffer protocol exports, pinning the arena until its consumer deletes it, so `numpy.from_dlpack` reads it in place.

```python
def __dlpack__(
    *,
    stream: object | None = None,
    max_version: tuple[int, int] | None = None,
    dl_device: tuple[int, int] | None = None,
    copy: bool | None = None,
) -> object
```

## __dlpack_device__

The DLPack device of the arena: (1, 0) for host pages, (2, ordinal) for NVIDIA, (10, ordinal) for AMD.

```python
def __dlpack_device__() -> tuple[int, int]
```

## degrees

```python
degrees: tuple[int | None, ...]
```

## edge_id_default

```python
edge_id_default: UUID
```

