{"id":2100,"library":"line-bot-sdk","title":"LINE Messaging API SDK for Python","description":"The `line-bot-sdk` is the official Python SDK for interacting with the LINE Messaging API. It simplifies the development of LINE bots by providing classes for sending messages, handling events, and managing user interactions. The current version is 3.23.0, and it maintains a frequent release cadence, often with monthly or bi-monthly updates to support new API features.","status":"active","version":"3.23.0","language":"en","source_language":"en","source_url":"https://github.com/line/line-bot-sdk-python","tags":["LINE","bot","messaging","webhook","sdk","chat"],"install":[{"cmd":"pip install line-bot-sdk","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Commonly used for building webhook endpoints to receive LINE events.","package":"flask","optional":false},{"reason":"Used for data validation and parsing of API models.","package":"pydantic","optional":false}],"imports":[{"symbol":"LineBotApi","correct":"from linebot import LineBotApi"},{"symbol":"WebhookHandler","correct":"from linebot import WebhookHandler"},{"symbol":"MessageEvent","correct":"from linebot.models import MessageEvent"},{"symbol":"TextMessage","correct":"from linebot.models import TextMessage"},{"symbol":"TextSendMessage","correct":"from linebot.models import TextSendMessage"},{"symbol":"InvalidSignatureError","correct":"from linebot.exceptions import InvalidSignatureError"},{"note":"In v3.x, the LineBotApi class moved directly under the `linebot` namespace, removing the intermediate `.api` module found in v2.x.","wrong":"from linebot.api import LineBotApi","symbol":"LineBotApi (old)","correct":"from linebot import LineBotApi"}],"quickstart":{"code":"import os\nfrom flask import Flask, request, abort\n\nfrom linebot import (\n    LineBotApi, WebhookHandler\n)\nfrom linebot.exceptions import (\n    InvalidSignatureError\n)\nfrom linebot.models import (\n    MessageEvent, TextMessage, TextSendMessage\n)\n\napp = Flask(__name__)\n\n# Get channel_secret and channel_access_token from environment variable\nchannel_secret = os.environ.get('LINE_CHANNEL_SECRET', '')\nchannel_access_token = os.environ.get('LINE_CHANNEL_ACCESS_TOKEN', '')\n\nif not channel_secret:\n    print('Specify LINE_CHANNEL_SECRET as environment variable.')\n    exit(1)\nif not channel_access_token:\n    print('Specify LINE_CHANNEL_ACCESS_TOKEN as environment variable.')\n    exit(1)\n\nline_bot_api = LineBotApi(channel_access_token)\nhandler = WebhookHandler(channel_secret)\n\n@app.route(\"/callback\", methods=['POST'])\ndef callback():\n    # get X-Line-Signature header value\n    signature = request.headers['X-Line-Signature']\n\n    # get request body as text\n    body = request.get_data(as_text=True)\n    app.logger.info(\"Request body: \" + body)\n\n    # handle webhook body\n    try:\n        handler.handle(body, signature)\n    except InvalidSignatureError:\n        print(\"Invalid signature. Please check your channel access token/channel secret.\")\n        abort(400)\n\n    return 'OK'\n\n\n@handler.add(MessageEvent, message=TextMessage)\ndef handle_message(event):\n    line_bot_api.reply_message(\n        event.reply_token,\n        TextSendMessage(text=f\"You said: {event.message.text}\")\n    )\n\n\nif __name__ == \"__main__\":\n    app.run(port=8000)\n","lang":"python","description":"This Flask example sets up a basic LINE webhook. It receives messages, verifies the signature, and replies with the user's message. Ensure `LINE_CHANNEL_SECRET` and `LINE_CHANNEL_ACCESS_TOKEN` environment variables are set. This snippet requires Flask to be installed (`pip install Flask`)."},"warnings":[{"fix":"Review the official migration guide for v3.x. Update `LineBotApi` imports (e.g., `from linebot import LineBotApi`), `WebhookHandler` instantiation, and imports for `linebot.models` classes.","message":"Upgrading from `line-bot-sdk` v2.x to v3.x introduced significant breaking changes, including refactored `LineBotApi` instantiation, changes to `WebhookHandler` setup, and updated module paths for event and message models.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Remove any code referencing `ThingsEvent` or related LINE Things models. These functionalities are no longer supported by the LINE Messaging API.","message":"All LINE Things related webhook code (e.g., `ThingsEvent`, `ThingsContent`, `LinkThingsContent`) was removed due to the LINE Things service shutdown. Although released as a patch version, this is a breaking change for applications using these features.","severity":"breaking","affected_versions":">=3.18.1"},{"fix":"Ensure your `LINE_CHANNEL_SECRET` is correct and matches the one configured in your LINE Developers console. For local development or specific scenarios, v3.19.1+ introduced an option to skip verification during handler initialization: `WebhookHandler(channel_secret, skip_events_signature_verification=True)` (use with caution in production).","message":"Webhook signature verification is enabled by default and is crucial for security. However, misconfiguration or local development setups can lead to `InvalidSignatureError`. The `WebhookHandler` will raise this error if the signature cannot be verified.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}