Simple Python module to call termux-api by subprocess.
Exception-free module to call termux-api.
Most calls return (result, error). Please check error is None. Result is None if not a query.
Thin wrapper around termux-api. Function & param names are close to the official wiki.
If wiki is not detailed enough, here's the official repos: termux-api, termux-api-package.
Support most APIs of v0.50.1, but not updated after v0.51.0 is released.
(Probably still works for many cases, but please be careful.)
- Python 3.7+, because of subprocess.run(capture_output=True).
Install Termux & Termux:API app, then pkg install termux-api,
import termux_api, then call any function.
(Certain calls require some permissions to be granted to the Termux API app.)
Example:
import termux_api
termux_api.vibrate()
pdoc can be used to generate simple docs:
pip install pdoc, pdoc termux_api.py.
Currently, this supports all API implementations on wiki. (v0.50.1)
But some are not fully tested, so please use with some caution.
Most functions return (result, error), function and param names are close to the wiki.
Function docstrings contain some hints about valid args, or test result of the function.
Special functions:
- Generators yield (result, error):
location(request="updates"),sensor(). tts_speak_init()starts a Popen, then returns 2 functions:speak(text)&close().
Some outputs from termux-api are not json, so it's hard to get results programmatically.
I tried to read the source code, and parsed most of them:
media_player_info(): return {Track: None} or {Status, Track, Current Position}media_player_play(): error if notNow Playingmedia_player_pause(): True if paused, None if already paused, False if no trackmedia_player_resume(): True if resumed, None if already playing, False if no trackmedia_player_stop(): True if stopped, False if no trackmedia_scan(): return scanned file countmicrophone_record(): error if notRecording startedmicrophone_record_stop(): True if stopped, False if no recordingsensor_cleanup(): True if successful, False if unnecessary
These functions' outputs are not parsed. Raw strings are returned:
job_scheduler*(): looks complicated
These APIs, which are not listed on the wiki, are not implemented yet:
termux-audio-info
termux-keystore
termux-nfc
termux-notification-channel
termux-notification-list
termux-saf-create
termux-saf-dirs
termux-saf-ls
termux-saf-managedir
termux-saf-mkdir
termux-saf-read
termux-saf-rm
termux-saf-stat
termux-saf-write
termux-speech-to-text
If you find a bug, please submit an issue. Thank you.