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

Uploaded Source

Built Distributions

httpout-0.0.40-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.8 kB view details)

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

httpout-0.0.40-cp313-cp313-musllinux_1_2_x86_64.whl (26.3 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

httpout-0.0.40-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.3 kB view details)

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

httpout-0.0.40-cp312-cp312-musllinux_1_2_x86_64.whl (26.3 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

httpout-0.0.40-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.4 kB view details)

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

httpout-0.0.40-cp311-cp311-musllinux_1_2_x86_64.whl (25.9 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

httpout-0.0.40-cp311-cp311-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.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.40-cp310-cp310-musllinux_1_2_x86_64.whl (25.8 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

httpout-0.0.40-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25.9 kB view details)

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

httpout-0.0.40-cp39-cp39-musllinux_1_2_x86_64.whl (25.5 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

httpout-0.0.40-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25.6 kB view details)

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

httpout-0.0.40-cp38-cp38-musllinux_1_2_x86_64.whl (25.3 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

httpout-0.0.40-cp38-cp38-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.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.40-cp37-cp37m-musllinux_1_2_x86_64.whl (24.8 kB view details)

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

httpout-0.0.40-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25.3 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.40.tar.gz.

File metadata

  • Download URL: httpout-0.0.40.tar.gz
  • Upload date:
  • Size: 15.7 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.40.tar.gz
Algorithm Hash digest
SHA256 92a9654eb05a6e4928666f0be56f62b432e34670801a68e1e3cd5a82ebcc533f
MD5 07485cb49d3192023aa43618b50f5bb4
BLAKE2b-256 73eda9e03e8273951e63d3bfe2bedfc0fe9e57db1c4be0bf39ffc7b1d657611c

See more details on using hashes here.

File details

Details for the file httpout-0.0.40-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.40-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf8b78ee8b6e0301aff6edea8f0dab78efa779e4bb7006d3d244502eaac11e66
MD5 dcdf82b05694e47e991b2e8374d88fc4
BLAKE2b-256 153255b9f5244e3491d185983f9ab49d024736af051bb93a51c2ea2887006fb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.40-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9ef6fbea8363ba494e9f96cd23f84ca0882573b0bfa6096b57fa587ca6cbb6eb
MD5 ae6557a4b374741555957e6d0de95403
BLAKE2b-256 5379d1b9ceba763dda7b4f8878b236731a779b4da1fc39c886e50d3499d84f9e

See more details on using hashes here.

File details

Details for the file httpout-0.0.40-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.40-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55f3b85d62c9a7c28e1743db0f8c6fd6b72864f738dfd2ced9a56f334463ff3f
MD5 900082185da0a35099e9b3c4115997ec
BLAKE2b-256 ad9ef80ee4190c21850414d4502aba70bf4b05b384a2b8f9965df1c403f9dcc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.40-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cd9902e8cc2a0f519a7ae878cdf323f771c6defd29896a69576f6c8d15dfa1ee
MD5 e5b046c48d325339cc9bb27f4aa77d3b
BLAKE2b-256 fdb3fb7ed798c15adcbdd88fb94ef36b56f38615f283eaf5d09a3818f7372cbc

See more details on using hashes here.

File details

Details for the file httpout-0.0.40-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.40-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5e2b3f1f487485ce3287cf20b93ef7227a00c1892fdbb793d4de28dc3d4b044f
MD5 b1846562d029bc40bd4ac38d148af360
BLAKE2b-256 7793c22309af53333a02f49620d70665ee56b263f76358e681688bd4de95335d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.40-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 07174890aad37b6e20357365718ccccadeca69bd214a181de7548085cb1588f6
MD5 1230f65790c14e54f5b4f774f82a8b51
BLAKE2b-256 7d7afb82f75d325ac7ea7dd218d83ba21ade0bf61bf9b8694b484c72888e025d

See more details on using hashes here.

File details

Details for the file httpout-0.0.40-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.40-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 33abc18f608ed251bd1b85d56a97017afdc533d3c094b078052f7e3c634a60bc
MD5 fa5fb40d991222c1e59512816d56071b
BLAKE2b-256 b89192a020b1465a1b54d54c3dd52bfed96a97d6b7b7fd29870b7244139941ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.40-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7bd4f72a4f3dba70b884c67cdfe5b5842befa52ccdc7b1b8a5b5d6310d90f78d
MD5 71a8d4458e1bab68739033aa397480c9
BLAKE2b-256 9315336daf3617dd6494ea298f1e5a03c9dc099510d810e3ec864677699bac15

See more details on using hashes here.

File details

Details for the file httpout-0.0.40-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.40-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8539028d0190fbdf1516975fc41646b870c936979dbaeaa3d9958353bc67ee8d
MD5 74e7f722966cad0f78e3cf9a0419b373
BLAKE2b-256 33958abebd4873a67760fb85adeb1c81cf27637e7d01b0548c62631564a738b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.40-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b7d5f127abc7ec1f6206df5223c3c57fe42640538791efbdaaac1b35cc1bd97c
MD5 3d688eace7245a2ae5e4dc840c545bc4
BLAKE2b-256 01697e5cdb7f4815aa0e71391fc133c7a627e2e8a8db87bb9249d97637fba9a7

See more details on using hashes here.

File details

Details for the file httpout-0.0.40-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.40-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 65c310b008b93e98cd43d6e2922683f5f1866aa97fa8417a67d323eff6c2237c
MD5 d13d77b16e565641dd8898341cbe2a69
BLAKE2b-256 e95393db31c560b11134219cedd7a59ffc8e07e54de26c2856f009b096ac1a09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.40-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5b0ff712fb8cce10cf46ac0553a64cbf14db732f56bfa28cdfc7a18d787d9ed4
MD5 747781ac4d169313c0fd87ae79c04445
BLAKE2b-256 ecd29c0671b132186711e74042d8bda3314eaf7924e479980a29b319dd89fd58

See more details on using hashes here.

File details

Details for the file httpout-0.0.40-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.40-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 434d8379ddcf21aafd378b98acff72c287bf8b0fe512eebd7160c101427ccfd4
MD5 86af546a071788aeb340774ad2d699aa
BLAKE2b-256 f903e319207bb6ac0e20fe328c2713f6aba50e6011e53465786f32ceac2aa4a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.40-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 784e5f413c85dd7b1bfd982a61051abeb87d6b5c48b103c67b6d95db3cfaf447
MD5 853221e8b7cae52c84ba1c1a340a3c6c
BLAKE2b-256 782094e1af0668558936804e43c13dd7f915c7176b34e9d097caa584901d9761

See more details on using hashes here.

File details

Details for the file httpout-0.0.40-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.40-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ac27b02ec2904e86f68e7f294b70a4b8e7f7b23afcba4d0361f329c912c2d237
MD5 0150b4dad37e9bf2fa2654ddc8192f7c
BLAKE2b-256 e4fe143bdcdf4021b8d17f61d9fa04ce37099a324dc2a062d42cf218b8ac3b18

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