Backend Development 5 min read

Running Python Scripts via Web URLs with httpout

This article introduces httpout, a lightweight Python tool that lets you execute scripts directly from web URLs, explains its installation, demonstrates usage with synchronous and asynchronous examples, highlights its key features, and provides built‑in objects for seamless web and CLI integration.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Running Python Scripts via Web URLs with httpout

httpout allows you to execute Python scripts from a web URL, sending the output to the browser. It works like a classic method of deploying scripts to the web but is more lightweight than CGI because it does not spawn a new process for each request.

Installation

<code>python3 -m pip install --upgrade httpout</code>

Example script (hello.py)

<code>import time
print('&lt;pre&gt;Hello...')
time.sleep(1)
print('and')
time.sleep(2)
print('Bye!&lt;/pre&gt;')</code>

Place the file in a folder and start the httpout server:

<code>python3 -m httpout --port 8000 example/</code>

You can then access the script at http://localhost:8000/hello.py . If you prefer URLs without the file suffix, create an internal folder to serve the script.

Features

Mixes asynchronous and synchronous execution, allowing both worlds to coexist in your script.

More lightweight than running CGI scripts.

Outputs characters line‑by‑line without waiting for the script to finish (e.g., using print() ).

No template engine required; scripts are portable between CLI and web.

Additional conveniences.

Mixed async and sync

The httpout server runs each module in a separate thread, enabling blocking code to run without interrupting the server loop, and also supports running coroutine functions using the existing event loop.

<code># ...
time.sleep(1)
async def main():
    await asyncio.sleep(1)
wait(main())
print('Done!')</code>

Utility functions such as wait() run a coroutine and wait for its completion.

Built‑in objects

You can access several objects without any imports, following the semantics of the __main__ module:

print()

run() – runs a coroutine and returns a concurrent.futures.Future object.

wait() – runs a coroutine and waits for it to finish.

__main__ – reference to the main route, usable in sub‑module imports.

__server__ – a dict containing basic HTTP request information.

Project repository: https://github.com/nggit/httpout

web servertutorialAsynchttpout
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.