Skip to main content

line.py

Python 非阻塞式 LINE Messaging API 串接, 輕鬆快速的製作 LINE 機器人
⚠️ 此 package 目前僅供(我)個人使用, 所以並沒有 cover 全部的 API, 如果有其他人想用的話, 我再加

安裝

pip install line-messaging-api

快速入門

import asyncio
from line import Bot, Cog, command, Context

class MyCog(Cog):
   def __init__(self, bot: Bot) -> None:
       super().__init__(bot)
   
   @command
   async def hello(self, ctx: Context) -> None:
       await ctx.reply_text("Hello, world!")

async def main():
   bot = Bot(channel_secret="YOUR_CHANNEL_SECRET", access_token="YOUR_ACCESS_TOKEN")
   bot.add_cog(MyCog(bot))
   await bot.run()

asyncio.run(main())

功能

  • 使用 aiohttp 及 asyncio, 完全非阻塞式運行 (async/await)
  • 底層使用 LINE 官方 Python SDK
  • 完整的 type hints (PEP 484)
  • 簡單上手, 快速製作 LINE 機器人

文檔

其他

LINE 已經有 SDK 了, 為什麼還要寫 line.py?

  • v3 的 SDK 可能因為是從 API 自動生成 model 的關係, 有非常糟糕的 typing 問題, 使用 line.py 完全不會遇到奇怪的紅線跟需要大量使用 type: ignore 的問題
  • 學習難度高, 不易使用, 不適合新手
  • 沒有一個快速新增指令的方法, 導致程式碼很冗長

你是不是抄襲 discord.py?

對。
但是 discord.py 的程式碼太高深了我看不懂, 所以只是參考概念 (例如 cog, 一些 function 的名稱, 新增指令的方式), 然後慢慢刻出來 line.py。

聯絡

有疑問可以加我 Discord:@seria_ati

Download files

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

Source Distribution

line_messaging_api-0.9.0.tar.gz (70.2 kB view details)

Uploaded Source

Built Distribution

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

line_messaging_api-0.9.0-py3-none-any.whl (42.7 kB view details)

Uploaded Python 3

File details

Details for the file line_messaging_api-0.9.0.tar.gz.

File metadata

  • Download URL: line_messaging_api-0.9.0.tar.gz
  • Upload date:
  • Size: 70.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.18

File hashes

Hashes for line_messaging_api-0.9.0.tar.gz
Algorithm Hash digest
SHA256 d85004648afa3b65ab99a3741f276f31ee1c3aeeeeec1cc77ab3a030fc7b4bba
MD5 09b258cedd9a91eb9555ad834bb6c488
BLAKE2b-256 1e19bf1ae43c369fd03f4cf083d5dddb4f5fc44858464285a54e1a3a02a06ca6

See more details on using hashes here.

File details

Details for the file line_messaging_api-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for line_messaging_api-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d044437c262f19345212dd038459cdbfabf3d629f9b50f2581cae823eb5c4581
MD5 c517558cd628035495ba330938fcc898
BLAKE2b-256 bca8b55567a97dd32d31314aa96f47c1340f5a52e4caf97b482e991681ce8587

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 files

0.8.19

2 files

Supported by

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