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.1.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.1-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: miaospeedlib-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 4dc1a1e1be094dddded259a237c7188f2e21af29aad18990e80626f43bedbcc3
MD5 bb54ae74af919347afa4a4c7713a96d9
BLAKE2b-256 e00008574361c6c2bd53620b3ad7d52a1e6a212b97ffdb6e2a88924a7e096b57

See more details on using hashes here.

File details

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

File metadata

  • Download URL: miaospeedlib-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 520a5efab0a5b2e755f8aeb6092142552c4b370173dc8839b1bfb8d0fc1476ae
MD5 cab7b2922a2c2d228f15331545a3f67c
BLAKE2b-256 802a5a9b7b77d8eed8dfb9a986951d2b2ed1e0093c12c8672519d141f9b35301

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