BioBlend
BioBlend is a Python library for interacting with the Galaxy API. It simplifies scripting and automating Galaxy analyses, as well as administering a Galaxy server. The library supports Python 3.10 - 3.14 and Galaxy release 19.05 and later. It is actively developed and maintained, with regular releases.
Common errors
-
bioblend.galaxy.client.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))cause The Galaxy server URL is incorrect, the server is not running, or there are network issues preventing connection.fixVerify the `GALAXY_URL` is correct and accessible. Ensure the Galaxy server is running and configured to accept API connections. Check firewall rules if connecting remotely. -
bioblend.galaxy.client.GalaxyAPIError: Client error: 403 Forbidden - Please provide a valid API key.
cause The provided API key is invalid, has insufficient permissions, or the Galaxy server requires authentication that was not met.fixDouble-check your `GALAXY_API_KEY` for typos. Ensure the key belongs to a user with the necessary permissions on the Galaxy server. Generate a new API key if unsure. -
AttributeError: 'HistoryClient' object has no attribute 'get_current_history'
cause You are trying to use a method that has been deprecated and removed from the BioBlend library in newer versions.fixConsult the BioBlend documentation (e.g., `bioblend.readthedocs.io`) for the version you are using to find the updated method for retrieving the current history, or refactor your code to use `get_histories()` and select the desired one.
Warnings
- breaking API key authentication mechanism changed in BioBlend v0.16.0. The API key must now be passed via the `x-api-key` header instead of as a direct parameter in some requests.
- deprecated Several methods were deprecated and removed in BioBlend v0.15.0, including `HistoryClient.download_dataset()`, `HistoryClient.get_current_history()`, `WorkflowClient.export_workflow_json()`, and `WorkflowClient.import_workflow_json()`.
- gotcha There are two `GalaxyInstance` classes available: `bioblend.galaxy.GalaxyInstance` and `bioblend.galaxy.objects.GalaxyInstance`. They expose different API styles (procedural vs. object-oriented) and may have different coverage of Galaxy modules.
Install
-
pip install bioblend
Imports
- GalaxyInstance (standard API)
from bioblend.galaxy import GalaxyInstance
- GalaxyInstance (object-oriented API)
from bioblend.galaxy.objects import GalaxyInstance
Quickstart
import os
from bioblend.galaxy import GalaxyInstance
# Replace with your Galaxy URL and API key or set as environment variables
GALAXY_URL = os.environ.get('GALAXY_URL', 'http://localhost:8080')
GALAXY_API_KEY = os.environ.get('GALAXY_API_KEY', 'YOUR_API_KEY_HERE')
if GALAXY_API_KEY == 'YOUR_API_KEY_HERE':
print("Warning: Please replace 'YOUR_API_KEY_HERE' with your actual Galaxy API key or set the GALAXY_API_KEY environment variable.")
exit(1)
try:
# Connect to the Galaxy instance
gi = GalaxyInstance(GALAXY_URL, key=GALAXY_API_KEY)
# Example: Get a list of available histories
histories = gi.histories.get_histories()
print(f"Found {len(histories)} histories:")
for hist in histories[:3]: # Print first 3 histories
print(f" - Name: {hist['name']}, ID: {hist['id']}")
# Example: Get current Galaxy version
version = gi.config.get_version()
print(f"Galaxy Version: {version}")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure your Galaxy server is running and accessible, and your API key is correct.")