Package: pyravendb-embedded
OverviewPyravendb-Embedded is a RavenDB  package for running RavenDB in embedded mode.EmbeddedServer().start_server()withEmbeddedServer().get_document_store("Embedded")asstore:withstore.open_session()assession:session.store(User(name="Ilay",age=4))session.save_changes()InstallationInstall fromPyPi, aspyravendb-embedded_.pipinstallpyravendbInstall Pyravendb-Embedded from pip will provide you with a copy of RavenDB server binaries files as wellUsageStart a serverTo start RavenDB server you only need to runstart_server()method fromEmbeddedServerinstance and that’s it.EmbeddedServer.start_server()To be more in control about your serverstart_servermethod can take one parameterserver_options.ServerOptionsframework_version- The framework version to run the server with.data_directory- Where to save the database data (if None the files will be saved in RavenDB folder in the base folder).server_url- The url the server will be opened if None the server will open on local host.dotnet_path- Where dotnet.exe is located if dotnet in the PATH nothing needed here (If .net core is not installed in your machineyou can downloaddotnet binariesand just put the path to it)command_line_args- A list of allserver command args.server_options=ServerOptions(data_directory="MYPATH/RavenDBDataDir")EmbeddedServer().start_server(server_options)SecurityThere are two options to make ravendb secured in Pyravendb-Embedded:secured(certificate_path, certificate_password=None)- For this option you will put a path to a .pfx file for the server and a password to the file if you have one.server_options=ServerOptions()server_options.secured("PATH_TO_PFX_CERT_FILE","PASSWORD_TO_CERT_FILE")EmbeddedServer.start_server(server_options)secured_with_exec(self, cert_exec, cert_exec_args, server_cert_fingerprint, client_cert_path, client_cert_password=None)- For this option you will have to put executable program (ex. powershell, python, etc) and the arguments for him, the fingerprint of the cert file you can use pyravendb Utils for that (see get_cert_file_fingerprint method), the client cert path and the password if you have one.server_options=ServerOptions()sserver_options.secured_with_exec("powershell","C:\\secrets\\give_me_cert.ps1",Utils.get_cert_file_fingerprint("PATH_TO_PEM_CERT_FILE"),"PATH_TO_PEM_CERT_FILE")EmbeddedServer.start_server(server_options)Get Document StoreAfter initialize and start the server we can useget_document_storemethod to be able to get a DocumentStore
and start work with RavenDB as normal.EmbeddedServer().start_server()withEmbeddedServer().get_document_store("Test")asstore:passget_document_storemethod can get or only the database_name or DatabaseOptionDatabaseOptionsdatabase_name- The name of the databaseskip_creating_database-get_document_storewill create a new database if the database is not exists, if this option if True we won’t create the database (Default False).# In this example we won't create the Test database if not exists will raise an exceptiondatabase_options=DatabaseOptions(database_name="Test",skip_creating_database=True)withEmbeddedServer().get_document_store(database_options)asstore:# Your code hereOpen the RavenDB studio in the browserTo open RavenDB studio from Pyravendb-Embedded you can useopen_studio_in_browsermethod and the studio will open automatically
one your default browser.EmbeddedServer().open_studio_in_browser()AcknowledgmentsEmbeddedServerclass is a singleton!Every time we useEmbeddedServer()we will get the same instance.