Skip to main content

LINE Official User API wrapper library for Python

Project description

LINELib

LINELibは、LINE公式アカウントのチャット・認証・自動化をPythonから簡単に扱えるライブラリです

特徴

  • Seleniumによる認証・Cookie管理
  • 複数Bot・チャットの取得・送信・監視
  • 有料のメッセージ送信を使わずにメッセージを送信する
  • ⬆️Push無限

インストール

pip install lineoa

使い方

1. 初回認証(SeleniumによるCookie保存)

from LINELib.linebot import LineBot
COOKIE_PATH = os.environ.get("LINEOA_COOKIE_PATH", "lineoa_cookie.json")
bot = LineBot(storage=COOKIE_PATH, ping_secs=20)  # 初回はSeleniumで手動ログイン
#storageを設定することによりcookieを保存

2. 以降はCookie自動復元

from LINELib.linebot import LineBot
COOKIE_PATH = os.environ.get("LINEOA_COOKIE_PATH", "lineoa_cookie.json")
bot = LineBot(storage=COOKIE_PATH, ping_secs=20)
#次回からcookieを利用してログイン

3. Bot一覧・チャット一覧取得

bots = bot.bots.ids  # {bot名: botId}
chats = bot.getChats(bot_id)  # ユーザーchatId一覧

4. メッセージ送信

bot.sendMessage(bot_id, user_id, "こんにちは!")

5. 画像送信

bot.sendFile(bot_id, chat_id, "sample.png")

6. メッセージ監視

bot.listen(botid="U*****")

7. リプライ返信

bot.sendMessage(bot_id=bot_id, chat_id=chat_id, text="りぷらい", quoteToken=quoteToken)

8. グループ内のメンバー全取得

bot.getMembers(bot_id=bot_id, chat_id=chat_id)

9. 簡単なpolling例

from LINELib.linebot import LineBot

bot = LineBot(
    cookie_path="lineoa-storage.json",  # cookieファイルパスのみ指定
    ping_secs=20
)

BOT_ID = "U****"

@bot.event
def on_message(event):
    payload = event.get('payload', {})
    chat_payload = payload.get('payload', {})
    message = chat_payload.get('message', {})
    text = message.get('text', '')
    if message.get('type') == 'text' and text == "ping":
        bot.sendMessage(bot_id=payload.get('botId'), chat_id=payload.get('chatId'), text="pong!")

if __name__ == "__main__":
    bot.listen(botid=BOT_ID)

サンプル

example を参照してください。

クラス構成

  • linebot ... モダンな設計思想に基づくクラス
  • LINELib ... 全機能統合のメインクラス
  • AuthService ... 認証・Cookie管理
  • ChatService ... チャットAPI
  • LINEOAError ... 例外クラス

注意事項

自己責任での使用 20message /1m のレートリミットが存在

ライセンス

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lineoa-5.5.7.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

lineoa-5.5.7-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file lineoa-5.5.7.tar.gz.

File metadata

  • Download URL: lineoa-5.5.7.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lineoa-5.5.7.tar.gz
Algorithm Hash digest
SHA256 863c01bc8400696f34b636b920b47d4702da28bc1d7155ebce7ee0361c5c8031
MD5 2b860c49695fd3aa03c550e5851f0c24
BLAKE2b-256 0e9b92e2f54ad9567b349b08cc527c9f6b64ce380b96b08c59b5807b63f2c446

See more details on using hashes here.

Provenance

The following attestation bundles were made for lineoa-5.5.7.tar.gz:

Publisher: python-publish.yml on Madoa5561/LINELib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lineoa-5.5.7-py3-none-any.whl.

File metadata

  • Download URL: lineoa-5.5.7-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lineoa-5.5.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2c1d37b7f96d574aafb00f9a84b1e7743113df832838661e5826c5491e5af4aa
MD5 6042bd31b99444ef31f235ff458de135
BLAKE2b-256 9284a228504e594898dc1085d33827a3e0d9a40f93c512bc7bbfb5cade3bf9d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for lineoa-5.5.7-py3-none-any.whl:

Publisher: python-publish.yml on Madoa5561/LINELib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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