Tools

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.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