Skip to main content

Run Android ADB over SSH on a remote host with a simple Python API

Project description

sshadb

Run Android ADB over SSH on a remote host with a simple Python API.

Overview

sshadb는 로컬 PC에서 SSH로 원격 서버에 접속해, 원격 서버에서 ADB 명령을 실행하고 그 결과를 로컬 Python API로 다룰 수 있게 해주는 경량 유틸리티 라이브러리입니다.

주요 기능:

  • 원격 adb devices 목록 조회
  • 특정 단말 대상 adb shell 실행
  • 파일 전송: 로컬 → 원격 → 단말(adb push), 단말 → 원격 → 로컬(adb pull)
  • 단말 상태 조회(adb get-state)

Requirements

  • Python 3.11+
  • 원격 서버에 SSH 접근 가능해야 합니다(포트 기본 22).
  • 원격 서버에 ADB가 설치되어 있어야 하며, 대상 단말이 해당 서버에 연결되어 있어야 합니다.

Installation

PyPI 배포 이후:

pip install sshadb

개발/로컬 설치:

python -m pip install -e .

테스트/개발 도구 포함 설치:

python -m pip install -e .[dev]

Quick Start

from sshadb import SSHAdb

client = SSHAdb(host="192.168.0.10", user="ubuntu", key_path="~/.ssh/id_rsa")
print(client.devices())
print(client.get_state("SERIAL"))
print(client.shell("SERIAL", "echo hello"))
client.push("SERIAL", "./local.txt", "/data/local/tmp/remote.txt")
client.pull("SERIAL", "/data/local/tmp/remote.txt", "./downloaded.txt")
client.close()

Usage

두 가지 방식으로 사용할 수 있습니다.

  1. 인스턴스 방식
from sshadb import SSHAdb

client = SSHAdb(
    host="192.168.0.10",
    user="ubuntu",
    key_path="~/.ssh/id_rsa",  # 또는 password="..."
    port=22,                    # 기본값 22
    timeout=10.0,               # 초 단위
    adb_path="adb",            # 원격의 adb 경로/이름
)
devices = client.devices()
state = client.get_state("SERIAL")
output = client.shell("SERIAL", "echo hello")
client.push("SERIAL", "./local.txt", "/data/local/tmp/remote.txt")
client.pull("SERIAL", "/data/local/tmp/remote.txt", "./downloaded.txt")
client.close()
  1. 전역 구성 + 편의 함수
import sshadb

sshadb.configure(host="192.168.0.10", user="ubuntu", key_path="~/.ssh/id_rsa")
print(sshadb.devices())
print(sshadb.get_state("SERIAL"))
print(sshadb.shell("SERIAL", "echo hello"))

API 개요

  • 클래스: sshadb.SSHAdb

    • devices() -> list[dict]
    • get_state(serial: str) -> str
    • shell(serial: str, command: str) -> str
    • push(serial: str, local_path: str, device_dest_path: str) -> None
    • pull(serial: str, device_src_path: str, local_dest_path: str) -> None
  • 전역 함수(전역 구성 사용 시):

    • sshadb.configure(**kwargs)
    • sshadb.devices() / sshadb.get_state(serial) / sshadb.shell(serial, cmd) / sshadb.push(...) / sshadb.pull(...)

Configuration

인증:

  • 비밀번호 기반: password="..."
  • 키 기반: key_path="~/.ssh/id_rsa"

연결/실행 옵션:

  • port: SSH 포트(기본 22)
  • timeout: SSH 연결 타임아웃(초)
  • adb_path: 원격 ADB 바이너리 경로 또는 이름(기본 adb)

Testing

환경 변수로 테스트 설정을 주입합니다. .env 파일을 사용하려면 프로젝트 루트에 배치하면 자동 로드됩니다.

  • 필수: SSHADB_HOST, SSHADB_USER, (SSHADB_PASSWORD 또는 SSHADB_KEY_PATH), SSHADB_SERIAL
  • 선택: SSHADB_PORT(기본 22), SSHADB_TIMEOUT(기본 10)

실행:

pytest -vv

부분 실행/디버깅:

pytest -vv tests/test_shell.py::test_shell_echo
pytest -vv -k devices -s -o log_cli_level=INFO

Versioning & Release

이 프로젝트는 Semantic Versioning(SemVer)을 따릅니다. 세부 전략과 배포 가이드는 다음 문서를 참고하세요.

릴리스 시 권장 순서:

  1. pyproject.tomlversion 업데이트
  2. src/sshadb/__init__.py__version__ 동기화
  3. 변경 이력 갱신(docs/changelog.md)
  4. Git 태그 생성: git tag -a vX.Y.Z -m "Release vX.Y.Z" && git push --tags
  5. 배포: python -m build && twine upload dist/*

PyPI 버전과 Git 태그는 반드시 일치해야 합니다.

License

MIT License. 자세한 내용은 LICENSE 파일을 참고하세요.

Links

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

sshadb-0.1.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

sshadb-0.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file sshadb-0.1.0.tar.gz.

File metadata

  • Download URL: sshadb-0.1.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for sshadb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9bae3c578b6972216176078fb7cc516b545b4bebe5cd08dad70013b5f02d6510
MD5 ff17f337f81282ea9100ca8c3dbc8f31
BLAKE2b-256 d6ce135d16e2a65f8bebf17dfc0a75f1b0ca84c861b62edd878bcea7918fc112

See more details on using hashes here.

File details

Details for the file sshadb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sshadb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for sshadb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c3567d0a0b5c82c3f11d6a85107f0d0d2d1bda15f00996aa5d58e059d706f80
MD5 b632cc098de67e786420625539dfe84d
BLAKE2b-256 ef0027fb4579f22609d142844530d1680e0ff27608e81b6cc454995199769af1

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