Galaxy Utilities
The `galaxy-util` package provides common utility functions and helper classes used across the larger Galaxy bioinformatics platform. It is an integral part of the Galaxy ecosystem, supporting various functionalities within the main application. Currently at version 26.0.0, it follows the rapid release cadence of the main Galaxy project, often tied to its major releases. While available on PyPI, its primary use case is within the Galaxy project itself.
Common errors
-
ModuleNotFoundError: No module named 'galaxy.util'
cause The `galaxy-util` package has not been installed, or your Python environment's path does not include the installation location.fixEnsure the package is installed: `pip install galaxy-util`. If using a virtual environment, ensure it's activated. -
AttributeError: module 'galaxy.util.path' has no attribute 'some_function_name'
cause The specific utility function or class you are trying to import/use (`some_function_name`) was removed, renamed, or refactored in the version of `galaxy-util` you have installed. This is common due to its internal utility nature.fixCheck the `galaxy.util` source code in the Galaxy project's GitHub repository (`lib/galaxy/util` for your specific version) to find the current API or an alternative. Update your code to reflect the new API. -
ImportError: cannot import name 'SomeSpecificClass' from 'galaxy.util.tool_shed'
cause A class or function previously available in a submodule of `galaxy.util` has been moved to a different module, or it has been removed entirely during a refactoring.fixConsult the Galaxy project's official documentation or examine the source code for the exact `galaxy-util` version you are using to determine the correct import path or if the functionality has been replaced.
Warnings
- breaking APIs within `galaxy.util` can change significantly between major Galaxy releases (e.g., v25 to v26). As an internal utility package, modules, functions, or their signatures might be refactored, moved, or removed without explicit deprecation warnings targeted at external users.
- gotcha The `galaxy-util` package is primarily designed for internal use within the Galaxy project. Its APIs are tightly coupled with the larger Galaxy application's internal structure and evolution, and may not always be suitable or stable for standalone, general-purpose use outside of the Galaxy ecosystem.
- gotcha Version mismatches between `galaxy-util` and the main `galaxy` package (if you are developing for Galaxy) can lead to unexpected behavior, `AttributeError`s, or runtime failures, as they are developed and released in tandem.
Install
-
pip install galaxy-util
Imports
- safe_path
from galaxy_util.path import safe_path
from galaxy.util.path import safe_path
- parse_json_string
from galaxy.util.json import parse_json_string
- sanitize_text
from galaxy.util.sanitize_text import sanitize_text
Quickstart
from galaxy.util.path import safe_path
from galaxy.util.sanitize_text import sanitize_text
# Example 1: Safely resolve a path component
unsafe_path_component = '../etc/passwd'
safe_component = safe_path(unsafe_path_component)
print(f"Unsafe: {unsafe_path_component}, Safe: {safe_component}")
# Example 2: Sanitize text input
raw_text = '<script>alert("XSS")</script>Hello & World!'
sanitized_text = sanitize_text(raw_text)
print(f"Raw: {raw_text}\nSanitized: {sanitized_text}")