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.50.tar.gz (73.4 kB view details)

Uploaded Source

Built Distributions

httpout-0.0.50-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (99.1 kB view details)

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

httpout-0.0.50-cp313-cp313-musllinux_1_2_x86_64.whl (238.8 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

httpout-0.0.50-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239.0 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

httpout-0.0.50-cp312-cp312-musllinux_1_2_x86_64.whl (249.7 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

httpout-0.0.50-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (250.4 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

httpout-0.0.50-cp311-cp311-musllinux_1_2_x86_64.whl (242.6 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

httpout-0.0.50-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (243.1 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

httpout-0.0.50-cp310-cp310-musllinux_1_2_x86_64.whl (227.3 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

httpout-0.0.50-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (229.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

httpout-0.0.50-cp39-cp39-musllinux_1_2_x86_64.whl (226.9 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

httpout-0.0.50-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (228.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

httpout-0.0.50-cp38-cp38-musllinux_1_2_x86_64.whl (222.3 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

httpout-0.0.50-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

httpout-0.0.50-cp37-cp37m-musllinux_1_2_x86_64.whl (210.6 kB view details)

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

httpout-0.0.50-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (212.3 kB view details)

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

File details

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

File metadata

  • Download URL: httpout-0.0.50.tar.gz
  • Upload date:
  • Size: 73.4 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.50.tar.gz
Algorithm Hash digest
SHA256 102e55e97de5336a4d60629c3ac3724ebdd3ab860cbf35a1e07a4ad2ab2a9cae
MD5 741cd225d6a7440b1ecce83f16a6a619
BLAKE2b-256 c3b6609d7260592236952035e5a59303dd4ffcdf467cee9f1aac59fcc0bb8229

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50.tar.gz:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.50-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.50-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ce10ecadfca6d6ff3f4b63761835ba7ba8630fc81c9425cb7230131ed5105651
MD5 e9832bc41144a376c5611a6889c1cd86
BLAKE2b-256 1f458b4044428c09c6820b7f0d8f4abfd422e3e14a0ee86a40095e078302f1da

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

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

File metadata

File hashes

Hashes for httpout-0.0.50-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5fb0343e5f72113a38f4646fe978be538c94fe3410d1650bb92fdd8afdb5331b
MD5 44efe99ffbd501f1aa0a4af4b2aed767
BLAKE2b-256 f61e0f051c5542fddd9c5ad4a24d0c017201bececee5592e0648b4cce3be5af7

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.50-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.50-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 93413d24b89ac6cd0e563e5ee6570371bbbd84931dcbdff9ea94309a52e5204f
MD5 9d52e10a7580b4584fa25223b09744f0
BLAKE2b-256 1e41e613d4dec1781a3575130ee4e3cfd3b77ae6150b8da635e1577fe1b6e290

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

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

File metadata

File hashes

Hashes for httpout-0.0.50-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 22ac281515ece04d7553e4c3640e1bb6f3fe3c8489f58848def73a7f78b88272
MD5 bc18234911da6e6aef3c9380e86fefa3
BLAKE2b-256 cf4e2d43197be07456ca1eea0e9973d9ab3c176677722ca66466f28558e41175

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.50-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.50-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 740bac1fb44e3be57d694cbf3eb9e5bdcfd643b18a35724e3fd88b768362fe4e
MD5 d57dfd5801533dc41436631045bc81d8
BLAKE2b-256 a94041a591b05d46b34e9c3d271dc6d3056e0e928db136261b05b21aa2831270

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

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

File metadata

File hashes

Hashes for httpout-0.0.50-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4241c1c8e0260a5129a90a7d24a31ac2200d362691040bb4ba54549e5d7158b4
MD5 531887c22d467985b9cdd4da75a9e07d
BLAKE2b-256 7736b4eab5aed1646105820c0b40f286f54252c4c26b8390252c406155e6a8a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.50-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.50-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 860110931bcb85ece35c1916ed1e0071f6c91ae709158c9f6efc6e0784280758
MD5 9cc2e0bdeb0dcf1ad83df36e7572c0d3
BLAKE2b-256 f3d832c64375e354808fba0ffddbe70323433f24e969c66f6046d3694f88f163

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

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

File metadata

File hashes

Hashes for httpout-0.0.50-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3c3445c2c13f661aa4275cd6a7258ebd2989f477cd3034b343439e209b566523
MD5 715e34a2429b952d8f6df0c1f9809913
BLAKE2b-256 b9fbf18eb246a24df1d5a97abf046438efd8a97769b23bfc532b214ea5b6553a

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp310-cp310-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.50-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.50-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e15138013e86c0b8538653d636bbee4fd848c81ec6399f9f629e65bfd84e2ea5
MD5 c92501b31f31d112be1eb4b851f9fa60
BLAKE2b-256 34ff85ed7b725dc3715bf5f7acdd3b57bbd7dd8cfb78c756cfa440b09b9338b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

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

File metadata

File hashes

Hashes for httpout-0.0.50-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6c57fd7947c71c3cafa5df3bd2ca02a639e52479e4f2e12c0fbfb16bc6315316
MD5 8d981304223870d8f198168edaf73ebc
BLAKE2b-256 36586d7b2134c931f14f3eb34d757a701427046945e5ef4d89ef191e2aa9c9da

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp39-cp39-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.50-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.50-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 369c05e95a338e4e49bd8b9208cb87ed22b124e30f5d1d6022d5510fc09b5908
MD5 f2e106ba1ca02a121dd4ab58eaa9daba
BLAKE2b-256 1a01f4f8d3c2cd4dcb27a06cd46a33c81453fb2136d4f74a20797ceaa7a9ee1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

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

File metadata

File hashes

Hashes for httpout-0.0.50-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a671070077de9dfd7ba0de9bd13729c8109dce733990037626db05b757593183
MD5 0fa9966249f3514d2034e601a9f4051c
BLAKE2b-256 ac4e22cf8028059a0e4795780c738ac161c7e5e20d6c56efda85351794339498

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp38-cp38-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.50-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.50-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6aeff54a75e6452ac2840199fe821d8debeb4d641be4026d2680584124682d84
MD5 b8392af2ed59a46b0f780a5b22c5e4f7
BLAKE2b-256 5b9765f0d067b1fd69508a1a6835e93a36aa127572ca737c5b13ecabd2b52815

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

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

File metadata

File hashes

Hashes for httpout-0.0.50-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a0c4953278d3f01066cf30e9bc1d6c638e89b5dd012e5115b07df7fbdd9fc9f9
MD5 b7397dd973de4b7efde4c4ee7f9b2010
BLAKE2b-256 8940b28299f65204f5bb2132c935d07336026bbac57309a9963af94c6c793387

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp37-cp37m-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.50-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.50-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0cc0ce747a0f9a12459f3981420959172d414947f82e9b003aaa7ab0ca44f297
MD5 74816ec1fe6ecc79960d718f28a5c292
BLAKE2b-256 f9ecdf9de0100f22015828dfee1790982579170ee6252ed4eb4d896817fd166d

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.50-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations:

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