{"library":"splunk-handler","title":"Splunk Logging Handler","type":"library","description":"The `splunk-handler` library provides a Python logging handler for sending log events to a Splunk Enterprise instance. It leverages the Splunk HTTP Event Collector (HEC) for data ingestion. The current version is 3.0.0, and the project maintains an active release cadence, addressing bug fixes, new features, and Python compatibility updates.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install splunk-handler"],"cli":null},"imports":["from splunk_handler import SplunkHandler","from splunk_handler import force_flush"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/zach-taylor/splunk_handler","docs":null,"changelog":null,"pypi":"https://pypi.org/project/splunk-handler/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import logging\nimport os\nfrom splunk_handler import SplunkHandler, force_flush\n\n# Configure Splunk HEC details via environment variables\nSPLUNK_HOST = os.environ.get('SPLUNK_HOST', 'splunk.example.com')\nSPLUNK_PORT = os.environ.get('SPLUNK_PORT', '8088')\nSPLUNK_TOKEN = os.environ.get('SPLUNK_TOKEN', 'YOUR_SPLUNK_HEC_TOKEN')\nSPLUNK_INDEX = os.environ.get('SPLUNK_INDEX', 'main')\n\n# Initialize the SplunkHandler\ntry:\n    splunk_handler = SplunkHandler(\n        host=SPLUNK_HOST,\n        port=SPLUNK_PORT,\n        token=SPLUNK_TOKEN,\n        index=SPLUNK_INDEX,\n        protocol='https', # Use 'http' if SSL is not configured\n        verify=True,      # Set to False if using self-signed certs and not providing CA\n        flush_interval=1.0 # Send logs every 1 second for demonstration\n    )\n    # Add the handler to the root logger\n    logging.getLogger('').addHandler(splunk_handler)\n    logging.getLogger('').setLevel(logging.INFO)\n\n    # Example log messages\n    logging.info('Hello from splunk-handler!')\n    logging.warning('This is a warning message.')\n    logging.error('An error occurred: %s', 'something went wrong')\n\n    # For environments like AWS Lambda, ensure logs are flushed before exiting.\n    # In a typical application, the atexit hook handles this, but explicit call might be needed.\n    force_flush()\n    print('Logs sent to Splunk (check your Splunk instance).')\n\nexcept Exception as e:\n    print(f\"Failed to configure Splunk handler or send logs: {e}\")\n    print(\"Please ensure SPLUNK_HOST, SPLUNK_PORT, SPLUNK_TOKEN, and SPLUNK_INDEX are correctly set.\")\n    print(\"Also, verify that Splunk HEC is enabled and accessible.\")","lang":"python","description":"This quickstart demonstrates how to configure and use `splunk-handler` to send log messages to Splunk Enterprise via the HTTP Event Collector. It uses environment variables for sensitive connection details and includes an example of `force_flush` for critical environments like AWS Lambda. Ensure your Splunk HEC is properly configured and accessible from where this code runs.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"3.0.0","pypi_latest":"3.0.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.1,"avg_import_s":0.57,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"splunk-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.59,"mem_mb":9.8,"disk_size":"21.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"splunk-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.37,"mem_mb":9.8,"disk_size":"22M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"splunk-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.7,"mem_mb":10.8,"disk_size":"23.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"splunk-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.6,"mem_mb":10.8,"disk_size":"24M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"splunk-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.64,"mem_mb":11.3,"disk_size":"15.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"splunk-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.9,"import_time_s":0.66,"mem_mb":11.3,"disk_size":"16M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"splunk-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.61,"mem_mb":11.6,"disk_size":"14.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"splunk-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2,"import_time_s":0.6,"mem_mb":11.6,"disk_size":"15M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"splunk-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.51,"mem_mb":9.4,"disk_size":"20.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"splunk-handler","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.5,"import_time_s":0.45,"mem_mb":9.4,"disk_size":"21M"}]}}