Using a driver class

While mako’s functions can be called from command line, they have also been documented extensively so they can be used from a Python script. The base, neo4biom, io, netstats, metastats and utils modules each contain a class that can interact with a running Neo4j database instance. To carry out the functions as part of a script, simply instantiate an object with the necessary information to connect to the database and it will set up a Neo4j driver that can be used to run mako-specific functions or to run custom queries.

All Neo4j driver classes in mako inherit methods from the ParentDriver class and therefore have a query method that can be used to run Cypher queries. Queries can be passed as a string. If appliccable, dictionaries for parameterized batch queries can also be used.

For example, the io module contains the IoDriver class. The IoDriver, like other mako drivers, can be called by providing Neo4j access details:


from mako.scripts.io import IoDriver
driver = IoDriver(user="testuser", 
                  password="test",
                  uri=inputs['address'], 
                  filepath="C:/testfolder/",
                  encrypted=False)
driver.convert_networkx(network=networkx_object, network_id="test_network"