You are currently browsing legacy 3.5 version of documentation. Click here to switch to the newest 5.1 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Session: Opening a session

To open synchronous session use open_session method from documentstore.


# Open session for a 'default' database configured in 'documentstore'
with store.open_session() as session:
    # code here

# Open session for a specific database
with store.open_session(database="Your database") as session:
    # code here

# Open session for a specific database with api_key
with store.open_session(database="Your database", api_key="API_KEY") as session:
    # code here
database str The name of the database (default value is None)
api_key str The api_key for the database (default value is None)
force_read_from_master bool If set to true force the database to always read from primary database in replication (default value is False)
Return Value
documentsession Implements Unit of Work for accessing the RavenDB server


with statement can be used when open a session