Fundamentals 11 min read

Eight Ways to Use Python Built‑in Modules Without Writing Code

This article demonstrates eight practical techniques for leveraging Python's built‑in command‑line modules—such as telnetlib, http.server, json.tool, idlelib, zipapp, encodings.rot_13, sysconfig, and zipfile—to perform useful tasks without writing any source code, illustrating each with concise commands and screenshots.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Eight Ways to Use Python Built‑in Modules Without Writing Code

In recent years Python has become popular because it lets developers accomplish complex tasks with minimal code, and many community‑contributed packages wrap intricate implementations behind user‑friendly interfaces.

Surprisingly, many of Python's capabilities can be accessed directly from the command line without writing any code; this article presents eight examples of using the python -m interface to invoke built‑in modules.

1. Test a service port

Using the telnetlib module you can test outbound traffic to a specific IP and port:

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

Replacing the port with an invalid number demonstrates error handling.

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

2. Start a local web server

The http.server module launches a simple HTTP server on port 8000:

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

After starting, you can browse to http://localhost:8000/ to share files in the current directory.

3. Validate and format JSON strings

Pipe a raw JSON string into json.tool to get pretty‑printed output and syntax error diagnostics:

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

4. Create a simple text editor

Using the idlelib module you can launch a minimal GUI editor for quick scripts:

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

After editing, save the file and verify its contents:

<code>cat get_time_app/print_time.py</code>

5. Build an executable application

The zipapp module packages a directory into a single .pyz executable without external tools like PyInstaller:

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

Run the resulting application with:

<code>python get_time_app.pyz</code>

6. Encode and decode strings or files

Demonstrations include ROT13 encryption via encodings.rot_13 , base64 encoding/decoding, and decoding a base64‑encoded script that can be executed directly:

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

7. Retrieve system metadata

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

<code>python -m sysconfig</code>
<code>python -m site</code>

8. Compress and extract files

The zipfile module can create and extract ZIP archives without external utilities:

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

After extraction, verify the contents with standard shell commands.

In summary, these eight command‑line examples show how Python’s built‑in modules can be harnessed to perform useful operations without writing any source code, offering convenient shortcuts for many everyday tasks.

CLIPythonAutomationscriptingNo-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.