Oslo Utility library
The oslo.utils library provides support for common utility functions such as encoding, exception handling, string manipulation, and time handling. It is an integral part of the OpenStack ecosystem. The current stable version is 10.0.1, with releases typically tied to the OpenStack development cycles.
Warnings
- breaking Dropped Python 2.x support in major versions. `oslo.utils` versions 10.x and later explicitly require Python 3.10 or newer. Older codebases running on Python 2 will need to be migrated to Python 3.
- gotcha Other libraries or OpenStack components might have implicit runtime dependencies on `oslo.utils` submodules. For example, `keystoneauth1` previously had an issue where it would fail without `oslo.utils` being explicitly installed, despite not declaring it as a direct dependency.
- gotcha The behavior of string encoding/decoding utilities like `encodeutils.safe_decode` and `encodeutils.safe_encode` changed significantly between Python 2 and Python 3. While current versions of `oslo.utils` only support Python 3, older codebases being migrated may contain assumptions or usage patterns from Python 2 that are no longer valid, particularly regarding `unicode` vs `str` types.
Install
-
pip install oslo.utils
Imports
- generate_uuid
from oslo_utils import uuidutils
- utcnow
from oslo_utils import timeutils
- safe_decode
from oslo_utils import encodeutils
- raise_without_exc_info
from oslo_utils import excutils
- constant_time_compare
from oslo_utils import secretutils
Quickstart
from oslo_utils import uuidutils
from oslo_utils import timeutils
# Generate a UUID
uuid = uuidutils.generate_uuid()
print(f"Generated UUID: {uuid}")
# Get current UTC time
now = timeutils.utcnow()
print(f"Current UTC time: {now}")