How alnyz/asyncline works
1. What this repository is
- AsyncLine is an async Python client library for the LINE messaging platform.
- It is not an app server; it is a reusable SDK that connects user code to LINE’s backend APIs and event stream.
2. Top-level architecture
- The public package is AsyncLine/.
- The central runtime object is the client exposed from main.py and imported as Client in the README.
- User code typically creates a client, logs in, registers async handlers, then starts the polling/stream loop.
3. Authentication and session management
- auth.py, connections.py, and config.py form the login/session boundary.
- The library supports multiple login paths mentioned in the README: token, email/password, QR login, and saved session/cert-based reuse.
- This layer is responsible for establishing and persisting the client identity used by downstream API calls.
4. Network and transport layer
- http_client.py is the general HTTP transport wrapper.
- lib/Gen/ contains generated service bindings and type definitions, which indicate the library talks to LINE services through generated RPC/Thrift-style clients rather than handwritten request objects.
- proto.py likely contains serialization or protocol helpers used by the transport and service layers.
5. Service-oriented feature modules
- The package is split into domain clients that map to LINE product areas:
- talk.py for messaging/chat actions
- buddy.py for contacts/buddy operations
- timeline.py for social/timeline features
- channel.py for channel-related APIs
- call.py for call/voice features
- shop.py for store/shop-related data
- liff.py for LIFF integration
- These modules are thin feature boundaries on top of the shared auth/network stack.
6. Event ingestion and bot loop
- poll.py and handler.py are the event-processing core.
- The README’s cli.poll.streams() and @cli.hooks(...) pattern shows the runtime is built around:
- consuming incoming events from LINE
- matching them through filters
- dispatching them to async callback handlers
- filters.py provides event predicates such as command matching.
7. Callback-driven application model
- User bots are assembled by registering handlers against event types.
- The examples directory demonstrates common bot shapes:
- simple echo bot
- conversation bot
- content mutation/send examples
- a plugin-based bot layout
- This makes the library feel like an event-driven framework layered on top of the LINE client.
8. Models and shared domain objects
- models.py holds shared data structures used across service modules and handlers.
- lib/Gen/ttypes.py and lib/Gen/liff/ttypes.py contain generated request/response/data types, which are part of the contract between the client and LINE’s APIs.
- This separation keeps transport payloads distinct from higher-level client logic.
9. Security and message handling
- e2ee.py suggests optional end-to-end encryption support for message content.
- log.py centralizes logging.
- buddy.py, talk.py, and poll.py likely rely on these lower-level utilities when processing inbound/outbound message payloads.
10. LIFF and generated API surface
- liff.py plus lib/Gen/liff/ provide a separate integration path for LINE Front-end Framework endpoints.
- The presence of generated constants and service classes in lib/Gen/f_LineService.py and lib/Gen/liff/f_LiffService.py indicates two backend API surfaces are supported: core LINE services and LIFF services.
11. Repository usage boundary
- examples/ is the main consumer-facing boundary of the repo.
- setup.py, requirements.txt, setup.cfg, and .travis.yml indicate standard Python packaging and CI, but they do not change the runtime architecture.
- The library targets Python 3.6/3.7 and relies heavily on async/await.
12. How data flows through the system
- Outbound path: user code -> Client -> auth/session -> feature module (talk, timeline, etc.) -> HTTP/RPC transport -> LINE backend.
- Inbound path: LINE backend -> poll/stream connection -> handler/filter pipeline -> user async callback -> optional outbound response through the same client.
- The main architectural boundary is therefore between user bot logic and LINE service access, with the client package mediating both directions.
Main entry points: main.py Client · http_client.py HTTP · talk.py Talk · handler.py Handler
Components 28
AsyncLine
Core client library package
- Client · Primary async LINE client used by user code
AsyncLine/main.py - Auth · Login and identity/session setup
AsyncLine/auth.py - Conn · Connection/session reuse and login path support
AsyncLine/connections.py - Config · Client configuration and runtime options
AsyncLine/config.py - HTTP · Shared HTTP transport wrapper
AsyncLine/http_client.py - Proto · Serialization and protocol utilities
AsyncLine/proto.py - Models · Common data structures used across modules
AsyncLine/models.py - Poll · Incoming event ingestion and polling loop
AsyncLine/poll.py - Handler · Routes events to async callbacks
AsyncLine/handler.py - Filters · Event matching and command predicates
AsyncLine/filters.py - Talk · Messaging and chat operations
AsyncLine/talk.py - Buddy · Buddy and contact operations
AsyncLine/buddy.py - Timeline · Timeline and social feature operations
AsyncLine/timeline.py - Channel · Channel-related operations
AsyncLine/channel.py - Call · Calling and voice-related operations
AsyncLine/call.py - Shop · Store and shop-related operations
AsyncLine/shop.py - LIFF · LIFF integration surface
AsyncLine/liff.py - E2EE · Optional end-to-end encryption support
AsyncLine/e2ee.py - Log · Central logging helpers
AsyncLine/log.py
Generated API
Auto-generated LINE and LIFF service bindings
- LINE Gen · Generated core LINE service definitions
AsyncLine/lib/Gen/f_LineService.py - LINE Types · Generated core API request and response types
AsyncLine/lib/Gen/ttypes.py - LIFF Gen · Generated LIFF service definitions
AsyncLine/lib/Gen/liff/f_LiffService.py - LIFF Types · Generated LIFF API request and response types
AsyncLine/lib/Gen/liff/ttypes.py
Examples
Consumer-facing bot and usage patterns
- Echo · Simple message echo example
examples/echo.py - Chat bot · Conversation example
examples/conversation.py - Send content · Content sending example
examples/send_content.py - Change content · Content mutation example
examples/change_content.py - Plugins · Plugin-based bot layout
examples/plugins_example/bot.py
Connections 33
- Client → Auth: login · Establishes client identity
- Client → Conn: reuse · Manages session and connection reuse
- Client → Config: configure · Reads runtime settings
- Client → Poll: stream · Starts event polling or streaming
- Client → Talk: messages · Routes messaging actions
- Client → Buddy: contacts · Routes buddy operations
- Client → Timeline: timeline · Routes timeline operations
- Client → Channel: channels · Routes channel operations
- Client → Call: calls · Routes call operations
- Client → Shop: shop · Routes commerce operations
- Client → LIFF: liff · Routes LIFF operations
- Talk → HTTP: transport · Uses shared HTTP transport
- Buddy → HTTP: transport · Uses shared HTTP transport
- Timeline → HTTP: transport · Uses shared HTTP transport
- Channel → HTTP: transport · Uses shared HTTP transport
- Call → HTTP: transport · Uses shared HTTP transport
- Shop → HTTP: transport · Uses shared HTTP transport
- LIFF → HTTP: transport · Uses shared HTTP transport
- HTTP → Proto: encode · Applies protocol helpers
- Talk → LINE Gen: rpc · Calls generated core LINE service
- Talk → LINE Types: types · Uses generated core API types
- LIFF → LIFF Gen: rpc · Calls generated LIFF service
- LIFF → LIFF Types: types · Uses generated LIFF API types
- Poll → Handler: dispatch · Hands incoming events to callbacks
- Handler → Filters: match · Selects callbacks by predicates
- Handler → Models: events · Consumes shared domain objects
- Poll → E2EE: decrypt · May decrypt protected message content
- Client → Log: log · Uses centralized logging
- Echo → Client: uses · Example client entry point
- Chat bot → Handler: hooks · Registers event callbacks
- Send content → Talk: send · Demonstrates outbound messaging
- Change content → Talk: mutate · Demonstrates content changes via messaging APIs
- Plugins → Handler: plugins · Shows plugin-based event dispatch