os-traits
raw JSON → 3.6.0 verified Mon Apr 27 auth: no python
A library containing standardized trait strings for libvirt domain capabilities, used to represent CPU features, hypervisor capabilities, and other traits. Current version: 3.6.0. Released ~1-2 times per year.
pip install os-traits Common errors
error ModuleNotFoundError: No module named 'os_traits' ↓
cause The package is installed as 'os-traits' but imported as 'os_traits'. Ensure you have installed the correct package.
fix
Run 'pip install os-traits' and then use 'import os_traits'.
error KeyError: 'HW_CPU_X86_SSE' ↓
cause The trait string may not exist in this version; trait names are case-sensitive and version-dependent.
fix
Check available traits using 'from os_traits import TRAITS; print(TRAITS.keys())' and use exact casing.
Warnings
breaking Trait values are not guaranteed to be stable between releases. Do not hardcode numeric trait values; always use the symbolic names. ↓
fix Use TRAITS dict to map from name to value, or use trait_names list for iteration.
gotcha The package name on PyPI is os-traits (hyphen), but the Python import uses underscore: os_traits. This is a common source of error. ↓
fix Install with pip install os-traits, but import with import os_traits.
deprecated Some traits may be deprecated in favor of new naming conventions (e.g., 'CPU_*' vs 'HW_CPU_*'). Always check the latest trait list. ↓
fix Refer to the official trait documentation for the latest naming.
Imports
- trait_names
from os_traits import trait_names - TRAITS
from os_traits import TRAITS
Quickstart
from os_traits import trait_names, TRAITS
# List all trait names
print(trait_names)
# Check if a certain trait exists
if 'HW_CPU_X86_SSE' in TRAITS:
print('SSE trait exists')
# Get trait name by value (if needed)
def get_trait_name(value):
for name, val in TRAITS.items():
if val == value:
return name
return None
print(get_trait_name(1))