Skip to content

Graph Collections #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jun 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4e6231b
Highlighting boolean values
apetenchea May 24, 2025
ba45028
Adding vertex and edge collection skeleton
apetenchea May 24, 2025
9dc1353
Refactoring serializers
apetenchea May 24, 2025
128d328
Using randomized graph name
apetenchea May 24, 2025
7a09541
Improving helper types
apetenchea May 24, 2025
6ea9259
Facilitating edge and vertex collection creation
apetenchea May 24, 2025
526b135
Vertex collection management
apetenchea May 24, 2025
9ccbe69
Edge collection management
apetenchea May 24, 2025
aa7f0c5
Adding cluster testcase
apetenchea May 24, 2025
a7dd6b2
Adding note about dictionary-like indexing
apetenchea May 29, 2025
d676262
Inserting and retrieving vertex documents
apetenchea May 29, 2025
0cf44f7
Moving methods from StandardCollection to base Collection so they are…
apetenchea May 29, 2025
d969ce6
Adding CRUD for vertex collections
apetenchea May 29, 2025
e56929e
Adding "has" for vertex collections
apetenchea May 29, 2025
d3b45af
Marking tests as asyncio
apetenchea May 29, 2025
d1fabd4
Inserting and retrieving edges
apetenchea May 29, 2025
5662f37
Event loop scope
apetenchea May 29, 2025
3eed2b2
Event loop scope again
apetenchea May 29, 2025
a5c6278
Updating edge
apetenchea May 29, 2025
5e4c0b4
Edges CRUD
apetenchea May 29, 2025
00eaf49
Extra edge methods
apetenchea Jun 1, 2025
3e8530c
Fixing lint
apetenchea Jun 1, 2025
2cb36a3
Added github gist example
apetenchea Jun 1, 2025
dcebf8e
Adding graph docs
apetenchea Jun 1, 2025
081eb7f
Adding graphs example in the readme
apetenchea Jun 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,67 @@ async def main():
student_names = []
async for doc in cursor:
student_names.append(doc["name"])
```

Another example with [graphs](https://docs.arangodb.com/stable/graphs/):

```python
async def main():
from arangoasync import ArangoClient
from arangoasync.auth import Auth

# Initialize the client for ArangoDB.
async with ArangoClient(hosts="http://localhost:8529") as client:
auth = Auth(username="root", password="passwd")

# Connect to "test" database as root user.
db = await client.db("test", auth=auth)

# Get the API wrapper for graph "school".
if await db.has_graph("school"):
graph = db.graph("school")
else:
graph = await db.create_graph("school")

# Create vertex collections for the graph.
students = await graph.create_vertex_collection("students")
lectures = await graph.create_vertex_collection("lectures")

# Create an edge definition (relation) for the graph.
edges = await graph.create_edge_definition(
edge_collection="register",
from_vertex_collections=["students"],
to_vertex_collections=["lectures"]
)

# Insert vertex documents into "students" (from) vertex collection.
await students.insert({"_key": "01", "full_name": "Anna Smith"})
await students.insert({"_key": "02", "full_name": "Jake Clark"})
await students.insert({"_key": "03", "full_name": "Lisa Jones"})

# Insert vertex documents into "lectures" (to) vertex collection.
await lectures.insert({"_key": "MAT101", "title": "Calculus"})
await lectures.insert({"_key": "STA101", "title": "Statistics"})
await lectures.insert({"_key": "CSC101", "title": "Algorithms"})

# Insert edge documents into "register" edge collection.
await edges.insert({"_from": "students/01", "_to": "lectures/MAT101"})
await edges.insert({"_from": "students/01", "_to": "lectures/STA101"})
await edges.insert({"_from": "students/01", "_to": "lectures/CSC101"})
await edges.insert({"_from": "students/02", "_to": "lectures/MAT101"})
await edges.insert({"_from": "students/02", "_to": "lectures/STA101"})
await edges.insert({"_from": "students/03", "_to": "lectures/CSC101"})

# Traverse the graph in outbound direction, breath-first.
query = """
FOR v, e, p IN 1..3 OUTBOUND 'students/01' GRAPH 'school'
OPTIONS { bfs: true, uniqueVertices: 'global' }
RETURN {vertex: v, edge: e, path: p}
"""

async with await db.aql.execute(query) as cursor:
async for doc in cursor:
print(doc)
```

Please see the [documentation](https://python-arango-async.readthedocs.io/en/latest/) for more details.
Loading
Loading