{"library":"osprofiler","title":"OpenStack Profiler Library","description":"OSProfiler is a Python library used by OpenStack projects and clients for cross-service profiling. It enables the generation of a single trace per request across multiple services, forming a tree of calls to help identify performance bottlenecks. It is actively maintained by the OpenStack community and provides API and CLI tools for trace management.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install osprofiler"],"cli":{"name":"osprofiler","version":"4.4.0"}},"imports":["from osprofiler import profiler","from osprofiler.web import WsgiMiddleware"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom osprofiler import profiler\n\n# In a production OpenStack environment, HMAC_KEY would be a shared secret.\n# For local testing, a simple key suffices.\nHMAC_KEY = os.environ.get('OSPROFILER_HMAC_KEY', 'my-very-secret-key-for-profiling')\n\n# Initialize the profiler with a base host, project, and HMAC key.\n# This is crucial; without initialization, profiling calls are ignored.\nprofiler.init('local-host', 'my-test-project', HMAC_KEY)\n\n@profiler.trace('my_outer_operation', info={'type': 'application_logic'})\ndef perform_complex_task(input_data):\n    print(f\"Starting complex task with: {input_data}\")\n    # Simulate some work\n    import time\n    time.sleep(0.01)\n\n    with profiler.Trace('inner_computation', info={'stage': 'data_processing'}):\n        intermediate_result = input_data * 2\n        time.sleep(0.005)\n    \n    print(f\"Intermediate result: {intermediate_result}\")\n    return intermediate_result + 10\n\nif profiler.is_active():\n    final_output = perform_complex_task(5)\n    print(f\"Final output: {final_output}\")\n    print(\"Profiler is active and trace points would be generated.\")\n    # In a real setup, trace data would be sent to a collector (e.g., Ceilometer)\n    # and retrieved via the `osprofiler` CLI (e.g., `osprofiler trace show <trace_id>`).\nelse:\n    print(\"Profiler is not active. Check initialization and configuration.\")","lang":"python","description":"This quickstart demonstrates how to initialize OSProfiler and add trace points using both the `@profiler.trace` decorator and the `with profiler.Trace` context manager. It highlights the importance of `profiler.init()` for activating profiling. The `HMAC_KEY` is essential for security and validating trace information, especially in distributed OpenStack environments.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"4.3.0","pypi_latest":"4.4.0","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":4.9,"avg_import_s":1.03,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"osprofiler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.01,"mem_mb":14,"disk_size":"45.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"osprofiler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.7,"import_time_s":0.71,"mem_mb":14,"disk_size":"47M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"osprofiler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.27,"mem_mb":15.8,"disk_size":"50.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"osprofiler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.8,"import_time_s":1.15,"mem_mb":15.8,"disk_size":"52M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"osprofiler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.12,"mem_mb":15.4,"disk_size":"50.4M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"osprofiler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.7,"import_time_s":1.19,"mem_mb":15.4,"disk_size":"52M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"osprofiler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.05,"mem_mb":16.2,"disk_size":"50.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"osprofiler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.6,"import_time_s":1.1,"mem_mb":16.2,"disk_size":"52M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"osprofiler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.89,"mem_mb":13.4,"disk_size":"47.5M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"osprofiler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":5.5,"import_time_s":0.83,"mem_mb":13.4,"disk_size":"49M"}]}}