vibex.sh Python SDK - Fail-safe logging handler for vibex.sh
Project description
vibex.sh Python SDK
Fail-safe logging handler for sending logs to vibex.sh.
Features
- Fail-Safe: Silently disables if configuration is missing or invalid
- Kill Switch: Permanently disables on 401/403 errors (expired/invalid tokens)
- Easy Integration: Drop-in Python logging handler
- Zero Dependencies (except
requests)
Installation
pip install vibex_sh
Quick Start
- Set environment variables:
export VIBEX_TOKEN=vb_live_your_token_here
export VIBEX_SESSION_ID=my-production-app
- Use in your Python application:
import logging
import json
from vibex_sh import VibexHandler
# Get your logger
logger = logging.getLogger('my_app')
# Add Vibex handler
vibex_handler = VibexHandler()
logger.addHandler(vibex_handler)
# Send JSON logs (only JSON logs are sent to Vibex)
logger.info(json.dumps({'cpu': 45, 'memory': 78, 'status': 'healthy'}))
logger.info(json.dumps({'error': 'connection_failed', 'retry_count': 3}))
Configuration
The SDK reads configuration from environment variables:
VIBEX_TOKEN(required): Your Vibex API tokenVIBEX_SESSION_ID(required): Your session IDVIBEX_API_URL(optional): API endpoint (default:https://vibex.sh/api/v1/ingest)
Fail-Safe Behavior
The SDK is designed to be fail-safe:
- Missing Config: If
VIBEX_TOKENorVIBEX_SESSION_IDis missing, the handler silently disables itself - Invalid Token: On 401/403 responses, the handler permanently disables for the process lifetime
- Network Errors: All network errors are silently handled - your application continues normally
- Rate Limits: On 429 (rate limit), logs are dropped but the handler remains enabled. Logs are still written to console by default (
passthrough_console=True)
Console Passthrough Options
By default, logs are forwarded to Vibex and also written to stderr (console), ensuring you can always see your logs locally while they're sent to Vibex.
passthrough_console (default: True)
When enabled (default), logs are always written to stderr in addition to being sent to Vibex. This provides visibility into your logs while forwarding them to Vibex.
# Default behavior - logs written to console and sent to Vibex
vibex_handler = VibexHandler() # passthrough_console=True by default
logger.addHandler(vibex_handler)
# To disable console output (logs only sent to Vibex)
vibex_handler = VibexHandler(passthrough_console=False)
logger.addHandler(vibex_handler)
Note: To avoid duplicate log output when using passthrough_console=True, either:
- Avoid using
logging.basicConfig()which adds a default StreamHandler, or - Configure your logger to not propagate:
logger.propagate = False
passthrough_on_failure (default: False)
When enabled, logs are written to stderr when sending to Vibex fails (rate limits, network errors, etc.). This is useful as an additional safety net, but with passthrough_console=True by default, it's typically not needed.
# Write logs to console only when sending fails
vibex_handler = VibexHandler(passthrough_console=False, passthrough_on_failure=True)
logger.addHandler(vibex_handler)
Important: Non-JSON logs are still discarded (only JSON-formatted logs are processed).
Important: JSON-Only Logging
Only JSON-formatted logs are sent to Vibex. Non-JSON logs are automatically discarded. Always stringify your log data:
import json
# ✅ Good - JSON logs are sent
logger.info(json.dumps({'cpu': 45, 'memory': 78}))
# ❌ Bad - Non-JSON logs are discarded
logger.info('Application started')
logger.info('High memory usage: 85%')
Advanced Usage
Direct Client Usage
from vibex_sh import VibexClient, VibexConfig
config = VibexConfig()
client = VibexClient(config)
# Send custom log
client.send_log('json', {'cpu': 45, 'memory': 78})
Check if Enabled
handler = VibexHandler()
if handler.is_enabled():
print('Vibex is active')
else:
print('Vibex is disabled (missing config or expired token)')
Verbose Mode
Enable verbose mode to see status messages when the handler initializes or encounters errors:
vibex_handler = VibexHandler(verbose=True)
logger.addHandler(vibex_handler)
License
MIT
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 vibex_sh-0.2.1.tar.gz.
File metadata
- Download URL: vibex_sh-0.2.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3f6f9244828aec7727db854c5a6f8e3afbdd4439441436a453ffdbeb84af3cc
|
|
| MD5 |
416f4d56017d13768c2731ce78b26d78
|
|
| BLAKE2b-256 |
3477b7469f3d7934e157b4084dec6787bf871e2dd18e505a809c0709a82e2746
|
File details
Details for the file vibex_sh-0.2.1-py3-none-any.whl.
File metadata
- Download URL: vibex_sh-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9002dfdd96ca0b8d1a7f97af9633688bbf7d6aae9bfc0a50ab30bd9bc8a6ff6d
|
|
| MD5 |
dbed21498976168cd84cfb085d203a48
|
|
| BLAKE2b-256 |
8fa7f8fdb46c829bb9fa44de6ba8deea5e3f0e20dd65187c7b7153774600a06d
|