Skip to main content

MiaoSpeed Client Library Implementations for Python.

Project description

MiaoSpeedLib

MiaoSpeed Client Library Implementations for Python.

Usage

from pypi:

pip install miaospeedlib -U

example:

import asyncio
import miaospeedlib as miaolib


slave_cfg = {
    "id": "local",
    "comment": "Local",
    "hidden": False,
    "token": "miaospeed-dev",
    "type": "miaospeed",
    "address": "127.0.0.1:8765",
    "option": {
        "downloadDuration": 8,
        "downloadThreading": 4,
        "pingAverageOver": 20,
        "taskRetry": 3,
        "downloadURL": "https://dl.google.com/dl/android/studio/install/3.4.1.0/android-studio-ide-183.5522156-windows.exe",
        "pingAddress": "http://www.google.com/generate_204",
        "stunURL": "udp://stunserver2024.stunprotocol.org:3478",
        "taskTimeout": 3000,
        "dnsServer": [
            "119.29.29.29:53",
            "223.5.5.5:53"
        ],
        "apiVersion": 2
    },
    "skipCertVerify": True,
    "tls": False,
    "invoker": "114514",
    "buildtoken": "MIAOKO4|580JxAo049R|GEnERAl|1X571R930|T0kEN",
    "path": "/miaospeed"
}

local_slave = miaolib.MiaoSpeedSlave().from_obj(slave_cfg)
isalive = asyncio.run(miaolib.MiaoSpeed.isalive(local_slave))
print("miaospeed slave isalive:", isalive)

For other miaospeed branch:

import yaml
import miaospeedlib as miaolib


slave_cfg = {
    "id": "local",
    "comment": "Local",
    "hidden": False,
    "token": "miaospeed-dev",
    "type": "miaospeed",
    "address": "127.0.0.1:8765",
    "option": {
        "downloadDuration": 8,
        "downloadThreading": 4,
        "pingAverageOver": 20,
        "taskRetry": 3,
        "downloadURL": "https://dl.google.com/dl/android/studio/install/3.4.1.0/android-studio-ide-183.5522156-windows.exe",
        "pingAddress": "http://www.google.com/generate_204",
        "stunURL": "udp://stunserver2024.stunprotocol.org:3478",
        "taskTimeout": 3000,
        "dnsServer": [
            "119.29.29.29:53",
            "223.5.5.5:53"
        ],
        "apiVersion": 1 # change to 1 for other branch
    },
    "skipCertVerify": True, # self-signed certificate
    "tls": True, # recommended 
    "invoker": "114514",
    "buildtoken": "MIAOKO4|580JxAo049R|GEnERAl|1X571R930|T0kEN",
    "path": "/miaospeed"
}
async def miaospeed_test(_nodes):
    srme_list = [
        miaolib.SlaveRequestMatrixEntry(miaolib.SlaveRequestMatrixType.TEST_PING_RTT, ""),
        miaolib.SlaveRequestMatrixEntry(miaolib.SlaveRequestMatrixType.TEST_PING_CONN, ""),
        miaolib.SlaveRequestMatrixEntry(miaolib.SlaveRequestMatrixType.GEOIP_OUTBOUND, ""),
        miaolib.SlaveRequestMatrixEntry(miaolib.SlaveRequestMatrixType.GEOIP_INBOUND, ""),
        # miaolib.SlaveRequestMatrixEntry(
        #     Type=miaolib.SlaveRequestMatrixType.TEST_SCRIPT,
        #     Params="IP"
        # ), # add script test if needed
    ]
    msreq = miaolib.SlaveRequest(
        miaolib.SlaveRequestBasics(
            ID="114514",
            Slave="114514",
            SlaveName="slave",
            Invoker="11111111111",
            Version="4.3.3"
        ),
        miaolib.SlaveRequestOptions(Matrices=srme_list),
    )
    msreq.Configs.patch_version() # for other branch
    # with open("./iptype.js", 'r', encoding="UTF-8") as _fp:
    #     js_content = _fp.read() # read script content , name='IP', ID='IP'
    # msreq.Configs.Scripts.append(miaolib.Script(ID="IP", Content=js_content)) # add script to SlaveRequest.Configs.Scripts
    ms = miaolib.MiaoSpeed(slave_config=miaolib.MiaoSpeedSlave().from_obj(slave_cfg), slave_request=msreq,
                                proxyconfig=_nodes)
    # You can add DNS servers to SlaveRequest.Configs.DNSServers, e.g.
    # ms.SlaveRequest.Configs.DNSServers.append("119.29.29.29:53")

    res, start_time = await ms.start()
    return res, start_time
# load clash nodes from Clash.yaml
with open(f"Clash.yaml", 'r', encoding="UTF-8") as fp:
    nodes = yaml.safe_load(fp)['proxies']
print("Your Clash nodes:\n", nodes)
result, _ = miaospeed_test(nodes)
print("result of miaospeed:\n", result)

Tips

  • You shoud rewrite the MiaoSpeed.start() method to fit your own test logic.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

miaospeedlib-0.1.2.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

miaospeedlib-0.1.2-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file miaospeedlib-0.1.2.tar.gz.

File metadata

  • Download URL: miaospeedlib-0.1.2.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for miaospeedlib-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9385bd9bf8cd57603a167b55d6e3eea7be48e1af0d57cb5bc69b46b1686b10ca
MD5 1d08f1b3747bcc0df526e68380086c18
BLAKE2b-256 fefc0c1ecf3870b65da24aafc7b3618a5c2fb305855e9a64ee8e0ef234a07dce

See more details on using hashes here.

File details

Details for the file miaospeedlib-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: miaospeedlib-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 31.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for miaospeedlib-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cfb7c92ddbafd33e6a3a3771d6be084a77bb0727a464a0e4eb1c5291ced0e34b
MD5 09493e086dfb3e210c0e12457f287552
BLAKE2b-256 a1c3f616ec2140f5a06e538b3c957bd139db61d16b2749fc7a280c288c1c22a3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page