Python client for the Honeycomb.io API
Project description
honeycomb-api-python
A modern, async-first Python client for the Honeycomb.io API.
Features
- Async-first design with full sync support
- Fluent builder pattern for queries, triggers, SLOs, and boards
- CLI tool for porting objects between environments
- Claude tool definitions exposing the full Honeycomb API for Claude-based agents
- Pydantic models for type-safe request/response handling
- Automatic retries with exponential backoff for transient failures
- Comprehensive error handling with specific exception types
- Dual authentication support (API keys and Management keys)
- Resource-oriented API for intuitive usage
Installation
# Using Poetry
poetry add honeycomb-api
# Using uv
uv add honeycomb-api
Quick Start
Async Usage (Recommended)
import asyncio
from honeycomb import HoneycombClient, QueryBuilder
async def main():
async with HoneycombClient(api_key="your-api-key") as client:
# List all datasets
datasets = await client.datasets.list_async()
for ds in datasets:
print(f"Dataset: {ds.name} ({ds.slug})")
# Run a query using the fluent QueryBuilder
query, result = await client.query_results.create_and_run_async(
QueryBuilder("Error Analysis") # Optional name for board integration
.dataset("my-dataset") # Dataset scope on builder
.last_24_hours() # Time preset matching Honeycomb UI
.count()
.p99("duration_ms")
.avg("duration_ms")
.gte("status_code", 500) # Filter shortcuts: gte, eq, contains, etc.
.group_by("service", "endpoint")
.order_by_count()
.limit(100)
)
for row in result.data.rows:
print(f"Service: {row['service']}, Count: {row['COUNT']}, P99: {row['P99']}")
asyncio.run(main())
Sync Usage
from honeycomb import HoneycombClient, QueryBuilder
with HoneycombClient(api_key="your-api-key", sync=True) as client:
datasets = client.datasets.list()
# Run queries with the same fluent API
query, result = client.query_results.create_and_run(
QueryBuilder()
.dataset("my-dataset")
.last_1_hour()
.count()
.group_by("endpoint"),
)
Builders with resource mixins
TriggerBuilder
from honeycomb import TriggerBuilder
# Create sophisticated alert in one fluent call
trigger = await client.triggers.create_async(
"api-logs",
TriggerBuilder("High Error Rate")
.dataset("api-logs") # Or .environment_wide() for all datasets
.last_15_minutes() # Frequency presets
.count()
.gte("status_code", 500)
.threshold_gt(100) # Threshold shortcuts
.email("oncall@example.com") # Multiple recipients
.pagerduty("critical")
.slack("#incidents")
.tag("team", "backend") # Tag support with validation
.build()
)
SLOBuilder
from honeycomb import SLOBuilder
# Create SLO with derived column and burn alerts automatically
slos = await client.slos.create_from_bundle_async(
SLOBuilder("API Availability")
.dataset("api-logs")
.target_nines(3) # 99.9% = .target_percentage(99.9)
.time_period_days(30)
.sli(
alias="success_rate",
expression="IF(LT($status_code, 400), 1, 0)",
description="Success indicator"
)
# Burn alerts with integrated recipients
.exhaustion_alert(exhaustion_minutes=15)
.budget_rate_alert(window_minutes=60, threshold_percentage=10)
.email("sre@example.com")
.pagerduty("critical")
.build()
)
BoardBuilder
from honeycomb import BoardBuilder, QueryBuilder, SLOBuilder
# Create board with inline queries and SLOs - no pre-creation needed!
board = await client.boards.create_from_bundle_async(
BoardBuilder("Production Dashboard")
.description("Service health monitoring")
.auto_layout()
.tag("team", "platform")
# Inline QueryBuilder - creates query automatically
.query(
QueryBuilder("Request Count")
.dataset("api-logs")
.last_24_hours()
.count()
.group_by("service"),
style="graph"
)
# Inline SLOBuilder - creates SLO automatically
.slo(
SLOBuilder("API Availability")
.dataset("api-logs")
.target_nines(3)
.sli(alias="sli_success")
)
# Environment-wide query
.query(
QueryBuilder("P99 Latency")
.environment_wide() # All datasets
.last_1_hour()
.p99("duration_ms")
.group_by("endpoint"),
style="table"
)
.build()
)
See full documentation for more examples and advanced features.
Authentication
The client supports two authentication methods:
API Key (Single Environment)
For accessing a single Honeycomb environment:
client = HoneycombClient(api_key="your-api-key")
The API key is sent via the X-Honeycomb-Team header.
Management Key (Multi-Environment)
For management operations across multiple environments:
client = HoneycombClient(
management_key="your-key-id",
management_secret="your-key-secret"
)
Management credentials are sent via the Authorization: Bearer header.
CLI Tool
For quick operations without writing Python:
# Run without installing (using uvx or pipx)
export HONEYCOMB_API_KEY=your_api_key_here
uvx honeycomb-api triggers list
# or
pipx run honeycomb-api triggers list
# Or install and use the short alias
uv tool install honeycomb-api
# or
pipx install honeycomb-api
hny triggers list
hny query run --dataset my-dataset --count --last-30-minutes
See the CLI Reference for full documentation.
Usage Guide
For complete usage examples and guides, see the full documentation:
- Quick Start Guide - Common operations with examples
- Working with Queries - Saved, ephemeral, and combined query patterns
- Working with Triggers - Alert configuration
- Working with SLOs - Service level objectives
- API Reference - Complete API documentation
Error Handling
The client provides specific exception types for different error scenarios (authentication, rate limiting, validation, etc.). All exceptions include useful debugging information like HTTP status codes and request IDs for support tickets.
See the Error Handling Guide for complete documentation and best practices.
Configuration
Client Options
from honeycomb import HoneycombClient, RetryConfig
client = HoneycombClient(
api_key="...", # API key for single-environment access
management_key="...", # Management key ID (alternative auth)
management_secret="...", # Management key secret
base_url="https://api.honeycomb.io", # API base URL (default)
timeout=30.0, # Request timeout in seconds (default: 30)
max_retries=3, # Max retry attempts (default: 3)
retry_config=None, # Custom retry configuration (optional)
sync=False, # Use sync mode (default: False)
)
Retry Behavior
The client automatically retries requests on:
- HTTP 429 (Rate Limited) - respects
Retry-Afterheader - HTTP 500, 502, 503, 504 (Server Errors)
- Connection timeouts
Retries use exponential backoff: 1s, 2s, 4s, ... up to 30s max.
Custom Retry Configuration
from honeycomb import HoneycombClient, RetryConfig
# Customize retry behavior
retry_config = RetryConfig(
max_retries=5, # More retry attempts
base_delay=2.0, # Start with 2s delay
max_delay=60.0, # Cap at 60s
exponential_base=2.0, # Double each time
retry_statuses={429, 503}, # Only retry these status codes
)
client = HoneycombClient(api_key="...", retry_config=retry_config)
API Reference
The client provides resource-oriented access to the Honeycomb API:
Core Resources:
client.datasets- Dataset managementclient.triggers- Alert triggersclient.slos- Service level objectivesclient.boards- Dashboardsclient.queries- Saved queriesclient.query_results- Query execution
Data Management:
client.columns- Column schema managementclient.markers- Event markers and annotationsclient.recipients- Notification recipientsclient.burn_alerts- SLO burn rate alertsclient.events- Event ingestion (send data to Honeycomb)
Team Management (v2 - requires Management Key):
client.api_keys- API key management (team-scoped)client.environments- Environment management (team-scoped)
All methods have both sync and async variants (list() / list_async()).
See the API Reference for complete documentation.
Development
Prerequisites
Setup
# Clone the repository
git clone https://github.com/irvingpop/honeycomb-api-python.git
cd honeycomb-api-python
# Install dependencies
make install-dev
# Or: poetry install
# Set up environment variables (for live API testing)
cp .envrc.example .envrc
# Edit .envrc with your API key
direnv allow
Testing Standards
This project maintains high test coverage standards:
- ≥95% coverage required for all resource modules
- Tests use Polyfactory for schema-valid mock data generation
Make Commands
All common development tasks are available via make. Run make help for a full list:
make help # Show all available commands
Setup
| Command | Description |
|---|---|
make install |
Install poetry production dependencies only |
make install-dev |
Install all poetry dependencies (including dev) |
Code Quality
| Command | Description |
|---|---|
make lint |
Run linter (ruff check) |
make lint-fix |
Run linter and auto-fix issues |
make format |
Format code with ruff |
make typecheck |
Run type checker (mypy) |
make check |
Run all checks (lint + typecheck) |
Testing
| Command | Description |
|---|---|
make test |
Run all tests |
make test-unit |
Run only unit tests |
make test-cov |
Run tests with coverage report |
make test-live |
Run live API tests (requires HONEYCOMB_API_KEY) |
Build & Publish
| Command | Description |
|---|---|
make build |
Build distribution packages |
make publish |
Publish to PyPI |
make publish-test |
Publish to Test PyPI |
Maintenance
| Command | Description |
|---|---|
make clean |
Remove build artifacts and cache files |
make update-deps |
Update dependencies to latest versions |
make ci |
Run full CI pipeline (install, check, test) |
Running Tests (Manual)
# Run all tests
make test
# Or: poetry run pytest tests/ -v
# Run with coverage
make test-cov
# Or: poetry run pytest --cov=honeycomb --cov-report=html
# Run specific test file
poetry run pytest tests/unit/test_wrapper_client.py -v
Code Quality (Manual)
# Run all checks
make check
# Or run individually:
poetry run ruff check src/ tests/ # Linting
poetry run ruff format src/ tests/ # Formatting
poetry run mypy src/ # Type checking
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run checks and tests (
make check && make test) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Guidelines
- Follow the existing code style (enforced by Ruff)
- Add tests for new functionality
- Update documentation as needed
- Keep commits focused and atomic
- Run
make cibefore submitting to ensure all checks pass
License
This project is licensed under the MIT License - see the LICENSE file for details.
Related Links
Acknowledgments
- Built with httpx for async HTTP
- Models powered by Pydantic
- API spec from Honeycomb OpenAPI
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file honeycomb_api-0.7.1.tar.gz.
File metadata
- Download URL: honeycomb_api-0.7.1.tar.gz
- Upload date:
- Size: 175.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5571ef1f977f95a5ab48ba5ad40351994d10e355c923b200657641eb2d81340
|
|
| MD5 |
2a4f3fb780a238d1cf32563b10f50b63
|
|
| BLAKE2b-256 |
c61f80e9b6d285cb30cf5a10c7d89bcd20d7379090e3e3363ba0d61c58ff0d85
|
File details
Details for the file honeycomb_api-0.7.1-py3-none-any.whl.
File metadata
- Download URL: honeycomb_api-0.7.1-py3-none-any.whl
- Upload date:
- Size: 237.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cf14441bdb492f9deb0698134d963d2d6a301fb646d6f67a3c67f752b6aa7d0
|
|
| MD5 |
bc4d44eea51873354064f319f919cc19
|
|
| BLAKE2b-256 |
20bcfcef6a4652286425c0fdcedaf97f79064be7710b6d2f592510b326016054
|