Edges

An edge is an entity that represents a connection between two documents. The main idea of edges is that you can build your own graph (tree) between sets of documents and then perform searches within the document hierarchy.

In order to define a vertex, from_document and to_document should be specified during the creation of the edge:

from arango import create

c = create()
c.test.create()

# create FROM document
from_doc = c.test.documents.create({
    "sample_key": "sample_value"
})

# create TO document
to_doc = c.test.documents.create({
    "sample_key1": "sample_value1"
})

# creating edge with custom data
c.test.edges.create(from_doc, to_doc, {"custom": 1})

Warning

Code below should be implemented by using AQL (AQL Queries). Not implemented at the moment.

# getting edge by document
# c.test.edges(from_doc)

# getting with direction
# c.test.edges(from_doc, direction="in")

# assert c.test.edges(from_doc).first.from_document == from_doc
# assert c.test.edges(from_doc).first.to_document == to_doc

Edges for Collection instance

Edges are accessible via a collection instance, for example connection.collection.sample_collection.edges. Usually this expressions looks lot shorter.

Basically via edges shortcut accessible Edges Proxy - Proxy object which have several shortcuts and produce Resultset object.

Below described basic method within Edges proxy:

class arango.edge.Edges(collection=None)

Proxy objects between Collection and Edge. Edges in general very related to Document.

create(*args, **kwargs)

Create new Edge

delete(ref)

Delete Edge by reference

update(ref, *args, **kwargs)

Update Edge by reference

Making queries

Warning

This functionality not implmented yet. Use AQL - AQL Queries section with custom wrapper to work with Edges.

More details in Edges REST Api documentation of ArangoDB

Edge

Edge instance methods consist from basic CRUD methods and additional methods specific obly for Edges:

class arango.edge.Edge(collection=None, _id=None, _rev=None, _from=None, _to=None, **kwargs)

Edge instance object

body

This property return Edge content

create(from_doc, to_doc, body=None, **kwargs)

Method to create new edge. from_doc and to_doc may be both document-handle or instances of Document object.

Possible arguments: waitForSync

Read more about additional arguments Edges REST Api

This method may raise EdgeAlreadyCreated exception in case edge already created.

Return edge instance (self) or None

delete()

Method to delete current edge. If edge deleted this method return True and in other case False

from_document

From vertex, return instance of Document or None

get(name=None, default=None)

This method very similar to dict‘s get method. The difference is that default value should be specified explicitly.

To get specific value for specific key in body use and default (fallback) value 0:

edge.get(name="sample_key", default=0)
id

Id of the Edge instance

rev

Revision of the Edge instance

save(**kwargs)

Method to save Edge. This is useful when edge udpated several times via update

Possible arguments: waitForSync

Read more about additional arguments Edges REST Api

to_document

To vertex, return instance of Document or None

update(body, from_doc=None, to_doc=None, save=True, **kwargs)

Method to update edge. In case from_doc or do_doc not specified or equal to None then current from_document and to_document will be used.

In case save argument set to False edge will not be updated until save() method will be called.

This method may raise EdgeNotYetCreated exception in case you trying to update edge which is not saved yet.

Exception EdgeIncompatibleDataType will be raised in case body of the edge isn’t dict.