def get_belapi_handle(client, username=None, password=None):
(username, password) = get_user_creds(username, password)<EOL>sys_db = client.db("<STR_LIT>", username=username, password=password)<EOL>try:<EOL><INDENT>if username and password:<EOL><INDENT>belapi_db = sys_db.create_database(<EOL>name=belapi_db_name,<EOL>users=[{"<STR_LIT:username>": username, "<STR_LIT:password>": password, "<STR_LIT>": True}],<EOL>)<EOL><DEDENT>else:<EOL><INDENT>belapi_db = sys_db.create_database(name=belapi_db_name)<EOL><DEDENT><DEDENT>except arango.exceptions.DatabaseCreateError:<EOL><INDENT>if username and password:<EOL><INDENT>belapi_db = client.db(belapi_db_name, username=username, password=password)<EOL><DEDENT>else:<EOL><INDENT>belapi_db = client.db(belapi_db_name)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>belapi_db.create_collection(belapi_settings_name)<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>belapi_db.create_collection(belapi_statemgmt_name)<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT>return belapi_db<EOL>
Get BEL API arango db handle