A Python wrapper for the Termux API commands
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file termux_api_python-0.1.1.tar.gz.
File metadata
- Download URL: termux_api_python-0.1.1.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73ca3be2e2358eddff4d807b2653abfef23ff95e9169e1355bd2129b174dd714
|
|
| MD5 |
deb333c07f6b515deb747ab95cb8d2ac
|
|
| BLAKE2b-256 |
96f18885f1261a08f372c4491a3a0a91b71eeccf541e8ba30cb6e7dda34de934
|
File details
Details for the file termux_api_python-0.1.1-py3-none-any.whl.
File metadata
- Download URL: termux_api_python-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec7be9720e1efe50e17c82c5c422fad12bd097202ecd7226cb3b2bb4d99d5892
|
|
| MD5 |
f374f92b3c2bec30c0e905784bc9689d
|
|
| BLAKE2b-256 |
4d9afbd1ffd810a576dee6d6fc4c603acad20964ab88d79dcdaa9780da40b666
|