{"library":"python-logstash-async","title":"Asynchronous Logstash Logging Handler","description":"Python-logstash-async is an asynchronous Python logging handler designed to send log events to a remote Logstash instance. It processes log events in a separate worker thread to avoid blocking the main application, crucial for performance-sensitive applications like web services. It supports TCP, UDP, and Beats protocols, with optional SSL for TCP, and can persist unsent logs to a SQLite database. The library is actively maintained with regular releases addressing bug fixes and introducing new features.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install python-logstash-async"],"cli":null},"imports":["from logstash_async.handler import AsynchronousLogstashHandler","from logstash_async.formatter import LogstashFormatter","from logstash_async.transport import HttpTransport","from logstash_async.transport import BeatsTransport"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import logging\nimport os\nfrom logstash_async.handler import AsynchronousLogstashHandler\nfrom logstash_async.formatter import LogstashFormatter\n\n# Configure Logstash host and port (replace with your Logstash details)\nLOGSTASH_HOST = os.environ.get('LOGSTASH_HOST', 'localhost')\nLOGSTASH_PORT = int(os.environ.get('LOGSTASH_PORT', '5959')) # Or 5000 for standard TCP/UDP\nLOGSTASH_DATABASE_PATH = os.environ.get('LOGSTASH_DB_PATH', 'logstash_events.db')\n\n# Get a logger instance\nlogger = logging.getLogger('my_app_logger')\nlogger.setLevel(logging.INFO)\n\n# Create a Logstash formatter\nformatter = LogstashFormatter(message_type='python-logstash', extra_prefix='dev', extra={'application': 'my-python-app'})\n\n# Create an asynchronous Logstash handler\n# It's recommended to specify a database_path for persistence across restarts\nhandler = AsynchronousLogstashHandler(\n    host=LOGSTASH_HOST,\n    port=LOGSTASH_PORT,\n    database_path=LOGSTASH_DATABASE_PATH,\n    # For TCP/Beats with SSL, set ssl_enable=True and configure certs\n    # ssl_enable=True,\n    # ssl_verify=True,\n    # ca_certs='/path/to/ca.crt'\n)\n\nhandler.setFormatter(formatter)\nlogger.addHandler(handler)\n\n# Add a console handler for local debugging\nconsole_handler = logging.StreamHandler()\nconsole_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))\nlogger.addHandler(console_handler)\n\n# Log some messages\nlogger.info('This is an info message from the quickstart.', extra={'user_id': 123})\nlogger.warning('A warning occurred with some extra data.', extra={'component': 'auth', 'status': 'failed'})\nlogger.error('An error message with detailed context.')\n\n# Ensure all queued logs are sent before exiting\n# In a real application, this might be handled by an atexit hook or proper shutdown logic\nlogger.info('Flushing pending log events...')\nhandler.close() # This will attempt to flush remaining events","lang":"python","description":"This quickstart demonstrates how to configure `python-logstash-async` with `AsynchronousLogstashHandler` and `LogstashFormatter`. It sets up a logger to send INFO, WARNING, and ERROR messages to a Logstash instance, including extra fields. A `database_path` is specified for persistent storage of events in case Logstash is unreachable or the application restarts. The example also includes a console handler for immediate feedback during development.","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":"4.1.0","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.9,"avg_import_s":0.82,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"python-logstash-async","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.69,"mem_mb":13.2,"disk_size":"23.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"python-logstash-async","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3,"import_time_s":0.47,"mem_mb":13.2,"disk_size":"24M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"python-logstash-async","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.87,"mem_mb":14.8,"disk_size":"26.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"python-logstash-async","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3,"import_time_s":0.78,"mem_mb":14.8,"disk_size":"27M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"python-logstash-async","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.02,"mem_mb":14.9,"disk_size":"17.9M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"python-logstash-async","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.5,"import_time_s":1.02,"mem_mb":14.9,"disk_size":"18M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"python-logstash-async","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.09,"mem_mb":15.9,"disk_size":"17.7M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"python-logstash-async","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.6,"import_time_s":0.98,"mem_mb":15.9,"disk_size":"18M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"python-logstash-async","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.66,"mem_mb":13.1,"disk_size":"22.7M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"python-logstash-async","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.5,"import_time_s":0.61,"mem_mb":13.1,"disk_size":"23M"}]}}