Skip to main content

The Treebeard Python SDK

Project description

Treebeard

Treebeard is a Python library for efficient log forwarding with support for trace contexts and batched logging.

Installation

pip install treebeardhq

Quick Start

from treebeardhq import Treebeard, Log

# Initialize Treebeard with your API key
Treebeard.init(
    api_key="your-api-key",
    endpoint="https://your-logging-endpoint.com/logs"
)
# Start a trace context
trace_id = Log.start("image-processing")

try:
    # Log different severity levels with optional metadata
    Log.info("Starting image processing", image_format="PNG")

    # Some business logic here...

    Log.debug("Image validation", data={"dimensions": [1920, 1080], "color_space": "RGB"})

    # More logic...

    Log.info("Image processed successfully", output_size_kb=256)

except Exception as e:
    Log.error("Processing failed", error=str(e))

finally:
    # End the trace context
    Log.end()

Logging Levels

Treebeard supports multiple logging levels:

Log.debug("Debug information")
Log.info("General information")
Log.warning("Warning message")
Log.error("Error message")

Adding Context Data

You can add metadata to your logs in two ways:

)

# Using keyword arguments
Log.info("User action",
    user_id="123",
    action="login",
    ip="192.168.1.1"
)

Trace Contexts

Trace contexts help you group related logs together:

# Start a new trace context
trace_id = Log.start("payment-processing")

# All logs within this context will include the trace ID
Log.info("Processing payment")
Log.debug("Validating card details")

# End the trace context when done
Log.end()

Configuration Options

When initializing Treebeard, you can configure several options:

Treebeard.init(
    api_key="your-api-key",
    endpoint="https://your-logging-endpoint.com/logs",
    debug_mode=True,  # Enable debug output
    batch_size=100,   # Max logs per batch
    batch_age=5.0,    # Max seconds before sending a batch
    threading_mode="thread"  # 'thread', 'eventlet', or 'gevent'
)

Thread Safety

Treebeard is thread-safe and supports different threading modes:

  • Standard Python threading (default)
  • Eventlet
  • Gevent

License

MIT License - see LICENSE file for details.

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

treebeardhq-0.4.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

treebeardhq-0.4.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file treebeardhq-0.4.0.tar.gz.

File metadata

  • Download URL: treebeardhq-0.4.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for treebeardhq-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5d53e8101aee17d7905e95002d6ca4c6c5ba34cff9cb30ca736b7c7465f929af
MD5 9cc70ebe5686c83b159cceb9f206ad56
BLAKE2b-256 f0380fb612e1a23c93e6bd4456ead5e4aa4b29f0fd842a057dc0f791f7068580

See more details on using hashes here.

File details

Details for the file treebeardhq-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: treebeardhq-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for treebeardhq-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9795c53aacfa7a529ed974c6872e9f535cbe7b625b6f544adae1eecbabc8f457
MD5 a71d01074977837f14ef2d7ad8d404fa
BLAKE2b-256 f7b56183fbb58d75fbdd1fcfefce18dc50d9cbab1367fab3586741f92e860f35

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page