The module interface respects the DB-API 2.0 standard defined in PEP 249.
- mgclient.connect(host=None, address=None, port=None, username=None, password=None, client_name=None, sslmode=0, sslcert=None, sslkey=None, trust_callback=None, lazy=False)¶
Makes a new connection to the database server and returns a
Currently recognized parameters are:
DNS resolvable name of host to connect to. Exactly one of host and address parameters must be specified.
Numeric IP address of host to connect to. This should be in the standard IPv4 address format. You can also use IPv6 if your machine supports it. Exactly one of host and address parameters must be specified.
Port number to connect to at the server host.
Username to connect as.
Password to be used if the server demands password authentication.
Alternate name and version of the client to send to server. Default is set by the underlying mgclient library.
This option determines whether a secure connection will be negotiated with the server. There are 2 possible values:
Only try a non-SSL connection (default).
Only try an SSL connection.
This parameter specifies the file name of the client SSL certificate. It is ignored in case an SSL connection is not made.
This parameter specifies the location of the secret key used for the client certificate. This parameter is ignored in case an SSL connection is not made.
A callable taking four arguments.
After performing the SSL handshake,
connect()will call this callable providing the hostname, IP address, public key type and fingerprint. If the function returns
FalseSSL connection will immediately be terminated.
This can be used to implement TOFU (trust on first use) mechanism.
If this is set to
True, a lazy connection is made. Default is
See Lazy connections section to learn about
advantages and limitations of using the
DB-API 2.0 requires the following constants to be defined:
Integer constant stating the level of thread safety the interface supports. For
mgclientit is 1, meaning that threads may share the module, but not connections.
By DB-API 2.0 specification, the module makes all error information available through these exceptions or subclasses thereof:
- exception mgclient.Warning¶
Exception raised for important warnings.
- exception mgclient.Error¶
Base class of all other error exceptions.
- exception mgclient.InterfaceError¶
Exception raised for errors related to the database interface rather than the database itself.
- exception mgclient.DatabaseError¶
Exception raised for errors related to the database.
- exception mgclient.DataError¶
Exception raised for errors that are due to problems with the processed data.
- exception mgclient.OperationalError¶
Exception raised for errors related to the database’s operation, not necessarily under the control of the programmer (e.g. unexpected disconnect, failed allocation).
- exception mgclient.IntegrityError¶
Exception raised when the relational integrity of the database is affected.
- exception mgclient.InternalError¶
Exception raised when the database encounters an internal error.
- exception mgclient.ProgrammingError¶
Exception raised for programming errors (e.g. syntax error, invalid parameters)
- exception mgclient.NotSupportedError¶
Exception raised in a case a method or database API was used which is not supported by the database.
In the current state,
OperationalError is raised for all errors
obtained from the database. This will probably be improved in the future.
Graph type objects¶
- class mgclient.Node¶
A node in the graph with optional properties and labels.
Unique node identifier (within the scope of its origin graph).
A list of node labels.
A dictionary of node properties.
- class mgclient.Relationship¶
A directed, typed connection between two nodes with optional properties.
Unique relationship identifier (within the scope of its origin graph).
Identifier of relationship start node (or -1 if it was not supplied by the database).
Identifier of relationship end node (or -1 if it was not supplied by the database).
A dictionary of relationship properties.
- class mgclient.Path¶
A sequence of alternating nodes and relationships corresponding to a walk in the graph.
A list of nodes in the order they appear in the path. It has one element more than the