Fundamentals 11 min read

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

This article demonstrates eight practical examples of leveraging Python's built‑in command‑line modules—such as -m, telnetlib, http.server, json.tool, idlelib, zipapp, encodings.rot_13, base64, sysconfig, and zipfile—to perform useful tasks without writing any Python source code.

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 achieve complex functionality with minimal code, and its ecosystem embraces tools that hide implementation details behind friendly interfaces. This tutorial shows how to use eight built‑in Python features directly from the command line, requiring no source code at all.

0. Python CLI "-m" Parameter

Using the python -m option runs a module as a script. By invoking modules that support command‑line operation, we can access many utilities without writing code.

1. Service Port Testing

Instead of installing telnet , Python's telnetlib module can test outbound traffic. Example:

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

Running the command shows a successful connection to Google’s port 443; using an invalid port (e.g., 999) raises an error.

2. Launch a Local Web Server

Python can start a simple HTTP server without any code:

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

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

3. Validate and Format JSON Strings

When a JSON string is unformatted, python -m json.tool can pretty‑print it. Example:

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

After fixing the missing comma, the command produces nicely indented JSON.

4. Create a Text Editor

Python’s idlelib (based on Tkinter) can launch a simple UI editor:

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

After editing and saving, the file can be inspected with cat get_time_app/print_time.py .

5. Build an Executable Application

Using the built‑in zipapp module, a directory can be packaged into a single .pyz file:

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

The resulting .pyz can be run with python get_time_app.pyz .

6. Encode and Decode Strings or Files

Python provides simple encoders. ROT13 encryption via encodings.rot_13 :

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

Base64 encoding/decoding:

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

Files can also be encoded/decoded with the same module.

7. Retrieve System Metadata

System configuration details are available via:

<code>python -m sysconfig</code>

For a concise view of Python’s install and site paths:

<code>python -m site</code>

8. File Compression

Python can create and extract zip archives without external tools:

<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, the original files can be verified with ls and cat . Python also supports tar and gzip formats.

Conclusion

The article demonstrates how Python’s built‑in modules enable a variety of useful tasks without writing any code, offering convenient shortcuts for developers in many scenarios.

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