Termux API Python Wrapper
This is a Python wrapper for the Termux API commands, making it easier to use Termux API functionality in Python scripts.
Features
- Provides a clean, Pythonic interface to Termux API commands
- Handles command execution and error handling
- Automatically parses JSON output from commands
- Supports all available Termux API commands
- Comprehensive documentation for each method
Installation
Manual Installation
- Make sure you have the Termux API app installed on your Android device
- Install the Termux API package in Termux:
pkg install termux-api - Copy the
termux_api.pyfile to your project or to a location in your Python path
PIP Installation
pip install termux-api-python
Usage
from termux_api_python import TermuxAPI
# Create an instance of the TermuxAPI class
termux = TermuxAPI()
# Show a toast message
termux.toast("Hello from Python!")
# Get battery status
battery = termux.battery_status()
print(f"Battery level: {battery['percentage']}%")
# Show a notification
termux.notification(
title="Python Notification",
content="This notification was created using the Python Termux API wrapper",
id="python-example"
)
# Get device location
location = termux.location()
print(f"Location: {location}")
# Text-to-speech
termux.tts_speak("Hello, this is text to speech from Python")
Advanced Notification Example
The wrapper supports all notification features, including buttons with actions, media controls, and direct reply:
# Interactive notification with buttons
termux.notification(
title="Interactive Notification",
content="This notification has buttons with actions",
id="interactive-example",
button1="Toast",
button1_action="termux-toast 'Button 1 was pressed!'",
button2="Vibrate",
button2_action="termux-vibrate"
)
# Media notification
termux.notification(
title="Media Controls",
content="Control media playback",
id="media-example",
type="media",
media_play="termux-toast 'Play pressed'",
media_pause="termux-toast 'Pause pressed'",
media_next="termux-toast 'Next pressed'",
media_previous="termux-toast 'Previous pressed'"
)
# Notification with direct reply (Android N+)
termux.notification(
title="Reply Example",
content="This notification supports direct reply",
id="reply-example",
button1="Reply",
button1_action="termux-toast \"You said: $REPLY\""
)
Check out notification_example.py for more notification examples.
Available Methods
The wrapper provides methods for all Termux API commands, including:
battery_status()- Get battery status informationbrightness(level)- Set the screen brightnesscall_log()- Get the call logcamera_info()- Get information about device camerascamera_photo(output_file)- Take a photo and save it to a fileclipboard_get()- Get the system clipboard textclipboard_set(text)- Set the system clipboard textcontact_list()- Get a list of contactsdialog(dialog_type, **kwargs)- Show a dialogdownload(url)- Download a filefingerprint()- Authenticate with a fingerprintlocation()- Get the device locationmedia_player(command)- Control the media playernotification(content, title, **kwargs)- Display a system notificationsms_list(**kwargs)- List SMS messagessms_send(number, message)- Send an SMStoast(message)- Show a toast messagetorch(on)- Toggle the torchtts_speak(text)- Speak text using TTSvibrate(duration_ms)- Vibrate the devicevolume(stream, volume)- Get or set the volumewifi_enable(enable)- Enable or disable WiFi- And many more...
See the termux_api_python.py file for a complete list of available methods and their parameters.
Examples
examples.py- General usage examples for various API methodsnotification_example.py- Comprehensive examples of notification features
Requirements
- Android device with Termux app installed
- Termux API app installed
- Termux API package installed in Termux
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for termux-api-python 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| termux_api_python-0.1.1.tar.gz | 12.5 kB | Without provenance | Details for termux_api_python-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| termux_api_python-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for termux_api_python-0.1.1-py3-none-any.whl |
Total release size: 22.4 kB
Release files / termux_api_python-0.1.1.tar.gz
| Download URL | termux_api_python-0.1.1.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73ca3be2e2358eddff4d807b2653abfef23ff95e9169e1355bd2129b174dd714
|
|
BLAKE2b-256 checksum How to use checksums |
96f18885f1261a08f372c4491a3a0a91b71eeccf541e8ba30cb6e7dda34de934
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Release files / termux_api_python-0.1.1-py3-none-any.whl
| Download URL | termux_api_python-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ec7be9720e1efe50e17c82c5c422fad12bd097202ecd7226cb3b2bb4d99d5892
|
|
BLAKE2b-256 checksum How to use checksums |
4d9afbd1ffd810a576dee6d6fc4c603acad20964ab88d79dcdaa9780da40b666
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Security for termux-api-python 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.