LINE Messaging API enables bot development for LINE, the dominant messaging platform in Japan, Thailand, and Taiwan with 196M+ monthly users. Official SDKs exist for Python and Node.js. Primary documentation is in Japanese — English docs are complete but may lag Japanese versions.
Install & Compatibility
Where this runs
tested against v? · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.925 runs
installs and imports cleanly · install 0.0s · import 1.854s · 117.3MB
glibcpy 3.10–3.925 runs
installs and imports cleanly · install 7.7s · import 1.670s · 189MB
156MB installed
● package 156MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
WebhookHandler (Python v3)
✓ from linebot.v3 import WebhookHandler
✗ from linebot import WebhookHandler
linebot v2 imports (no .v3) still work but are legacy. All new code should use linebot.v3 namespace.
MessagingApi (Python v3)
✓ from linebot.v3.messaging import Configuration, ApiClient, MessagingApi
✗ from linebot import LineBotApi
LineBotApi is the v2 class. Replaced by MessagingApi in v3. Both still work but v3 is current.
Minimal LINE bot webhook handler using linebot.v3 SDK with Flask.
from flask import Flask, request, abort
from linebot.v3 import WebhookHandler
from linebot.v3.exceptions import InvalidSignatureError
from linebot.v3.messaging import (
Configuration, ApiClient, MessagingApi,
ReplyMessageRequest, TextMessage
)
from linebot.v3.webhooks import MessageEvent, TextMessageContent
app = Flask(__name__)
configuration = Configuration(access_token='YOUR_CHANNEL_ACCESS_TOKEN')
handler = WebhookHandler('YOUR_CHANNEL_SECRET')
@app.route('/callback', methods=['POST'])
def callback():
signature = request.headers['X-Line-Signature']
body = request.get_data(as_text=True)
try:
handler.handle(body, signature)
except InvalidSignatureError:
abort(400)
return 'OK'
@handler.add(MessageEvent, message=TextMessageContent)
def handle_message(event):
with ApiClient(configuration) as api_client:
line_bot_api = MessagingApi(api_client)
line_bot_api.reply_message(
ReplyMessageRequest(
reply_token=event.reply_token,
messages=[TextMessage(text=event.message.text)]
)
)
if __name__ == '__main__':
app.run()
Errors
Common errors & fixes
InvalidSignatureError: <InvalidSignatureError [Invalid signature. signature=...]>
The webhook signature sent by the LINE Platform does not match the signature calculated by your bot server, often due to an incorrect Channel Secret or modifications to the request body before verification.
fixEnsure the 'Channel Secret' in your bot application exactly matches the one in the LINE Developers Console, and use the raw request body without any modification (e.g., pretty-printing JSON) for signature validation with UTF-8 encoding.
LineBotApiError [Authentication failed due to the following reason: invalid token. Confirm that the access token in the authorization...]
The Channel Access Token used for API requests is invalid, expired, revoked, or incorrectly configured.
fixVerify that the 'Channel Access Token' in your code is correct and currently valid in the LINE Developers Console. If it's a short-lived token, ensure it hasn't expired, and if it's been reissued or revoked, obtain a new valid token.
Request failed with status code 400
This error, often accompanied by an 'invalid replyToken', indicates an issue with the request payload sent to the LINE Messaging API, such as using an expired, already used, or incorrectly formatted reply token or message object.
fixEnsure the 'reply_token' is used immediately after receiving the event and has not been used before, as reply tokens are single-use and time-sensitive. Also, verify that the message objects in your request adhere to the LINE Messaging API specifications.
ModuleNotFoundError: No module named 'linebot'
The 'line-bot-sdk' Python package has not been installed or is not accessible in the current Python environment.
fixInstall the library using pip: `pip install line-bot-sdk`. Confirm that your script is being executed within the Python environment where the package was installed.
LineBotSdkDeprecatedIn30: Call to deprecated method ... (Use 'from linebot.v3.messaging import MessagingApi' and 'MessagingApi(...)....' instead. See https://github.com/line/line-bot-sdk-python/blob/master/README.rst for more details.) -- Deprecated since version 3.0.0.
Your code is using older modules or methods from the `linebot` (version 2.x) namespace, but a newer version of the SDK (3.x) is installed, which has introduced a `v3` namespace with breaking changes.
fixUpdate your imports and code to use the `linebot.v3` modules and classes as specified in the deprecation warning, adapting your code to the new API structure.
Audit
Dependencies
flaskoptionalRequired for webhook server in Python examples. Any WSGI framework works.