Skip to content

Commit a785969

Browse files
authored
Merge pull request #159 from bucanero/master
docs(fix): add setup reference to grpcio v1.19.0 package
2 parents f66a613 + e8431be commit a785969

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

README.md

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# pydgraph
22

3-
Official Dgraph client implementation for Python (Python >= v2.7 and >= v3.5),
4-
using [grpc].
3+
Official Dgraph client implementation for Python (Python >= v2.7 and >= v3.5), using [gRPC][grpc].
54

65
[grpc]: https://grpc.io/
76

@@ -44,6 +43,14 @@ Install using pip:
4443
pip install pydgraph
4544
```
4645

46+
### Install Notes
47+
48+
To avoid issues when adding composite credentials or when using client authorization, please install gRPC version 1.19.0:
49+
50+
```sh
51+
pip install grpcio==1.19.0
52+
```
53+
4754
## Supported Versions
4855

4956
Depending on the version of Dgraph that you are connecting to, you will have to
@@ -57,9 +64,9 @@ use a different version of this client.
5764

5865
## Quickstart
5966

60-
Build and run the [simple][] project in the `examples` folder, which
61-
contains an end-to-end example of using the Dgraph python client. Follow the
62-
instructions in the README of that project.
67+
Build and run the [simple project][simple] in the `examples` folder, which
68+
contains an end-to-end example of using the Dgraph python client. For additional details, follow the
69+
instructions in the project's [README](./examples/simple/README.md).
6370

6471
[simple]: ./examples/simple
6572

@@ -91,8 +98,8 @@ op = pydgraph.Operation(schema=schema)
9198
client.alter(op)
9299
```
93100

94-
Starting Dgraph version 20.03.0, indexes can be computed in the background.
95-
You can set `run_in_background` field of the `pydgraph.Operation` to `True`
101+
Starting with Dgraph version 20.03.0, indexes can be computed in the background.
102+
You can set the `run_in_background` field of `pydgraph.Operation` to `True`
96103
before passing it to the `Alter` function. You can find more details
97104
[here](https://docs.dgraph.io/master/query-language/#indexes-in-background).
98105

@@ -102,8 +109,8 @@ op = pydgraph.Operation(schema=schema, run_in_background=True)
102109
client.alter(op)
103110
```
104111

105-
`Operation` contains other fields as well, including drop predicate and drop all.
106-
Drop all is useful if you wish to discard all the data, and start from a clean
112+
`Operation` contains other fields as well, including the `drop` predicate and `drop all`.
113+
Drop all is useful if you wish to discard all the data, and start with a clean
107114
slate, without bringing the instance down.
108115

109116
```python
@@ -115,7 +122,7 @@ client.alter(op)
115122

116123
### Creating a Transaction
117124

118-
To create a transaction, call `DgraphClient#txn()` method, which returns a
125+
To create a transaction, call the `DgraphClient#txn()` method, which returns a
119126
new `Txn` object. This operation incurs no network overhead.
120127

121128
It is good practice to call `Txn#discard()` in a `finally` block after running
@@ -202,7 +209,7 @@ txn.mutate(del_obj=person)
202209
```
203210

204211
For a complete example with multiple fields and relationships, look at the
205-
[simple] project in the `examples` folder.
212+
[simple project][simple] in the `examples` folder.
206213

207214
Sometimes, you only want to commit a mutation, without querying anything further.
208215
In such cases, you can set the keyword argument `commit_now=True` to indicate
@@ -219,7 +226,7 @@ txn.do_request(request)
219226
### Committing a Transaction
220227

221228
A transaction can be committed using the `Txn#commit()` method. If your transaction
222-
consisted solely of calls to `Txn#query` or `Txn#queryWithVars`, and no calls to
229+
consist solely of `Txn#query` or `Txn#queryWithVars` calls, and no calls to
223230
`Txn#mutate`, then calling `Txn#commit()` is not necessary.
224231

225232
An error is raised if another transaction(s) modify the same data concurrently that was
@@ -245,11 +252,11 @@ finally:
245252
### Running a Query
246253

247254
You can run a query by calling `Txn#query(string)`. You will need to pass in a
248-
GraphQL+- query string. If you want to pass an additional dictionary of any
255+
[DQL](https://dgraph.io/docs/query-language/) query string. If you want to pass an additional dictionary of any
249256
variables that you might want to set in the query, call
250257
`Txn#query(string, variables=d)` with the variables dictionary `d`.
251258

252-
The response would contain the field `json`, which returns the response JSON.
259+
The query response contains the `json` field, which returns the JSON response.
253260

254261
Let’s run a query with a variable `$a`, deserialize the result from JSON and
255262
print it out:
@@ -296,8 +303,7 @@ txn.do_request(request)
296303
The `txn.do_request` function allows you to run upserts consisting of one query and
297304
one mutation. Query variables could be defined and can then be used in the mutation.
298305

299-
To know more about upsert, we highly recommend going through the docs at
300-
https://docs.dgraph.io/mutations/#upsert-block.
306+
To know more about upsert, we highly recommend going through the [mutations docs](https://docs.dgraph.io/mutations/#upsert-block).
301307

302308
```python
303309
query = """{
@@ -317,7 +323,7 @@ txn.do_request(request)
317323
The upsert block also allows specifying a conditional mutation block using an `@if` directive. The mutation is executed
318324
only when the specified condition is true. If the condition is false, the mutation is silently ignored.
319325

320-
See more about Conditional Upsert [Here](https://docs.dgraph.io/mutations/#conditional-upsert).
326+
See more about Conditional Upserts [here](https://docs.dgraph.io/mutations/#conditional-upsert).
321327

322328
```python
323329
query = """
@@ -359,7 +365,9 @@ stub2.close()
359365
```
360366

361367
### Setting Metadata Headers
368+
362369
Metadata headers such as authentication tokens can be set through the metadata of gRPC methods. Below is an example of how to set a header named "auth-token".
370+
363371
```python
364372
# The following piece of code shows how one can set metadata with
365373
# auth-token, to allow Alter operation, if the server requires it.
@@ -368,7 +376,7 @@ metadata = [("auth-token", "the-auth-token-value")]
368376
dg.alter(op, metadata=metadata)
369377
```
370378

371-
### Setting a timeout.
379+
### Setting a timeout
372380

373381
A timeout value representing the number of seconds can be passed to the `login`,
374382
`alter`, `query`, and `mutate` methods using the `timeout` keyword argument.
@@ -389,7 +397,7 @@ every request will need to include the credentials. In the example below, we are
389397
trying to add authentication to a proxy that requires an API key. This value is
390398
expected to be included in the metadata using the key "authorization".
391399

392-
```
400+
```python
393401
creds = grpc.ssl_channel_credentials()
394402
call_credentials = grpc.metadata_call_credentials(
395403
lambda context, callback: callback((("authorization", "<api-key>"),), None))
@@ -399,14 +407,14 @@ client_stub = pydgraph.DgraphClientStub(
399407
client = pydgraph.DgraphClient(client_stub)
400408
```
401409

402-
### Async methods.
410+
### Async methods
403411

404412
The `alter` method in the client has an asyncronous version called
405413
`async_alter`. The async methods return a future. You can directly call the
406414
`result` method on the future. However. The DgraphClient class provides a static
407415
method `handle_alter_future` to handle any possible exception.
408416

409-
```
417+
```python
410418
alter_future = self.client.async_alter(pydgraph.Operation(
411419
schema="name: string @index(term) ."))
412420
response = pydgraph.DgraphClient.handle_alter_future(alter_future)
@@ -419,7 +427,7 @@ just like `async_alter`.
419427
You can use the `handle_query_future` and `handle_mutate_future` static methods
420428
in the `Txn` class to retrieve the result. A short example is given below:
421429

422-
```
430+
```python
423431
txn = client.txn()
424432
query = "query body here"
425433
future = txn.async_query()
@@ -473,23 +481,23 @@ python scripts/protogen.py
473481
The generated file `api_pb2_grpc.py` needs to be changed in recent versions of python.
474482
The required change is outlined below as a diff.
475483

476-
```
484+
```diff
477485
-import api_pb2 as api__pb2
478486
+from . import api_pb2 as api__pb2
479487
```
480488

481489
### Running tests
482490

483491
To run the tests in your local machine, you can run the script
484-
`scripts/local-tests.sh`. This script assumes Dgraph and dgo (Go client) are
492+
`scripts/local-tests.sh`. This script assumes Dgraph and [dgo](https://github.com/dgraph-io/dgo) (Go client) are
485493
already built on the local machine and that their code is in `$GOPATH/src`.
486494
It also requires that docker and docker-compose are installed in your machine.
487495

488496
The script will take care of bringing up a Dgraph cluster and bringing it down
489-
after the tests are executed. The script uses the port 9180 by default to
497+
after the tests are executed. The script uses the port `9180` by default to
490498
prevent interference with clusters running on the default port. Docker and
491499
docker-compose need to be installed before running the script. Refer to the
492-
official Docker documentation for instructions on how to install those packages.
500+
official [Docker documentation](https://docs.docker.com/) for instructions on how to install those packages.
493501

494502
The `test.sh` script downloads and installs Dgraph. It is meant for use by our
495503
CI systems and using it for local development is not recommended.

0 commit comments

Comments
 (0)