API

SQLAlchemy interface

ispyb.sqlalchemy.enable_debug_logging()[source]

Write debug level logging output for every executed SQL query.

This setting will persist throughout the Python process lifetime and affect all existing and future sqlalchemy sessions. This should not be used in production as it can be expensive, can leak sensitive information, and, once enabled, cannot be disabled.

ispyb.sqlalchemy.session(credentials=None)[source]

Create an SQLAlchemy session.

Warning

This function is deprecated.

Parameters:

credentials – a config file or a Python dictionary containing database credentials. See function url() for details.

Returns:

The SQLAlchemy session.

ispyb.sqlalchemy.url(credentials=None) str[source]

Return an SQLAlchemy connection URL

Parameters:

credentials

a config file or a Python dictionary containing database credentials. If credentials=None then look for a credentials file in the ISPYB_CREDENTIALS environment variable.

Example credentials file:

[ispyb_sqlalchemy]
username = user
password = password
host = localhost
port = 3306
database = ispyb_build

Example credentials dictionary:

{
    "username": "user",
    "password": "password",
    "host": localhost",
    "port": 3306,
    "database": "ispyb",
}

Returns:

A string containing the SQLAlchemy connection URL.

Connecting to ISPyB

exception ispyb.ConnectionError[source]

Bases: ISPyBException

Unable to connect or connection has been closed.

exception ispyb.ISPyBException[source]

Bases: Exception

Base class for all exceptions

exception ispyb.NoResult[source]

Bases: ISPyBException

Query returned no result.

exception ispyb.ReadWriteError[source]

Bases: ISPyBException

Record could not be read, inserted, updated or deleted. This could be due to illegal values, the wrong number of parameters, a violation of table or index constraints, a permissions error, or a database failure.

ispyb.open(credentials=None, configuration_file=None)[source]

Create an ISPyB connection.

Parameters:

credentials

a config file containing database credentials. If credentials=None then look for a credentials file in the “ISPYB_CREDENTIALS” environment variable.

Example credentials file:

[ispyb_mariadb_sp]
user = ispyb_api
pw = password_1234
host = localhost
port = 3306
db = ispybtest
reconn_attempts = 6
reconn_delay = 1

Returns:

The ISPyB connection object.