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

Uploaded Source

Built Distributions

httpout-0.0.36-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.36-cp313-cp313-musllinux_1_2_x86_64.whl (24.0 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

httpout-0.0.36-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.0 kB view details)

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

httpout-0.0.36-cp312-cp312-musllinux_1_2_x86_64.whl (24.1 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

httpout-0.0.36-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.1 kB view details)

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

httpout-0.0.36-cp311-cp311-musllinux_1_2_x86_64.whl (23.8 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

httpout-0.0.36-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.9 kB view details)

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

httpout-0.0.36-cp310-cp310-musllinux_1_2_x86_64.whl (23.6 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

httpout-0.0.36-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.6 kB view details)

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

httpout-0.0.36-cp39-cp39-musllinux_1_2_x86_64.whl (23.4 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

httpout-0.0.36-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.4 kB view details)

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

httpout-0.0.36-cp38-cp38-musllinux_1_2_x86_64.whl (22.9 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

httpout-0.0.36-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.9 kB view details)

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

httpout-0.0.36-cp37-cp37m-musllinux_1_2_x86_64.whl (22.5 kB view details)

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

httpout-0.0.36-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.4 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.36.tar.gz.

File metadata

  • Download URL: httpout-0.0.36.tar.gz
  • Upload date:
  • Size: 15.6 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.36.tar.gz
Algorithm Hash digest
SHA256 1863948607c4eeed3425516196c93786cf6285fc12c6ef0df32191c523d05cce
MD5 5537f48c5961536d428e5fad38e21a72
BLAKE2b-256 a17a302bf9a46b8b574f3ca9644dee72a68d70131157064be133f81929584111

See more details on using hashes here.

File details

Details for the file httpout-0.0.36-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.36-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 663fbafd7235266355045daf37f14f32b3d87c258b40777babe04ef472c66bcc
MD5 28a35a5eb2f66736e958fec09c1ecf2e
BLAKE2b-256 e0822e97cdf506d55844be88555cfdcb0200434da9de8e21837d5c2ba31cf17f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.36-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d430acd8e1d59c59e6e1d8f6e9656f34a5583f253c814008321769ff2ff1e9dc
MD5 ca6bbb482aef5ab4cac3953dd29bf9b4
BLAKE2b-256 971c06e6545008cd59dacf9c4ce92de002c3dbdef977e1596d4996cbb6e51e3b

See more details on using hashes here.

File details

Details for the file httpout-0.0.36-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.36-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ded448d0cfb68ef5f56cf3082f909dfce653ed9e61270c4f11909d8f291046be
MD5 3aaea5d16c1d24c0d0da50e887b4b0a1
BLAKE2b-256 839969fbd7d374af4d30e2374e28c13f037e981e762b799232136334782fa409

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.36-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 eef062d0eb445d487f63d8bcdc6a4087eda6d422e77830b7b9bb2d240a6aedce
MD5 a010e4afbf57a3ff1b24260a59a9e72a
BLAKE2b-256 c54e30a86052dd5f5855a42c56fda3f2ddfdca7fe8fdd8d318116308a16ccfa6

See more details on using hashes here.

File details

Details for the file httpout-0.0.36-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.36-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 db9d68e1d25321226f142d589d47a9103e6f81ff3a5b47ce6cb0efb02e717c30
MD5 6dcb919df2f4f9ebe40accd37e99dc1c
BLAKE2b-256 bc398bcb7b062dfc391862759ed50307f62fead507baba3cc1d71c7c0218e1c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.36-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cf1f0262cc760f69a1cfdf86af89be3ee567cb72a8a14e9d07fa87f7582741b9
MD5 513f687f71b75add91f24d36d827b0d7
BLAKE2b-256 fe9cbf4cf078ce11588e6bc50332552669ab7fffc9262894e5729e10f3bc3f66

See more details on using hashes here.

File details

Details for the file httpout-0.0.36-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.36-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc44314cf8340af8d59e11001e4f74b616828722b67328455802b208ae144efe
MD5 2d01383621ff93fed507008ff48f344b
BLAKE2b-256 cc177b30b885a32c2e4d809b2f51994b7d8b93b4524528ac5ac94ee88d7de992

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.36-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6df7c3571e54a9cdb741ac3fcac8e8eb495272fb5f41fead24fe99ae83900058
MD5 3f09e70297337ae9ee1e07c384d0d4e5
BLAKE2b-256 6080b54a989e5200527b44a4ee79eccfd3943bc1c299bf08cb6a7e479d6eea33

See more details on using hashes here.

File details

Details for the file httpout-0.0.36-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.36-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9e38434f0a6a50a5371e9a6d7a7cb0985806889f646474372646be6bafec3c37
MD5 2b573bfc8e7312fa12758f15ebca00c6
BLAKE2b-256 a2201298852df2a2a3cda3f8e82b1a839916b2e1aa70260e10ad7d6acfab1634

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.36-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4c206c66dbaf7d4ab4d28ca2b71e92257e2339a7b5fe06874b2c7dc4d44d1822
MD5 7bd50ddb5428f4d771fcfe88d1fb14ba
BLAKE2b-256 bb5ca37e9c8282716db449e1680a0c942e86284745a971f90ac7440274dae133

See more details on using hashes here.

File details

Details for the file httpout-0.0.36-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.36-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d259859a6d49b004118f557ded013358b1489aa16f917d9e841e7d45939f7c2d
MD5 d25c74216a21e6339511cb8499b74c7e
BLAKE2b-256 8c8ad58ee80fc36d777a9be90aafbab16d33cbb8acfa199330bb5edb12193b4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.36-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d2f7777ea25028a55bfefbc3c84dc1ede6bb9ca81611bad0bf754ad918bdc8a9
MD5 70daea3d8abc521ea54772a045732af3
BLAKE2b-256 3ddb0e9e80c778655ffbad1f75d65982583847b7e5d482b8d3dc98a60f51e19d

See more details on using hashes here.

File details

Details for the file httpout-0.0.36-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.36-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c71bf163c700f8520dc2ba2a9411f13bd72cb96046b6b115d1e8389c3bc2ea34
MD5 e66b915ea5a45b6e14134c48eb0ac26e
BLAKE2b-256 cc3e1a33010f1646e2a14bc822189c5056f7b3aeec3ab6162f28a2a29ba1ce5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.36-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ef4f5f0df1c2e4d787d2b3cd8137d6ae77ba01772cc88bec29b4496505321fb1
MD5 b35c71346271f10968ef33af9e1a1598
BLAKE2b-256 ecea826243c91fce8036f6aaa6b2ae44948f66b40f4c84e2f23fc1194b4da16b

See more details on using hashes here.

File details

Details for the file httpout-0.0.36-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.36-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d6e6890150185547e4aef7ef12cef4c8b87ff9405e3eeb8a99b06780797c9163
MD5 73b8a7456e3970151d3728396831bc8c
BLAKE2b-256 8dbd859b95d969096448eada8840956b035fa3a69371c99efdb20651137925d2

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