This example would not work as query and mutation need to be separate operations.
There is a pending PR for pydgraph at Add Dgraph v1 support and make the interface compatible with other clients by gpahal · Pull Request #21 · dgraph-io/pydgraph · GitHub which should be merged soon by @gpahal. The PR would also add examples.