pydgraph
raw JSON → 25.2.0 verified Fri May 01 auth: no python
Official Python client for Dgraph, a distributed graph database. Version 25.2.0 supports Dgraph v25 API, requires Python >=3.9, and uses gRPC for communication. Release cadence is approximately quarterly.
pip install pydgraph Common errors
error ModuleNotFoundError: No module named 'pydgraph' ↓
cause pydgraph not installed or installed in a different Python environment.
fix
Run
pip install pydgraph or activate the correct virtual environment. error AttributeError: module 'pydgraph' has no attribute 'DgraphClient' ↓
cause Importing from wrong module; likely imported a submodule instead of the top-level package.
fix
Use
from pydgraph import DgraphClient (capital C, w). error grpc.RpcError: ... UNAVAILABLE ... failed to connect to all addresses ↓
cause Dgraph server is not running or the host:port is incorrect.
fix
Start Dgraph server or check the endpoint address (default localhost:9080).
error TypeError: __init__() got an unexpected keyword argument 'api_endpoint' ↓
cause Incorrect usage of `DgraphClientStub` constructor; signature changed in newer versions.
fix
Use
DgraphClientStub('localhost:9080') (string argument) or see docs for v25. Warnings
gotcha Using `from pydgraph import DgraphClientStub` is incorrect; the correct import is `from pydgraph import DgraphClientStub` (same) but note that `DgraphClientStub` is actually imported as `dgraph_client_stub` in some older docs. Actually the correct symbol is `DgraphClientStub` available directly. ↓
fix Use `from pydgraph import DgraphClientStub` for the stub class.
gotcha Transactions must be either committed or discarded; forgetting to discard a read-only transaction can lead to resource leaks. ↓
fix Always call `txn.discard()` in a finally block or use context manager (since v25.1.0).
gotcha The `from_cloud` function (deprecated in v23.0.0) may not work with newer Dgraph Cloud endpoints; use `from_cloud` with caution. ↓
fix Use `DgraphClientStub(api_endpoint)` directly or check cloud documentation.
breaking v25.0.0 updated to use Dgraph v25 API, which is incompatible with older Dgraph servers. Replaced RPC calls may cause connection failures. ↓
fix Upgrade Dgraph server to v25.x or use an older pydgraph version (e.g., 24.3.0) with Dgraph v24.
Install
pip install pydgraph==25.2.0 Imports
- Stub wrong
from pydgraph import Stubcorrectfrom pydgraph import stub - DgraphClient wrong
from pydgraph.client import DgraphClientcorrectfrom pydgraph import DgraphClient - Txn wrong
from pydgraph.txn import Txncorrectfrom pydgraph import Txn
Quickstart
import pydgraph
# Create a client stub
client_stub = pydgraph.DgraphClientStub('localhost:9080')
# Create a client
client = pydgraph.DgraphClient(client_stub)
# Set schema
schema = 'name: string @index(exact) .'
op = pydgraph.Operation(schema=schema)
client.alter(op)
# Create a transaction and run a query
txn = client.txn(read_only=True)
res = txn.query('{"me": function(func: eq(name, "Alice")) { name }}')
print(res.json)
txn.discard()
# Close the stub
client_stub.close()