Implementation:OpenHands OpenHands Version
| Knowledge Sources | |
|---|---|
| Domains | UI_Components, React |
| Last Updated | 2026-02-11 21:00 GMT |
Overview
A Python module providing multi-layered version detection for the OpenHands package with graceful fallback strategies.
Description
The version module exposes the package version through the __version__ variable and the get_version() function. It implements a multi-layered detection strategy that attempts the following sources in order:
- pyproject.toml — Reads the version directly from the project's
pyproject.tomlfile if available in the source tree. - importlib.metadata — Uses the standard library
importlib.metadatamodule to query the installed package version. - pkg_resources — Falls back to the legacy
pkg_resourcesAPI from setuptools for older environments. "unknown"— Returns the string"unknown"if all detection methods fail.
The module also exports a __package_name__ variable containing the canonical package name. The source file is 44 lines long.
Usage
Use this module to programmatically determine the installed version of OpenHands at runtime. It is commonly used in CLI output, logging, HTTP user-agent headers, telemetry, and diagnostic information.
Code Reference
Source Location
openhands/version.py (44 lines)
Signature
// Note: This module is Python, not TypeScript.
// Python signature:
def get_version() -> str:
"""Returns the package version string, or 'unknown' if detection fails."""
...
__version__: str
__package_name__: str
Import
// Python import:
// from openhands.version import __version__
// from openhands.version import get_version
I/O Contract
Inputs (Props)
The get_version() function takes no arguments. It reads from the environment and filesystem automatically.
Outputs
| Output | Type | Description |
|---|---|---|
get_version() return value |
str |
The detected version string (e.g., "1.11.4") or "unknown" if all detection methods fail.
|
__version__ |
str |
Module-level variable holding the result of get_version(), evaluated at import time.
|
__package_name__ |
str |
The canonical name of the package (e.g., "openhands").
|
Usage Examples
// Python usage examples:
// Basic version check
from openhands.version import __version__
print(f"OpenHands version: {__version__}")
// Using the function directly
from openhands.version import get_version
version = get_version()
if version == "unknown":
print("Warning: Could not determine package version")
// In a CLI tool
from openhands.version import __version__, __package_name__
print(f"{__package_name__} v{__version__}")