{"id":24315,"library":"pydgraph","title":"pydgraph","description":"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.","status":"active","version":"25.2.0","language":"python","source_language":"en","source_url":"https://github.com/dgraph-io/pydgraph","tags":["graph","database","dgraph","grpc"],"install":[{"cmd":"pip install pydgraph","lang":"bash","label":"Latest version"},{"cmd":"pip install pydgraph==25.2.0","lang":"bash","label":"Pin specific version"}],"dependencies":[{"reason":"gRPC communication with Dgraph server","package":"grpcio","optional":false},{"reason":"Protocol Buffers for data serialization","package":"protobuf","optional":false}],"imports":[{"note":"Stub is a module, not a class; use stub.Stub or create client via dgraph_client","wrong":"from pydgraph import Stub","symbol":"Stub","correct":"from pydgraph import stub"},{"note":"Direct import from pydgraph is preferred and stable","wrong":"from pydgraph.client import DgraphClient","symbol":"DgraphClient","correct":"from pydgraph import DgraphClient"},{"note":"Direct import from pydgraph is stable","wrong":"from pydgraph.txn import Txn","symbol":"Txn","correct":"from pydgraph import Txn"}],"quickstart":{"code":"import pydgraph\n\n# Create a client stub\nclient_stub = pydgraph.DgraphClientStub('localhost:9080')\n# Create a client\nclient = pydgraph.DgraphClient(client_stub)\n\n# Set schema\nschema = 'name: string @index(exact) .'\nop = pydgraph.Operation(schema=schema)\nclient.alter(op)\n\n# Create a transaction and run a query\ntxn = client.txn(read_only=True)\nres = txn.query('{\"me\": function(func: eq(name, \"Alice\")) { name }}')\nprint(res.json)\ntxn.discard()\n\n# Close the stub\nclient_stub.close()","lang":"python","description":"Connect to a local Dgraph instance, set schema, query data."},"warnings":[{"fix":"Use `from pydgraph import DgraphClientStub` for the stub class.","message":"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.","severity":"gotcha","affected_versions":"all"},{"fix":"Always call `txn.discard()` in a finally block or use context manager (since v25.1.0).","message":"Transactions must be either committed or discarded; forgetting to discard a read-only transaction can lead to resource leaks.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `DgraphClientStub(api_endpoint)` directly or check cloud documentation.","message":"The `from_cloud` function (deprecated in v23.0.0) may not work with newer Dgraph Cloud endpoints; use `from_cloud` with caution.","severity":"gotcha","affected_versions":">=23.0.0"},{"fix":"Upgrade Dgraph server to v25.x or use an older pydgraph version (e.g., 24.3.0) with Dgraph v24.","message":"v25.0.0 updated to use Dgraph v25 API, which is incompatible with older Dgraph servers. Replaced RPC calls may cause connection failures.","severity":"breaking","affected_versions":">=25.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `pip install pydgraph` or activate the correct virtual environment.","cause":"pydgraph not installed or installed in a different Python environment.","error":"ModuleNotFoundError: No module named 'pydgraph'"},{"fix":"Use `from pydgraph import DgraphClient` (capital C, w).","cause":"Importing from wrong module; likely imported a submodule instead of the top-level package.","error":"AttributeError: module 'pydgraph' has no attribute 'DgraphClient'"},{"fix":"Start Dgraph server or check the endpoint address (default localhost:9080).","cause":"Dgraph server is not running or the host:port is incorrect.","error":"grpc.RpcError: ... UNAVAILABLE ... failed to connect to all addresses"},{"fix":"Use `DgraphClientStub('localhost:9080')` (string argument) or see docs for v25.","cause":"Incorrect usage of `DgraphClientStub` constructor; signature changed in newer versions.","error":"TypeError: __init__() got an unexpected keyword argument 'api_endpoint'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}