You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Create `accountName` and `accountKey`string variables. Store the `COSMOS_GREMLIN_ENDPOINT` and `COSMOS_GREMLIN_KEY` environment variables as the values for each respective variable.
128
+
1. Create `accountName` and `accountKey` variables. Store the `COSMOS_GREMLIN_ENDPOINT` and `COSMOS_GREMLIN_KEY` environment variables as the values for each respective variable.
Copy file name to clipboardExpand all lines: articles/cosmos-db/gremlin/quickstart-python.md
+157-1Lines changed: 157 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,21 +37,177 @@ In this quickstart, you use the `gremlinpython` library to connect to a newly cr
37
37
38
38
## Setting up
39
39
40
-
This section walks you through creating an API for Gremlin account and setting up a .NET project to use the library to connect to the account.
40
+
This section walks you through creating an API for Gremlin account and setting up a Python project to use the library to connect to the account.
41
41
42
42
### Create an API for Gremlin account
43
43
44
44
The API for Gremlin account should be created prior to using the Python library. Additionally, it helps to also have the database and graph in place.
45
45
46
46
[!INCLUDE[Create account, database, and graph](includes/create-account-database-graph-cli.md)]
47
47
48
+
### Create a new Python console application
48
49
50
+
Create a Python console application in an empty folder using your preferred terminal.
49
51
52
+
1. Open your terminal in an empty folder.
50
53
54
+
1. Create the **app.py** file.
51
55
56
+
```bash
57
+
touch app.py
58
+
```
52
59
60
+
### Install the PyPI package
53
61
62
+
Add the `gremlinpython` PyPI package to the Python project.
54
63
64
+
1. Create the **requirements.txt** file.
65
+
66
+
```bash
67
+
touch requirements.txt
68
+
```
69
+
70
+
1. Add the `gremlinpython` package from the Python Package Index to the requirements file.
71
+
72
+
```requirements
73
+
gremlinpython==3.7.0
74
+
```
75
+
76
+
1. Install all the requirements to your project.
77
+
78
+
```bash
79
+
python install -r requirements.txt
80
+
```
81
+
82
+
### Configure environment variables
83
+
84
+
To use the *NAME* and *URI* values obtained earlier in this quickstart, persist them to new environment variables on the local machine running the application.
85
+
86
+
1. To set the environment variable, use your terminal to persist the values as `COSMOS_ENDPOINT` and `COSMOS_KEY` respectively.
87
+
88
+
```bash
89
+
export COSMOS_GREMLIN_ENDPOINT="<account-name>"
90
+
export COSMOS_GREMLIN_KEY="<account-key>"
91
+
```
92
+
93
+
1. Validate that the environment variables were set correctly.
94
+
95
+
```bash
96
+
printenv COSMOS_GREMLIN_ENDPOINT
97
+
printenv COSMOS_GREMLIN_KEY
98
+
```
99
+
100
+
## Code examples
101
+
102
+
- [Authenticate the client](#authenticate-the-client)
103
+
- [Create vertices](#create-vertices)
104
+
- [Create edges](#create-edges)
105
+
- [Query vertices & edges](#query-vertices--edges)
106
+
107
+
The code in this article connects to a database named `cosmicworks` and a graph named `products`. The code then adds vertices and edges to the graph before traversing the added items.
108
+
109
+
### Authenticate the client
110
+
111
+
Application requests to most Azure services must be authorized. For the API forGremlin, use the *NAME* and *URI* values obtained earlierin this quickstart.
112
+
113
+
1. Open the **app.py** file.
114
+
115
+
1. Import `client` and `serializer` from the `gremlin_python.driver` module.
1. Create `ACCOUNT_NAME` and `ACCOUNT_KEY` variables. Store the `COSMOS_GREMLIN_ENDPOINT` and `COSMOS_GREMLIN_KEY` environment variables as the values for each respective variable.
Validate that your application works as expected by running the application. The application should execute with no errors or warnings. The output of the application includes data about the created and queried items.
203
+
204
+
1. Open the terminal in the Python project folder.
205
+
206
+
1. Use `python <filename>` to run the application. Observe the output from the application.
0 commit comments