Weblate 的 Python API

安裝

The Python API is shipped separately as the Weblate Client package:

pip install wlc

wlc

WeblateException

exception wlc.WeblateException

適用於所有例外的基底類別。

Weblate

class wlc.Weblate(key='', url='http://127.0.0.1:8000/api/', config=None, retries=0, status_forcelist=None, allowed_methods=None, backoff_factor=0, timeout=300)
參數:
  • key (str) -- 使用者金鑰

  • url (str) -- API server URL.

  • config (wlc.config.WeblateConfig) -- 配置物件,覆寫任何其他參數。

  • retries (int) -- HTTP 重試總次數。

  • status_forcelist (list) -- 應該觸發重試的 HTTP 狀態代碼。

  • allowed_methods (list) -- HTTP methods that may be retried.

  • backoff_factor (float) -- Retry backoff factor passed to urllib3.

  • timeout (int) -- HTTP request timeout in seconds.

Access class to the API, define API key and optionally API URL.

get(path)
參數:

path (str) -- 請求路徑

回傳型別:

object

執行單個 API GET 呼叫。

post(path, **kwargs)
參數:

path (str) -- 請求路徑

回傳型別:

object

Performs a single API POST call.

wlc.config

exception wlc.config.WLCConfigurationError

Raised when configuration can not be loaded or combines an unscoped API key with an automatically discovered project API URL.

WeblateConfig

class wlc.config.WeblateConfig(section='weblate')
參數:

section (str) -- 要使用的配置部分

遵循 XDG 規範的配置檔案解析器。

load(path=None)
參數:

path (str) -- 載入配置的路徑。

Loads configuration from path when it is specified. Otherwise it loads the discovered global configuration file and then the nearest project configuration file (.weblate, .weblate.ini, or weblate.ini) from the current directory or its parents.

validate_url_key()

Validates the resolved API URL and key sources.

When the API URL comes from an automatically discovered project configuration file, unscoped keys must pin the destination explicitly: WLC_KEY requires WLC_URL, and a key set through the command-line configuration path requires an explicit URL from the same path. URL-scoped [keys] entries continue to work with project configuration.

get_url_key()
回傳:

tuple with the resolved API URL and API key

Returns the resolved API URL and key and performs the same validation as validate_url_key().

wlc.main

wlc.main.main(settings=None, stdout=None, args=None)
參數:
  • settings (list) -- Settings to override as list of tuples

  • stdout (object) -- 用於列印輸出的 stdout 檔案物件,預設使用 sys.stdout

  • args (list) -- 要處理的命令列引數,預設使用 sys.args

命令列介面的主要入口點。

@wlc.main.register_command(command)

Decorator to register Command class in main parser used by main().

Command

class wlc.main.Command(args, config, stdout=None)

用於呼叫指令的主類別。