Skip to main content

Clash Controller API

Async Python client for Clash-compatible external controller APIs.

The client currently targets Clash, Clash Premium, Clash Meta, Mihomo, clash-rs, and sing-box's Clash API compatibility layer. Endpoint capabilities are detected at runtime because support differs between cores.

Installation

python -m pip install clash-controller-api

The distribution name is clash-controller-api; the import name is clash_controller_api. The caller owns the aiohttp.ClientSession passed to ClashAPI and remains responsible for closing it.

Usage

import asyncio

import aiohttp
from clash_controller_api import ClashAPI


async def main():
    async with aiohttp.ClientSession() as session:
        api = ClashAPI("http://localhost:9090", "your-token", session=session)
        await api.async_validate_connection()
        result = await api.async_fetch_data()
        print(result.data)
        print(result.errors)


asyncio.run(main())

async_fetch_data() detects and caches endpoint capabilities automatically. Its FetchResult contains successful responses in data and per-endpoint exceptions in errors. Direct requests raise APIAuthError, APIConnectionError (including APITimeoutError), or APIClientError for invalid responses. All inherit from ClashAPIError.

The client does not retry requests. Polling may fall back between supported WebSocket and HTTP transports; authentication failures stop that fallback.

Development

Python 3.11 or newer is required.

python -m pip install -e ".[test]"
pytest

Run the pinned real-core contract against all supported cores with:

python tests/run.py system

Metadata

Release files for clash-controller-api 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clash-controller-api 0.1.2
File Size Uploaded
clash_controller_api-0.1.2.tar.gz 19.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for clash-controller-api 0.1.2
File Interpreter ABI Platform
clash_controller_api-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 31.5 kB

Release files / clash_controller_api-0.1.2.tar.gz

Download URL clash_controller_api-0.1.2.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
61c6b666e1a1c11213ce9542d220e7130fc8d601cfe51b7e0d6b0eaf3eb01469
BLAKE2b-256 checksum
How to use checksums
4fbd12c260cc687e7b20e43e5bb1b0c87c1f394f1d24ec14801daa219a4c62ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release files / clash_controller_api-0.1.2-py3-none-any.whl

Download URL clash_controller_api-0.1.2-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf0a0bd3b65996857d4427ad8e40e4393d2b4ab36016db00b06884b4c7af3c40
BLAKE2b-256 checksum
How to use checksums
9c1fb21e0258a538d976350c6fb948aa6fcaa3977591dc12749eb6994a323e78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page