{"id":16391742,"url":"https://github.com/williamfzc/pyatool","last_synced_at":"2025-08-09T02:15:56.558Z","repository":{"id":62578769,"uuid":"154817619","full_name":"williamfzc/pyatool","owner":"williamfzc","description":"python android toolkit 🔨","archived":false,"fork":false,"pushed_at":"2020-02-23T08:39:24.000Z","size":67,"stargazers_count":20,"open_issues_count":0,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-17T19:52:29.083Z","etag":null,"topics":["android","android-toolkit","python","python-android-toolkit","python3"],"latest_commit_sha":null,"homepage":"https://pyatool.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/williamfzc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-26T10:27:01.000Z","updated_at":"2024-02-02T03:24:56.000Z","dependencies_parsed_at":"2022-11-03T21:01:31.576Z","dependency_job_id":null,"html_url":"https://github.com/williamfzc/pyatool","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamfzc%2Fpyatool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamfzc%2Fpyatool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamfzc%2Fpyatool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamfzc%2Fpyatool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/williamfzc","download_url":"https://codeload.github.com/williamfzc/pyatool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244725582,"owners_count":20499632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-toolkit","python","python-android-toolkit","python3"],"created_at":"2024-10-11T04:47:13.819Z","updated_at":"2025-03-21T02:32:14.110Z","avatar_url":"https://github.com/williamfzc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IMPORTANT!!\n\n这个仓库不再维护了，不建议在正式环境里使用。替代品：\n\n- 跟这个库一样用subprocess实现的：[miniadb](https://github.com/williamfzc/minadb)\n- 用socket实现的：[adbutils](https://github.com/openatx/adbutils)\n\n---\n\n# pyatool\n\n[English Version](https://github.com/williamfzc/pyatool/blob/master/README_en.md)\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/5f6647a3121aa7d278ab/maintainability)](https://codeclimate.com/github/williamfzc/pyatool/maintainability)\n[![PyPI version](https://badge.fury.io/py/pyatool.svg)](https://badge.fury.io/py/pyatool)\n[![Downloads](https://pepy.tech/badge/pyatool)](https://pepy.tech/project/pyatool)\n[![Documentation Status](https://readthedocs.org/projects/pyatool/badge/?version=latest)](https://pyatool.readthedocs.io/en/latest/?badge=latest)\n\n\u003e python android toolkit 🔨\n\n## TL;DR\n\n直接用我们提供的标准库，对android设备进行各种操作。\n\n```python\nfrom pyatool import PYAToolkit\n\n# 初始化\ndevice = PYAToolkit('123456F')\n\n# 1. 直接调用\npackage_list = device.show_package()\n# 2. 或者 通过标准库（有自动补全，能够看到真实的方法实现）\npackage_list = device.std.show_package(toolkit=device)\n\n# 具体返回内容与调用的方法实现有关\nprint(package_list)\n```\n\n- 完整API参见[官方文档](https://pyatool.readthedocs.io/en/latest/)\n- 更多使用例子参见[demo.py](demo.py)\n\n## 安装\n\n请使用python3\n\n```python\npip install pyatool\n```\n\n## 目标\n\n- 简化日常开发中对设备的操作\n- 简洁的方法自定义与增删\n- 无痛融入到现有框架内\n- 减少重复工作，共享开发\n- 降低使用门槛，让所有人都可以快速上手\n\n## 还想要更多功能？\n\n### 自定义函数\n\npyatool提供的自定义API让开发者能够很方便地自定义需要的方法并挂载到上面。事实上，它自带的方法也是通过这种方法开发的。\n\n#### 简单定制\n\n例如，我们想自定义一个方法`show_package`用于展示已安装的包并做进一步处理：\n\n```python\n# 自定义需要的函数，传入名称与对应的adb命令\nPYAToolkit.bind_cmd(func_name='show_package', cmd='shell pm list package')\n\n# 初始化\ndevice_toolkit = PYAToolkit('123456F')\n\n# 然后你就可以直接使用了：\nresult = device_toolkit.show_package()\n\n# 它将执行下列命令并将执行结果返回到result：\nadb -s 123456F shell pm list package\n```\n\n再也不用看到那些烦人的`os`与`subprocess`。pyatool也覆盖了多台设备同时连接时的状况，所有烦人的`adb -s 123456F shell`再见~\n\n#### 高级定制\n\n当然，我们平时的需求不可能仅仅需要一条adb命令。pyatool也支持了更复杂的定制。例如我们需要一个函数，用于下载apk并安装到手机上：\n\n```python\ndef download_and_install(url, toolkit=None):\n    resp = requests.get(url)\n    if not resp.ok:\n        return False\n    with tempfile.NamedTemporaryFile('wb+', suffix='.apk', delete=False) as temp:\n        temp.write(resp.content)\n        temp.close()\n        toolkit.adb.run(['install', '-r', '-d', '-t', temp.name])\n        os.remove(temp.name)\n    return True\n\n\nPYAToolkit.bind_func(real_func=download_and_install)\n```\n\n其中，你的函数必须包含名为toolkit的可选参数，它将提供一些方法用于简化开发流程。例如，通过`toolkit.device_id`获取设备id、`toolkit.adb.run`用于执行adb命令。\n\n```python\n# 之后就可以自由使用\ndevice_toolkit = PYAToolkit('123456F')\ndevice_toolkit.download_and_install()\n```\n\n### 单次开发\n\npyatool如此设计的目的是为了能够尽量减少重复工作。为了方便所有人加入开发，往内置库中添加方法非常容易。\n\n如果你编写了一些好方法并希望将其合入pyatool标准库以方便后续使用，你只需要将你的方法添加到 `extras.py` 中，发起PR！\n\n## 具体案例\n\n在实际开发中，我们可能会频繁给设备安装apk；例如一旦设备连入电脑，自动给该设备安装apk。而结合[whenconnect](https://github.com/williamfzc/whenconnect)，只需要几行代码就可以实现：\n\n```python\nfrom pyatool import PYAToolkit\nfrom whenconnect import when_connect\n\n\nVERSION = 'v0.1.4'\nBASE_URL = r'https://github.com/williamfzc/simhand2/releases/download/{}/{}'\nTEST_APK = r'app-debug-androidTest.apk'\nMAIN_APK = r'app-debug.apk'\n\nTEST_DL_URL = BASE_URL.format(VERSION, TEST_APK)\nMAIN_DL_URL = BASE_URL.format(VERSION, MAIN_APK)\n\n\ndef install_sh(device_id):\n    pya = PYAToolkit(device_id)\n    pya.install_from(url=TEST_DL_URL)\n    pya.install_from(url=MAIN_DL_URL)\n    print('install simhand2 ok in {}'.format(device_id))\n\n\nwhen_connect(device='all', do=install_sh)\n```\n\n就完成了。在运行之后，一旦有android设备接入，将会自动为其安装apk。\n\n## 意见与建议\n\n欢迎issue与PR\n\n## 协议\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamfzc%2Fpyatool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilliamfzc%2Fpyatool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamfzc%2Fpyatool/lists"}