cancel
Showing results for 
Search instead for 
Did you mean: 

Neo4j Bolt driver for Python : Re-using just 1 SESSION vs. starting/destroying sessions as needed

julian
Node Link

I have a wrapper class to provide convenience and extra functionality around the standard Neo4j Bolt driver for Python... My main dilemma is how to best handle sessions.

A simple approach is to just start a new session when this class is instantiated, then save it as an object attribute, and just re-use as needed... As simple as it gets!

~
And yet, the Neo4j Python Driver 4.2 API Documentation says:

a session should generally be short-lived... In general, sessions will be created and destroyed within a with context

~
On a similar note, The session API - Neo4j Driver Manual says

In languages that support them, simple sessions are usually scoped within a context block; this ensures that they are properly closed and that any underlying connections are released and not leaked.

~
However, it'd seem that the simple approach of doing everything within the same 1 session, also prevents any danger of leaking sessions!
~
On this forum, I found Best way to use Neo4J driver sessions , but it doesn't really answer my question. It only provided a case report:

The most common way I've seen is to have one session for reads and another for writes

~
I'd love to hear about pros and cons...
I'd love to hear about best practices...
~
I presume the best approach may depend on single vs. multiple nodes... and on the amount of concurrent traffic ?
Thanks!

0 REPLIES 0
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.