@@ -109,6 +109,50 @@ Here is a simple usage example:
109
109
result = db.aql.execute(' FOR s IN students RETURN s' )
110
110
print ([student[' name' ] for student in result])
111
111
112
+
113
+ Here is another example involving graphs:
114
+
115
+ .. code-block :: python
116
+
117
+ from arango import ArangoClient
118
+
119
+ client = ArangoClient()
120
+
121
+ # Create a new graph
122
+ graph = client.db(' my_database' ).create_graph(' my_graph' )
123
+ students = graph.create_vertex_collection(' students' )
124
+ courses = graph.create_vertex_collection(' courses' )
125
+ takes = graph.create_edge_definition(
126
+ name = ' takes' ,
127
+ from_collections = [' students' ],
128
+ to_collections = [' courses' ]
129
+ )
130
+
131
+ # Insert vertices
132
+ students.insert({' _key' : ' 01' , ' full_name' : ' Anna Smith' })
133
+ students.insert({' _key' : ' 02' , ' full_name' : ' Jake Clark' })
134
+ students.insert({' _key' : ' 03' , ' full_name' : ' Lisa Jones' })
135
+
136
+ courses.insert({' _key' : ' MAT101' , ' title' : ' Calculus' })
137
+ courses.insert({' _key' : ' STA101' , ' title' : ' Statistics' })
138
+ courses.insert({' _key' : ' CSC101' , ' title' : ' Algorithms' })
139
+
140
+ # Insert edges
141
+ takes.insert({' _from' : ' students/01' , ' _to' : ' courses/MAT101' })
142
+ takes.insert({' _from' : ' students/01' , ' _to' : ' courses/STA101' })
143
+ takes.insert({' _from' : ' students/01' , ' _to' : ' courses/CSC101' })
144
+ takes.insert({' _from' : ' students/02' , ' _to' : ' courses/MAT101' })
145
+ takes.insert({' _from' : ' students/02' , ' _to' : ' courses/STA101' })
146
+ takes.insert({' _from' : ' students/03' , ' _to' : ' courses/CSC101' })
147
+
148
+ # Traverse the graph in outbound direction, breath-first
149
+ traversal_results = graph.traverse(
150
+ start_vertex = ' students/01' ,
151
+ strategy = ' bfs' ,
152
+ direction = ' outbound'
153
+ )
154
+ print (traversal_results[' vertices' ])
155
+
112
156
Please read the full `API documentation `_ for more details!
113
157
114
158
.. _API documentation :
0 commit comments