Skip to main content

httpout is a runtime environment for Python files. It allows you to execute your Python scripts from a web URL, the print() output goes to your browser.

Project description

httpout

Coverage Quality Gate Status

httpout is a runtime environment for Python files. It allows you to execute your Python scripts from a web URL, the print() output goes to your browser.

This is the classic way to deploy your scripts to the web. You just need to put your regular .py files as well as other static files in the document root and each will be routable from the web. No server reload is required!

It provides a native experience for running your script from the web.

How does it work?

httpout will assign every route either like /hello.py or /index.py with the name __main__ and executes it as a module in a thread pool. Monkey patching is done at the module-level by hijacking the __import__.

In the submodules perspective, the __main__ object points to the main module such as /hello.py, rather than pointing to sys.modules['__main__'] or the web server itself.

httpout does not perform a cache mechanism like standard imports or with sys.modules to avoid conflicts with other modules / requests. Because each request must have its own namespace.

To keep it simple, only the main module is cached (as code object). The cache will be valid during HTTP Keep-Alive. So if you just change the script there is no need to reload the server process, just wait until the connection is lost.

Keep in mind this may not work for running complex python scripts, e.g. running other server processes or multithreaded applications as each route is not a real main thread.

httpout

Install

python3 -m pip install --upgrade httpout

Example

# hello.py
import time


print('<pre>Hello...')

time.sleep(1)
print('and')

time.sleep(2)
print('Bye!</pre>')

Put hello.py in the examples/ folder, then run the httpout server with:

python3 -m httpout --port 8000 examples/

and your hello.py can be accessed at http://localhost:8000/hello.py. If you don't want the .py suffix in the URL, you can instead create a hello/ folder with index.py inside.

Handling forms

This is an overview of how to view request methods and read form data.

# form.py
import sys

from httpout import wait, request, response


method_str = request.environ['REQUEST_METHOD']
method_bytes = request.method


if method_str != 'POST':
    response.set_status(405, 'Method Not Allowed')
    print('Method Not Allowed')
    sys.exit()


# we can't use await outside the async context
# so wait() is used here because request.form() is a coroutine object
form_data = wait(request.form())

print(method_str, method_bytes, form_data)

It can also be written this way:

# form.py
import sys

from httpout import run, request, response


method_str = request.environ['REQUEST_METHOD']
method_bytes = request.method


if method_str != 'POST':
    response.set_status(405, 'Method Not Allowed')
    print('Method Not Allowed')
    sys.exit()


async def main():
    # using await instead of wait()
    form_data = await request.form()

    print(method_str, method_bytes, form_data)


run(main())

Then you can do:

curl -d foo=bar http://localhost:8000/form.py

Features

httpout is designed to be fun. It's not built for perfectionists. httpout has:

  • A hybrid async and sync, the two worlds can coexist in your script seamlessly; It's not yet time to drop your favorite synchronous library
  • More lightweight than running CGI scripts
  • Your print()s are sent immediately line by line without waiting for the script to finish like a typical CGI
  • No need for a templating engine, just do if-else and print() making your script portable for both CLI and web
  • And more

Security

It's important to note that httpout only focuses on request security; to ensure that path traversal through the URL never happens.

httpout will never validate the script you write, you can still access objects like os, eval(), open(), even traversal out of the document root. So this stage is your responsibility.

FYI, PHP used to have something called Safe Mode, but it was deemed architecturally incorrect, so they removed it.

The PHP safe mode is an attempt to solve the shared-server security problem. It is architecturally incorrect to try to solve this problem at the PHP level, but since the alternatives at the web server and OS levels aren't very realistic, many people, especially ISP's, use safe mode for now.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

httpout-0.0.43.tar.gz (15.8 kB view details)

Uploaded Source

Built Distributions

httpout-0.0.43-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.1 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.43-cp313-cp313-musllinux_1_2_x86_64.whl (26.5 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

httpout-0.0.43-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.5 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.43-cp312-cp312-musllinux_1_2_x86_64.whl (26.5 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

httpout-0.0.43-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.6 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.43-cp311-cp311-musllinux_1_2_x86_64.whl (26.1 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

httpout-0.0.43-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.2 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.43-cp310-cp310-musllinux_1_2_x86_64.whl (26.0 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

httpout-0.0.43-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.1 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.43-cp39-cp39-musllinux_1_2_x86_64.whl (25.7 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

httpout-0.0.43-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.43-cp38-cp38-musllinux_1_2_x86_64.whl (25.5 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

httpout-0.0.43-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.43-cp37-cp37m-musllinux_1_2_x86_64.whl (25.0 kB view details)

Uploaded CPython 3.7m musllinux: musl 1.2+ x86-64

httpout-0.0.43-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25.5 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

File details

Details for the file httpout-0.0.43.tar.gz.

File metadata

  • Download URL: httpout-0.0.43.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for httpout-0.0.43.tar.gz
Algorithm Hash digest
SHA256 6acdf5acbb03b66dbbadb0e6b8a35642e9474a5e62e9910ee6809a172a4da1b6
MD5 24b8c68b3b0d50f4fa3a95e322e13bd1
BLAKE2b-256 d4d94cd1b2660cc1692a13effda9d99cf5ed97cf2bbf58e644311ecedfd2a4ae

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1488e496841e6f3491d0dc6c22dcdaad4835bcf9ba2560afa8c7ec341826bb57
MD5 975f1d624e4ef94181f36476cf455be9
BLAKE2b-256 aef0f572ae9b16099ff18ccce8a0bd27cb15a716cb1fbb6284d14cf00a9c1e24

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a83cc9a80eca29e819d1277264325ee6915460b60b6ff4cf0b4021bcfb435dbe
MD5 eccfc3d6c7304eb0229baf41935a3da7
BLAKE2b-256 13ac0c3aa1e44ad082b462ce024e0fd2dcb7a05e12ff3f0026ec9d89c71b3239

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cb1e8dc38f221e3bb52f8e4362a1302f4e5e7b8a421d43ddad600475b403ae7f
MD5 3f0b0a6e7ab927e7f3f1689081106539
BLAKE2b-256 1ea2aff76772476b66f78a62d1a943626a2773b617f3a197c042c15bdb987600

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3f56d00f1e1f44c348ff47c192c1a787d478c340826b544d2afe6895275a7c3b
MD5 5f17d892c385acb90cc6f4e7742fa1be
BLAKE2b-256 1b122f7c33567760bffee4144817929a1a6b0f6ba92fef430099d336a96b68e8

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d8e125e9faf78875fbcf97512cae8752adf9f556ae6a26335b76d75c70d1dd2e
MD5 b33161653e17b86642e85baef27e929f
BLAKE2b-256 04df212ad47269c6bedfdf4a98ced9bf8e95af0e2d19e83308e9ad89535e2f96

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 92f3f34534344180b880ab835c68917eb6c4e4353cc33da9f11e0dd604b285d8
MD5 9e8ce56bb36d1225d137f19c5b9ff50a
BLAKE2b-256 509c7e5ecf9b8e41c1a67aad0da8e104057cbc88198a379388bc39991750523e

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 25c5ea4e98a23129e2a9473c8ab568ba3acf3899e6acc88407176e7b18015d4f
MD5 4e1284b68794d64a803e8d018b4c13ad
BLAKE2b-256 338e71864cc436c26c8c1ae7948914ad2520a41cf1932305a393335bc2a19d9f

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 211021492451f5e699585c70623db066b37004ddd249ddc46f6170ccaf6cc96f
MD5 a21c48833d1134fd1e6483800a8cef85
BLAKE2b-256 dafc27042b53c9e740428b0c8d5b762e9048476588c145c7f92508466557069d

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cce0bf778ba5789880031e0c4e12a63ffb1faa9ab0bbac33af0e04198b45674d
MD5 d0fba3f0f37d7bc033b8b0c238467e1e
BLAKE2b-256 7aba87598daf1f344b5dd2441cf61bc74bfc232a3de9a5afc9dca6719feaa9fb

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2beb63112d0098de06829054aa5fc4e5552b024229342433e3768d5d0e805679
MD5 2096858ae5fea35f54e9d7afe67e7da8
BLAKE2b-256 0ac405b887bcb85dd7b240e752e81961707f72a436e4bcad507f88d6a22d6d1c

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 051496452a80e8102bb43a86c30c7ad72c84515ae827b8c8d1dbb735928767ba
MD5 dc5b8775726599f38b7c984b46eb632f
BLAKE2b-256 1beee9890930dc40210a04bbade09d17d4d726e9ac42550111cec2e9bb30111d

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp38-cp38-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 387397f03a3bb52b011e329801d2ba4c5290d98bfefda157b665fe207d565002
MD5 552b80036f6dabfd9d6b43086eb3b8ec
BLAKE2b-256 9e71bf43b21a625bd5e8b666638fcfd14ea99648f02cf15c26f5a6a763ebd8f7

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 410b6c7547f26b58f92af7cd6681e40b62f36f3831ec271b5ff18afd2f155f06
MD5 28206f4840f9eee02efc93610615bd2a
BLAKE2b-256 34615d8189b404848f3c30bb4bff041f7f8746f1b420937ca6f02923a5acb2f7

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp37-cp37m-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 df869e535cd7330f317c75aa078b049f42a1c9db8483072a0453ab7a61ad825e
MD5 9787d643a772cdcb3c984993f9c32736
BLAKE2b-256 e7e8c9c8d38b4ae970e7695dc18b2aacf571940a55e2ff229a1f3c82d378c6ad

See more details on using hashes here.

File details

Details for the file httpout-0.0.43-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.43-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f20e7465ea7381e930b6c247da7356453c5ebc8e3be7930b258c74c2fb1214f
MD5 e62bd70ce05bd0b8a84bf0bf718b68b9
BLAKE2b-256 52f242d358bd599b68d8b3d282b6c722973c0a5f06135c60610a6f6b9b24a67f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page