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.1

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.1
File Size Uploaded
clash_controller_api-0.1.1.tar.gz 19.5 kB Details

Built distribution (wheel)

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

Total release size: 31.1 kB

Release files / clash_controller_api-0.1.1.tar.gz

Download URL clash_controller_api-0.1.1.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
661d1ecf224ee5b226155671a7343f7ea7aaf75a249a2e8a5ec82b5fab5709fd
BLAKE2b-256 checksum
How to use checksums
75648ae21225949038e15984d7e1afaff88eb91b0d0f14520131e6959359663d
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.1-py3-none-any.whl

Download URL clash_controller_api-0.1.1-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38b5e44b3ef5913e7374adf53d70225b21e394905312bde087bf0869acf6bee1
BLAKE2b-256 checksum
How to use checksums
d552cc2740ba51e54a0f1730b2ca404b0ce2db70afb0da2219891a440ae024b1
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

0.1.2

2 release files

This release

0.1.1 This release

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