File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ __pycache__
2+ /env
3+ /.envrc
Original file line number Diff line number Diff line change 1- # example-graphql-python
1+ ## dfuse GraphQL Python Example
2+
23This simple program demonstrates how easy it is to query our GraphQL API over gRPC in Python. It:
34
45* Request a token from our authentication API
@@ -7,12 +8,34 @@ This simple program demonstrates how easy it is to query our GraphQL API over gR
78* Executes a simple GraphQL query
89* Prints the response
910
10- #### Running the example
11+ ### Requirements
12+
13+ You will need to have Python3 (>= 3.4+) as well as ` virtualenv ` and ` pip `
14+ ` >= 15.0+ ` .
15+
16+ We use a virtual environment for this example, all dependencies are listed
17+ in the ` requirements.txt ` at the root of this project.
18+
19+ #### Quickstart
20+
21+ First of all, visit [ https://app.dfuse.io ] ( https://app.dfuse.io ) to get
22+ a free API key for your project.
1123
12- First of all, visit [ https://app.dfuse.io ] ( https://app.dfuse.io ) to get ` YOUR_API_KEY ` .
24+ First, clone this repository to your work folder:
1325
14- ~~~ bash
26+ ``` bash
1527git clone https://github.com/dfuse-io/example-graphql-python.git
1628cd example-graphql-python
29+ ```
30+
31+ Setup the virtual environment and pull all dependencies:
32+
33+ ``` bash
34+ ./install_deps.sh
35+ ```
36+
37+ Once your environment is setup properly, simply run the ` example.py ` script:
38+
39+ ``` bash
1740python3 example.py YOUR_API_KEY_HERE
18- ~~~
41+ ```
Original file line number Diff line number Diff line change @@ -35,13 +35,13 @@ def stub():
3535
3636query = '''
3737subscription {
38- searchTransactionsForward(query: "status:executed ", limit: 10) {
38+ searchTransactionsForward(query: "account:eosio.token receiver:eosio.token action:transfer ", limit: 10) {
3939 trace {
4040 id
4141 matchingActions{
4242 account
4343 receiver
44- name
44+ name
4545 json
4646 }
4747 }
@@ -53,5 +53,9 @@ def stub():
5353stream = dfuse_graphql .Execute (Request (query = query ))
5454
5555for rawResult in stream :
56- result = json .loads (rawResult .data )
57- print (result ['searchTransactionsForward' ]['trace' ]['matchingActions' ])
56+ if rawResult .errors :
57+ print ("An error occurred" )
58+ print (rawResult .errors )
59+ else :
60+ result = json .loads (rawResult .data )
61+ print (result ['searchTransactionsForward' ]['trace' ]['matchingActions' ])
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ ROOT=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
4+
5+ main () {
6+ current_dir=" ` pwd` "
7+ trap " cd \" $current_dir \" " EXIT
8+ pushd " $ROOT " & > /dev/null
9+
10+ if [[ $1 == " --help" ]]; then
11+ usage
12+ exit 0
13+ fi
14+
15+ # Not Windows friendly, need to be adapted here to be Windows aware
16+ python3 -m venv env
17+ source env/bin/activate
18+ pip3 install -r requirements.txt
19+ }
20+
21+ usage () {
22+ echo " usage: install_deps"
23+ echo " "
24+ echo " Setup Python virtualenv environment and install all necessary"
25+ echo " dependencies for this project. Requires venv to be available"
26+ echo " in PATH and scripts expects a pip version '>= 15.0'."
27+ echo " "
28+ echo " Python3 is required also. No support for Python2 is provided"
29+ }
30+
31+ main $@
Original file line number Diff line number Diff line change 1+ ## The following requirements were added by pip freeze:
2+ grpcio == 1.22.0
3+ grpcio-tools == 1.22.0
4+ protobuf == 3.9.1
5+ six == 1.12.0
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ ROOT=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
4+
5+ main () {
6+ current_dir=" ` pwd` "
7+ trap " cd \" $current_dir \" " EXIT
8+ pushd " $ROOT " & > /dev/null
9+
10+ if [[ $1 == " --help" ]]; then
11+ usage
12+ exit 0
13+ fi
14+
15+ pip3 freeze -r requirements.txt > requirements.txt
16+ }
17+
18+ usage () {
19+ echo " usage: update_deps"
20+ echo " "
21+ echo " Freeze the actual dependencies and update the requirements.txt file"
22+ echo " used to store them."
23+ }
24+
25+ main $@
You can’t perform that action at this time.
0 commit comments