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

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.3
File Size Uploaded Provenance Actions
clash_controller_api-0.1.3.tar.gz 19.9 kB With provenance Details for clash_controller_api-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 31.8 kB

Release files / clash_controller_api-0.1.3.tar.gz

Download URL clash_controller_api-0.1.3.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d793fc7f91869cca4a5b2d447a50c0d2de62b8b3d32fe65fe68b033ead828a5f
BLAKE2b-256 checksum
How to use checksums
c69e712680dda868db509fb388ae0521cc1a6b87c6ee0f4b5a7faf542da5a992
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 25, 2026.

Transparency log

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

Download URL clash_controller_api-0.1.3-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30887a7edba41e2ee2b0c1f06267569e1b87c1b9f65feea11c6489e15a6bc3b0
BLAKE2b-256 checksum
How to use checksums
129430dbbd91c114c4e5fd27a7d45ee6fee2fd31df1cfd5b292eb08a9af0b947
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 25, 2026.

Transparency log

Security for clash-controller-api 0.1.3

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for clash_controller_api-0.1.3.tar.gz

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 Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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