Skip to content

Add unified client [DRAFT]#985

Closed
habara-k wants to merge 19 commits intomasterfrom
unified-client
Closed

Add unified client [DRAFT]#985
habara-k wants to merge 19 commits intomasterfrom
unified-client

Conversation

@habara-k
Copy link
Copy Markdown
Contributor

@habara-k habara-k commented Apr 10, 2026

Motivation

The current v3 SDK is auto-generated from the LINE OpenAPI specs, where each YAML file produces a separate client class (e.g., MessagingApi, ManageAudience, Insight, etc.). This means users must instantiate and manage multiple clients individually, leading to verbose boilerplate:

from linebot.v3.messaging import Configuration, ApiClient, MessagingApi
from linebot.v3.insight import Configuration as InsightConfiguration, ApiClient as InsightApiClient, Insight

messaging_config = Configuration(access_token='TOKEN')
insight_config = InsightConfiguration(access_token='TOKEN')

with ApiClient(messaging_config) as api_client, InsightApiClient(insight_config) as insight_client:
    messaging_api = MessagingApi(api_client)
    insight_api = Insight(insight_client)
    ...

This PR introduces a unified client that wraps all per-domain clients behind a single entry point:

from linebot.v3 import LineBotClient

with LineBotClient(channel_access_token='TOKEN') as client:
    client.push_message(...)
    client.get_number_of_followers(...)

What's changed

  • Add tools/generate_unified_client.py — a script that introspects the per-domain API classes and generates LineBotClient / AsyncLineBotClient wrapper classes. This script is hooked into generate-code.py so it runs automatically after the OpenAPI generator completes.
  • Add LineBotClient and AsyncLineBotClient (auto-generated) under linebot.v3
  • Update all examples (flask-echo, flask-kitchensink, aiohttp-echo, fastapi-echo, rich-menu, simple-server-echo) and README.rst to use the unified client
  • Add MIGRATION.md — comprehensive migration guide from legacy linebot (v2) to linebot.v3, covering client construction, imports, method mapping, error handling, and a full before/after echo-bot example
  • Deprecate all legacy linebot.models and linebot.http_client classes with @deprecated decorator pointing users to linebot.v3 equivalents
  • Add Sphinx doc generation for v3 modules
  • Add tests for both sync and async unified clients

Design decisions

async_req parameter is intentionally excluded

The OpenAPI-generated per-domain clients (e.g., AsyncMessagingApi) support an async_req parameter on every method. When async_req=True, the request runs in a thread pool and returns an AsyncResult:

thread = messaging_api.push_message(req, async_req=True)
result = thread.get()

This is a thread-based concurrency escape hatch for users of the sync client who want non-blocking behavior without asyncio. The unified clients intentionally drop this parameter because neither use case needs it:

  • LineBotClient — designed for straightforward synchronous usage. Users who need thread-based concurrency can access the underlying per-domain clients directly (e.g., client._messaging_api).
  • AsyncLineBotClient — already fully async via asyncio/aiohttp. The thread pool path would be counterproductive.

How to review

  • Doc: Build and preview locally:
    cd docs && make html && open build/html/index.html
img1 img2

@habara-k habara-k force-pushed the unified-client branch 5 times, most recently from d3991b0 to 11d5313 Compare April 10, 2026 09:48
@habara-k habara-k self-assigned this Apr 13, 2026
@habara-k habara-k changed the title Add unified client Add unified client [DRAFT] Apr 14, 2026
@habara-k habara-k closed this Apr 14, 2026
@habara-k habara-k deleted the unified-client branch April 14, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant