Fundamentals 10 min read

Eight No‑Code Features in Python: Using Built‑in Modules via the CLI

This article demonstrates eight practical ways to leverage Python's built‑in modules directly from the command line—such as testing ports, launching a web server, formatting JSON, creating a simple editor, building executable archives, encoding/decoding data, retrieving system metadata, and compressing files—without writing any Python code.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Eight No‑Code Features in Python: Using Built‑in Modules via the CLI

Python’s popularity is largely due to its ability to perform complex tasks with very little code, and many of its built‑in modules can be used without writing a single script.

0. Python CLI “-m” parameter

By invoking Python with the -m flag you can run a module as a script. For example, python --help lists all available options, and the -m mod argument runs the specified module directly from the command line.

1. Service port testing

Instead of installing telnet , you can use the built‑in telnetlib module to test outbound connectivity. Example:

<code>python -m telnetlib -d 142.250.70.174 443</code>

Attempting to connect to a closed port (e.g., 999) raises an error.

2. Launching a local web server

The http.server module can start a simple HTTP server with a single command:

<code>python -m http.server</code>

The server listens on port 8000 and serves files from the current directory, making it easy to share files with others.

3. Validating and pretty‑printing JSON strings

When you have a compact JSON string, you can format it using the json.tool module:

<code>echo '{"name": {"first_name":"Chris", "last_name":"Tao"}, "age":33}' | python -m json.tool</code>

If the JSON is malformed, json.tool points out the error (e.g., a missing comma).

4. Creating a simple text editor

Python’s idlelib (based on Tkinter) can launch a basic GUI editor without installing external tools:

<code>mkdir get_time_app
python -m idlelib get_time_app/print_time.py</code>

After editing, save with Ctrl+S and verify the file using cat get_time_app/print_time.py .

5. Building an executable application

The zipapp module packages a directory into a self‑contained .pyz executable:

<code>python -m zipapp get_time_app -m "print_time:main"
python get_time_app.pyz</code>

6. Encoding and decoding strings or files

Python can perform ROT13 encoding via encodings.rot_13 :

<code>echo "I am Chris" | python -m encodings.rot_13</code>

Base64 encoding/decoding is available with the base64 module:

<code>echo "I am Chris" | python -m base64
echo "SSBhbSBDaHJpcwo=" | python -m base64 -d</code>

You can also encode a file and pipe the result back to Python for immediate execution.

7. Retrieving system metadata

Run python -m sysconfig to display full Python configuration details, or python -m site for a concise view of the environment and site‑specific paths.

8. File compression

Using the zipfile module you can create and extract zip archives without external tools:

<code>python -m zipfile -c get_time_app.zip get_time_app
python -m zipfile -e get_time_app.zip get_time_app_extracted</code>

Python also supports tar and gzip formats for compression and extraction.

Conclusion

The article showcases how Python’s built‑in modules enable a variety of useful tasks—ranging from networking checks to file packaging—without writing any code, offering convenient shortcuts for many everyday scenarios.

CLIPythonAutomationcommand lineNo-codeBuilt-in Modules
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.