@@ -8,15 +8,15 @@ Driver for ArangoDB REST API
88
99python-arango is a driver for ArangoDB (https://www.arangodb.com/ ) REST API
1010
11- ## Installation (will be in PyPi soon)
11+ ## Installation (will also be in PyPi soon)
1212
1313``` bash
1414git clone https://github.com/Joowani/python-arango.git
1515cd python-arango
1616python2.7 setup.py install
1717```
1818
19- ## Initializing ArangoDB Connection
19+ ## Initializing Connection
2020``` python
2121from arango import Arango
2222
@@ -42,13 +42,16 @@ a.db("dbXX").is_system
4242## AQL Functions
4343``` python
4444my_db = a.db(" my_db" )
45- # List the AQL functions that's defined in databse "my_db"
45+
46+ # List the AQL functions that's defined in database "my_db"
4647my_db.aql_functions
48+
4749# Add a new AQL function
4850my_db.add_aql_function(
4951 " myfunctions::temperature::ctof" ,
5052 " function (celsius) { return celsius * 1.8 + 32; }"
5153)
54+
5255# Remove a AQL function
5356my_db.remove_aql_function(" myfunctions::temperature::ctof" )
5457```
@@ -57,8 +60,10 @@ my_db.remove_aql_function("myfunctions::temperature::ctof")
5760``` python
5861# Retrieve the execution plan without executing it
5962my_db.explain_query(" FOR doc IN my_col doc" )
63+
6064# Validate the AQL query without executing it
6165my_db.validate_query(" FOR doc IN my_col doc" )
66+
6267# Execute the AQL query and iterate through the AQL cursor
6368cursor = my_db.execute_query(
6469 " FOR d IN my_col FILTER d.value == @val RETURN d" ,
@@ -71,14 +76,19 @@ for doc in cursor: # the cursor is deleted when the generator is exhausted
7176## Collections
7277``` python
7378my_db = a.db(" my_db" )
79+
7480# List the collection names in "my_db"
7581my_db.collections
82+
7683# Add a new collection
7784my_db.add_collection(" new_col" )
85+
7886# Add a new edge collection
7987my_db.add_collection(" new_ecol" , is_edge = True )
88+
8089# Rename a collection
8190my_db.rename_collection(" new_col" , " my_col" )
91+
8292# Remove a collection from the database
8393my_db.remove_collection(" my_col" )
8494
@@ -99,21 +109,25 @@ my_col.revision
99109
100110# Load the collection into memory
101111my_col.load()
112+
102113# Unload the collection from memory
103114my_col.unload()
115+
104116# Rotate the collection journal
105117my_col.rotate_journal()
118+
106119# Return the checksum of the collection
107120my_col.checksum()
121+
108122# Remove all documents in the collection
109123my_col.truncate()
124+
110125# Check if a document exists in the collection
111126my_col.contains(" a_document_key" )
112127" a_document_key" in my_col
113128```
114129
115130## Indexes
116-
117131``` python
118132my_col = a.collection(" my_col" )
119133
@@ -138,68 +152,114 @@ my_col.add_fulltext_index(fields=["attr1"], min_length=10)
138152```
139153
140154## Documents
141-
142155``` python
143- # Managing documents in a particular collection
144156my_col = a.db(" my_db" ).collection(" my_col" )
157+
158+ # Retrieve a document by its key
145159my_col.get_document(" doc01" )
160+
161+ # Add a new document ("_key" attribute is optional)
146162my_col.add_document({" _key" : " doc01" , " value" : 1 })
163+
164+ # Replace a document
147165my_col.replace_document(" doc01" , {" value" : 2 })
166+
167+ # Update a document
148168my_col.update_document(" doc01" , {" another_value" : 3 })
169+
170+ # Remove a document
149171my_col.remove_document(" doc01" )
172+
173+ # Iterate through the documents in a collection and update them
150174for doc in my_col:
151175 new_value = doc[" value" ] + 1
152176 my_col.update_document(doc[" _key" ], {" new_value" : new_value})
153177```
154178
155- # Simple collection-specific queries
156- my_col.first(5) # return the first 5 documents
157- my_col.last(3) # return the last 3 documents
158- my_col.all() # return all documents (generator object)
159- my_col.any() # return a random document
160- my_col.get_first_example({"value": 1}) # return first document whose "value" is 1
161- my_col.get_by_example({"value": 1}) # return all documents whose "value" is 1
162- my_col.update_by_example( # update all documents whose "value" is 1 with the new value
179+ ## Simple (Collection-Specific) Queries
180+ ``` python
181+ # Return the first 5 documents in collection "my_col"
182+ my_col.first(5 )
183+
184+ # Return the last 3 documents
185+ my_col.last(3 )
186+
187+ # Return all documents (cursor generator object)
188+ my_col.all()
189+
190+ # Return a random document
191+ my_col.any()
192+
193+ # Return first document whose "value" is 1
194+ my_col.get_first_example({" value" : 1 })
195+
196+ # Return all documents whose "value" is 1
197+ my_col.get_by_example({" value" : 1 })
198+
199+ # Update all documents whose "value" is 1 with a new attribute
200+ my_col.update_by_example(
163201 {" value" : 1 },
164202 new_value = {" new_attr" : 1 }
165203)
166- my_col.within(latitude=100, longitude=20, radius=15) # return all docs within (requires geo-index)
167- my_col.near(latitude=100, longitude=20, radius=15) # return all docs near (requires geo-index)
168204
169- # Managing Graphs
205+ # Return all docs within a radius around a given coordinate (requires geo-index)
206+ my_col.within(latitude = 100 , longitude = 20 , radius = 15 )
207+
208+ # Return all documents near a given coordinate (requires geo-index)
209+ my_col.near(latitude = 100 , longitude = 20 )
210+ ```
211+
212+ ## Graphs
213+ ``` python
170214my_db = a.db(" my_db" )
171- my_db.graphs # list all the graphs in the database
215+ # List all the graphs in the database
216+ my_db.graphs
217+ # Add a new graph
172218my_graph = my_db.add_graph(" my_graph" )
173219
174- # Adding vertex collections to a graph
220+ # Add new vertex collections to a graph
175221my_db.add_collection(" vcol01" )
176222my_db.add_collection(" vcol02" )
177223my_graph.add_vertex_collection(" vcol01" )
178224my_graph.add_vertex_collection(" vcol02" )
179225
180- # Adding an edge definition to a graph
226+ # Add a new edge definition to a graph
181227my_db.add_collection(" ecol01" , is_edge = True )
182228my_graph.add_edge_definition(
183229 edge_collection = " ecol01" ,
184230 from_vertex_collections = [" vcol01" ],
185231 to_vertex_collections = [" vcol02" ],
186232)
187- # Retrieving information from a graph
233+
234+ # Retrieve graph information
188235my_graph.properties
189236my_graph.id
190237my_graph.revision
191238my_graph.edge_definitions
192239my_graph.vertex_collections
193240my_graph.orphan_collections
241+ ```
242+
194243
195- # Managing vertices (needs valid vertex collections)
244+ ## Vertice
245+ ``` python
246+ # Add new vertices
196247my_graph.add_vertex(" vcol01" , {" _key" : " v01" , " value" : 1 })
197248my_graph.add_vertex(" vcol02" , {" _key" : " v01" , " value" : 1 })
249+
250+ # Replace a vertex
198251my_graph.replace_vertex(" vol01/v01" , {" value" : 2 })
252+
253+ # Update a vertex
199254my_graph.update_vertex(" vol02/v01" , {" new_value" : 3 })
255+
256+ # Remove a vertex
200257my_graph.remove_vertex(" vol01/v01" )
258+ ```
201259
202- # Managing edges (needs valid vertex and edge collections)
260+ ## Edges
261+ ``` python
262+ # Add a new edge
203263my_graph.add_edge(
204264 " ecol01" ,
205265 {
@@ -209,20 +269,38 @@ my_graph.add_edge(
209269 " value" : 1 ,
210270 }
211271)
272+
273+ # Replace an edge
212274my_graph.replace_edge(" ecol01/e01" , {" new_value" : 2 })
275+
276+ # Update an edge
213277my_graph.update_edge(" ecol01/e01" , {" value" : 3 })
278+
279+ # Remove an edge
214280my_graph.remove_edge(" ecol01/e01" )
281+ ```
215282
216- # Graph traversals
283+ ## Traversals
284+ ``` python
285+ # Execute a graph traversal
217286results = my_graph.execute_traversal(
218287 start_vertex = " vcol01/v01" ,
219288 direction = " outbound" ,
220289 strategy = " depthfirst"
221290)
291+
292+ # Get the visited nodes in order
222293results.get(" visited" )
294+
295+ # Get the paths traversed
223296results.get(" paths" )
297+ ```
298+
299+ ## Batch Requests
300+ ``` python
301+ # NOTE : only (add/update/replace/remove) methods (documents/vertices/edges) are supported at the moment
224302
225- # Batch Requests (only add, update, replace and remove methods are supported atm)
303+ # Execute a batch documents request
226304my_db.execute_batch([
227305 (
228306 my_col.add_document, # method name
@@ -251,6 +329,7 @@ my_db.execute_batch([
251329 ),
252330])
253331
332+ # Execute a batch vertex requests
254333self .db.execute_batch([
255334 (
256335 my_graph.add_vertex,
@@ -268,8 +347,6 @@ self.db.execute_batch([
268347 {" wait_for_sync" : True }
269348 ),
270349])
271-
272-
273350```
274351
275352## Running System Tests (requires ArangoDB on localhost)
0 commit comments