Tools

class mogwai.tools.BlueprintsWrapper(class_name=None, setup=None, *args, **kwargs)

Abstract implementation for using a Blueprints graph wrapper within a persisted transaction. Within this transaction g refers to the wrapped graph.

Parameters:
  • class_name (str) – the Blueprints Implementation class name
  • setup (str) – an iterable with additional groovy statements that are executed upon initialization. (optional, default: [])
Returns:

the used RexPro connection pool (with default session)

Raises MogwaiBlueprintsWrapperException:
 

if no class name is provided

class mogwai.tools.Factory

Factory for Mogwai models.

exception mogwai.tools.ImportStringError(import_name, exception)

Provides information about a failed import_string() attempt.

exception = None
import_name = None
class mogwai.tools.LazyImportClass(import_name)

Lazily load and return a class

klass

Imports the class and caches

class mogwai.tools.PartitionGraph(write=None, read=None, *args, **kwargs)

Wrapper for the Blueprints PartitionGraph, which is documented by https://github.com/tinkerpop/blueprints/wiki/Partition-Implementation

Parameters:
  • write (str) – the default read+write partition.
  • read (iterable) – optional read partitions.
Returns:

the used RexPro connection pool (with default session)

Raises MogwaiBlueprintsWrapperException:
 

if no write partition is provided

class mogwai.tools.SessionPoolManager(bindings=None, pool_size=10)

A context manager that exposes a pool whose connections share the same session. If RexPro is used without concurrency, it is not necessary to use connections from the pool explicitly. connection.execute_query is patched in this case to use connections from the pool by default. In concurrent mode the pool always needs to be used explicitly, because we cannot rely on global context for patching.

Parameters:
  • bindings (dict) – variables that are available throughout the session (optional)
  • pool_size (int) – the maximum number of simultaneous connections for this pool
Returns:

the used RexPro connection pool (with default session)

class mogwai.tools.cached_property(func, name=None, doc=None)

A decorator that converts a function into a lazy property. The function wrapped is called the first time to retrieve the result and then that calculated result is used the next time you access the value:

class Foo(object):

    @cached_property
    def foo(self):
        # calculate something important here
        return 42

The class has to have a __dict__ in order for this property to work.

mogwai.tools.import_string(import_name, silent=False)

Imports an object based on a string. This is useful if you want to use import paths as endpoints or something similar. An import path can be specified either in dotted notation (xml.sax.saxutils.escape) or with a colon as object delimiter (xml.sax.saxutils:escape).

If silent is True the return value will be None if the import fails.

Parameters:
  • import_name – the dotted name for the object to import.
  • silent – if set to True import errors are ignored and None is returned instead.
Returns:

imported object

mogwai.spec.get_existing_indices()

Find all Vertex and Edge types available in the database

mogwai.spec.write_compiled_indices_to_file(filename, spec=None)

Write the compile index specification to file

Parameters:filename (basestring) – The file to write to
mogwai.spec.write_diff_indices_to_file(filename, spec=None)

Preview of index diff specification to write to file

Parameters:filename (basestring) – The file to write to
mogwai.spec.write_specs_to_file(filename)

Generate and write a specification to file

Parameters:filename (basestring) – The file to write to