Honeycomb Python Client
A simple, user-friendly wrapper for sending events to Honeycomb using libhoney, with built-in connection management to prevent file descriptor exhaustion in high-throughput environments.
Installation
Copy the honeycomb_client.py file (and __init__.py) into your project, or install as a public package if set up.
Usage
from capture_hc.honeycomb_client import HoneycombClient
# Initialize the client (use your own writekey and dataset)
honey = HoneycombClient(
writekey="<YOUR_WRITE_KEY>",
dataset="<YOUR_DATASET>",
batch_size=50, # Flush after 50 events (default)
flush_interval=5.0 # Or flush every 5 seconds (default)
)
# Send an event (fields as a dictionary)
honey.send_event({
"alert_name": "Test Alert",
"priority": "P1",
"message": "Something happened!",
"duration_ms": 123.4
})
# Use the timed decorator to automatically measure and send duration
@honey.timed({"alert_name": "important_task"})
def important_task(x, y, event=None):
# ... your code ...
event.add_field("result", x + y)
return x + y
important_task(1, 2)
# You can also customize the event variable name
@honey.timed({"alert_name": "custom_var"}, event_arg='track')
def another_task(x, y, track=None):
track.add_field("custom_field", x * y)
return x * y
another_task(2, 3)
Features
- Connection Management: Prevents "Too many open files" errors with intelligent batching
- Batch Processing: Configurable batch size and flush intervals to optimize performance
- Thread-Safe: Safe for concurrent use in multi-threaded environments
- Simple
send_event(dict)interface - All fields are added to the event
@honey.timed({...})decorator to measure and send function execution time automatically- Automatic cleanup on process exit
Connection Management
The client automatically manages connections to prevent file descriptor exhaustion:
- Batch Size: Events are batched and sent together (default: 50 events)
- Flush Interval: Events are flushed after a time interval (default: 5 seconds)
- Connection Pooling: Limits concurrent connections (max 10 by default)
- Thread Safety: All operations are thread-safe
Tuning for High-Throughput
For environments with many concurrent tasks (like Airflow):
# For high-throughput environments
honey = HoneycombClient(
writekey="<YOUR_WRITE_KEY>",
dataset="<YOUR_DATASET>",
batch_size=100, # Larger batches
flush_interval=10.0 # Longer intervals
)
# Force flush when needed
honey.flush()
# Clean up when done
honey.close()
Advanced
You can pass debug=True to enable debug logging
Integration Example
Set your environment variables and run the script to send a test event and a timed event:
export HONEYCOMB_WRITEKEY=your_writekey
export HONEYCOMB_DATASET=your_dataset
python -m integration_example
This will:
- Send a simple event to Honeycomb
- Use the
@honey.timeddecorator to send a timed event with custom fields
Example from integration_example.py:
@honey.timed({'alert_name': 'decorator_test'})
def test_func(event=None):
event.add_field('custom_field', 123)
return 'decorator event sent!'
Lazy decorator (module or class)
Use a one-liner lazy decorator that initializes at call-time and works with legacy functions:
from capture_hc import lazy_timed
@lazy_timed(extra_fields={'alert_name': 'legacy_task'}, event_arg=None)
def legacy_task(x, y):
return x + y
Or use it via the class for discoverability:
from capture_hc import HoneycombClient
@HoneycombClient.lazy_timed(extra_fields={'alert_name': 'legacy_task'}, event_arg=None)
def legacy_task(x, y):
return x + y
- Credentials resolve from env by default (
HONEYCOMB_WRITEKEY,HONEYCOMB_DATASET). - Set
event_arg=Noneif your function can't accept the event kwarg.
Airflow note
- Prefer lazy decorators or initialize the client inside the task function to avoid DAG-parse-time side effects.
Metadata
Release files for capture-hc 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| capture_hc-0.2.0.tar.gz | 7.6 kB | Without provenance | Details for capture_hc-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| capture_hc-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for capture_hc-0.2.0-py3-none-any.whl |
Total release size: 14.5 kB
Release files / capture_hc-0.2.0.tar.gz
| Download URL | capture_hc-0.2.0.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a85c9697ef91c076f29f46094be748a8fa042152c0213d9fa9cccd917a5e9267
|
|
BLAKE2b-256 checksum How to use checksums |
4fc8be32b81627b25beff5c581d36d36deb5a96fd1efa681061e48d0bd56685d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Release files / capture_hc-0.2.0-py3-none-any.whl
| Download URL | capture_hc-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6c79055a9d7360484ff64a7e2aea83a8caa4e51c42de43cfb2c23ac40f99f6ba
|
|
BLAKE2b-256 checksum How to use checksums |
f4809ca9e8d20178184e05613f5ca3dde04d8b6675502618fceaf3410e5d7e2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Security for capture-hc 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.