Last update: 2025-05-09T07:54:31.000Z
Content:
---
title: "Send Python logs to Tinybird · Tinybird Docs"
theme-color: "#171612"
description: "Send your Python logs to Tinybird using the standard logging library and Tinybird Python SDK."
inkeep:version: "forward"
---




# Send Python logs to Tinybird [¶](https://www.tinybird.co/docs/forward/get-data-in/guides/python-sdk#send-python-logs-to-tinybird)

Copy as MD You can send logs from a Python application or service to Tinybird using the standard Python logging library and the [tinybird-python-sdk](https://pypi.org/project/tinybird-python-sdk/).

## Prerequisites [¶](https://www.tinybird.co/docs/forward/get-data-in/guides/python-sdk#prerequisites)

To use the Tinybird Python SDK you need Python 3.11 or higher.

## Configure the logging handler [¶](https://www.tinybird.co/docs/forward/get-data-in/guides/python-sdk#configure-the-logging-handler)

First, configure a Tinybird logging handler in your application. For example:

import logging
from multiprocessing import Queue
from tb.logger import TinybirdLoggingQueueHandler

logger = logging.getLogger('your-logger-name')
handler = TinybirdLoggingHandler(<YOUR_TB_API_URL>, <YOUR_TB_WRITE_TOKEN>, 'your-app-name')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler) Each time you call the logger, the SDK sends an event to the `tb_logs` data source in your workspace.

To configure the data source name, initialize the `TinybirdLoggingHandler` like this:

handler = TinybirdLoggingHandler(<YOUR_TB_API_URL>, <YOUR_TB_WRITE_TOKEN>, 'your-app-name', ds_name="your_tb_ds_name")
## Non-blocking logging [¶](https://www.tinybird.co/docs/forward/get-data-in/guides/python-sdk#non-blocking-logging)

If you want to avoid blocking the main thread, use a queue to send the logs to a different thread. For example:

import logging
from multiprocessing import Queue
from tb.logger import TinybirdLoggingQueueHandler
from dotenv import load_dotenv

load_dotenv()
TB_API_URL = os.getenv("<YOUR_TB_API_URL>")
TB_WRITE_TOKEN = os.getenv("<YOUR_TB_WRITE_TOKEN>")

logger = logging.getLogger('your-logger-name')
handler = TinybirdLoggingQueueHandler(Queue(-1), TB_API_URL, TB_WRITE_TOKEN, 'your-app-name', ds_name="your_tb_ds_name")
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
