Python

A readable general-purpose language with a rich library

python Languages and build tools PSF-2.0

About

Python is a widely used language with clear syntax and a large standard library. Add-on packages cover almost anything else. It suits scripting, automation and quick data work in the terminal.

Install it

pkg install python

Run this inside Termux. If the package is already present, pkg will say so and do nothing.

Commands worth knowing

6 of the invocations you will actually reach for. Tap the copy button to put one on your clipboard.

python script.py Run a saved script and print its output. Test a change before putting it on a schedule.
python -m http.server Serve the current folder over HTTP with a built-in module. Handy for sharing files on a local network.
python -m json.tool data.json Reformat a JSON file with proper indentation, so it is easier to read.
python -i script.py Run a script, then drop into an interactive prompt with its variables still in scope.
python -c print(2**10) Evaluate a short expression straight from the command line, without a file.
python -m venv env Create an isolated environment, so a project keeps its own library versions.

Worked example

Run python -m json.tool data.json and this is what you should see.

termux
$ python -m json.tool data.json
{
    "name": "learntool",
    "version": "1.0",
    "active": true
}

The tool rewrites the file with four-space indentation.

Developed by

The Python Software Foundation · released under PSF-2.0.