Simple Python module to call termux-api by subprocess.
I used qpython + sl4a before. This is made to call termux-api in my Python scripts.
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.
- 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.
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, returnspeak(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 Playing
media_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 started
microphone_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
If you find a bug, please submit an issue. Thank you.