Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions src/content/docs/client-apis/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ The following features are not yet supported in the async API:

</Tabs>

## Output utilities

The Python API provides some utilities to process query results.

```py
# Get all rows as a list of tuples
print(response.get_all())

# Change the output format to a dictionary, where the keys are the column names
print(response.rows_as_dict().get_all())

# Get the first 2 rows as a list of tuples
print(response.get_n(2))

# Get the next row as a tuple
if response.has_next():
print(response.get_next())

# Get all rows as a list of tuples
print(list(response))
```

## Run multiple queries in one execution

By default, executing a single query in the Python API will return a `QueryResult` object. However,
Expand Down
22 changes: 22 additions & 0 deletions src/content/docs/get-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ Result:
The approach shown above returned a list of lists containing query results. See below for more
output options for Python.

**Output as a dictionary**

You can also get the results of a Cypher query as a dictionary.

```py
response = conn.execute(
"""
MATCH (a:User)-[f:Follows]->(b:User)
RETURN a.name, b.name, f.since;
"""
)
for row in response.rows_as_dict():
print(row)
```

```bash
{'a.name': 'Adam', 'b.name': 'Karissa', 'f.since': 2020}
{'a.name': 'Adam', 'b.name': 'Zhang', 'f.since': 2020}
{'a.name': 'Karissa', 'b.name': 'Zhang', 'f.since': 2021}
{'a.name': 'Zhang', 'b.name': 'Noura', 'f.since': 2022}
```

**Pandas**

You can also pass the results of a Cypher query to a [Pandas](https://pandas.pydata.org/) DataFrame
Expand Down
20 changes: 8 additions & 12 deletions src/content/docs/tutorials/python/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ Finally, we can print out a list of tables:
```py
result = conn.execute("CALL SHOW_TABLES() RETURN *")

print(result.get_column_names())
while result.has_next():
print(result.get_next())
for row in result:
print(row)
```

### Running the code
Expand Down Expand Up @@ -178,9 +177,8 @@ def main() -> None:
# Query to be filled out below
result = conn.execute(...)

print(result.get_column_names())
while result.has_next():
print(result.get_next())
for row in result:
print(row)

if __name__ == "__main__":
main()
Expand Down Expand Up @@ -385,9 +383,8 @@ def main() -> None:

result = conn.execute("CALL SHOW_TABLES() RETURN *")

print(result.get_column_names())
while result.has_next():
print(result.get_next())
for row in result:
print(row)

if __name__ == "__main__":
main()
Expand All @@ -407,9 +404,8 @@ def main() -> None:
# Query to be filled out below
result = conn.execute(...)

print(result.get_column_names())
while result.has_next():
print(result.get_next())
for row in result:
print(row)

if __name__ == "__main__":
main()
Expand Down