{"id":5677,"library":"oslo-utils","title":"Oslo Utility library","description":"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.","status":"active","version":"10.0.1","language":"en","source_language":"en","source_url":"https://github.com/openstack/oslo.utils","tags":["openstack","utility","encoding","exceptions","time","uuid","python3"],"install":[{"cmd":"pip install oslo.utils","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Date and time parsing.","package":"iso8601","optional":false},{"reason":"Internationalization utilities.","package":"oslo.i18n","optional":false},{"reason":"Network address manipulation.","package":"netaddr","optional":false},{"reason":"Core utilities for Python packages.","package":"packaging","optional":false},{"reason":"Process and system utility information.","package":"psutil","optional":false},{"reason":"Grammar and parsing tools.","package":"pyparsing","optional":false},{"reason":"YAML parsing and emitting.","package":"PyYAML","optional":false},{"reason":"Utilities for collecting technical debt (e.g., deprecation warnings).","package":"debtcollector","optional":false}],"imports":[{"note":"Used for generating UUIDs.","symbol":"generate_uuid","correct":"from oslo_utils import uuidutils"},{"note":"Provides timezone-aware UTC datetime objects.","symbol":"utcnow","correct":"from oslo_utils import timeutils"},{"note":"Handles safe decoding of bytes to strings.","symbol":"safe_decode","correct":"from oslo_utils import encodeutils"},{"note":"Utility for re-raising exceptions without retaining full traceback information, common in OpenStack for error handling.","symbol":"raise_without_exc_info","correct":"from oslo_utils import excutils"},{"note":"Provides a constant-time comparison function suitable for cryptography.","symbol":"constant_time_compare","correct":"from oslo_utils import secretutils"}],"quickstart":{"code":"from oslo_utils import uuidutils\nfrom oslo_utils import timeutils\n\n# Generate a UUID\nuuid = uuidutils.generate_uuid()\nprint(f\"Generated UUID: {uuid}\")\n\n# Get current UTC time\nnow = timeutils.utcnow()\nprint(f\"Current UTC time: {now}\")","lang":"python","description":"This quickstart demonstrates how to generate a UUID and get the current UTC time using two common modules from oslo.utils: `uuidutils` and `timeutils`."},"warnings":[{"fix":"Upgrade your Python environment to 3.10+ and ensure all dependencies are compatible. Review and update any Python 2 specific code patterns.","message":"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.","severity":"breaking","affected_versions":"< 10.0.0"},{"fix":"When installing OpenStack clients or other 'oslo' ecosystem libraries, ensure `oslo.utils` is explicitly installed if `ModuleNotFoundError` issues arise, even if not explicitly listed in `requirements.txt` of the primary application.","message":"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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Thoroughly review all calls to `encodeutils.safe_decode`, `safe_encode`, and `to_utf8` in migrated Python 2 code. Ensure that expected input types (bytes or str) and output types (str or bytes) align with Python 3 string semantics.","message":"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.","severity":"gotcha","affected_versions":"All versions (when migrating from Python 2)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}