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

Uploaded Source

Built Distributions

httpout-0.0.38-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.7 kB view details)

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

httpout-0.0.38-cp313-cp313-musllinux_1_2_x86_64.whl (26.2 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

httpout-0.0.38-cp313-cp313-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.13 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.38-cp312-cp312-musllinux_1_2_x86_64.whl (26.1 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

httpout-0.0.38-cp312-cp312-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.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.38-cp311-cp311-musllinux_1_2_x86_64.whl (25.8 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

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

httpout-0.0.38-cp310-cp310-musllinux_1_2_x86_64.whl (25.6 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

httpout-0.0.38-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25.7 kB view details)

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

httpout-0.0.38-cp39-cp39-musllinux_1_2_x86_64.whl (25.4 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

httpout-0.0.38-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25.4 kB view details)

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

httpout-0.0.38-cp38-cp38-musllinux_1_2_x86_64.whl (25.1 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

httpout-0.0.38-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25.7 kB view details)

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

httpout-0.0.38-cp37-cp37m-musllinux_1_2_x86_64.whl (24.7 kB view details)

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

httpout-0.0.38-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25.2 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.38.tar.gz.

File metadata

  • Download URL: httpout-0.0.38.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.38.tar.gz
Algorithm Hash digest
SHA256 50f1b9aeea5b3f5a36f09bd4f89a952824edebdb45ce34ea405ce780188774b6
MD5 e9c96d3c0daab3c21c6f7fa0a5b726ef
BLAKE2b-256 042c17ce9e5b8728b27cd0245699f333750d8b67021a12950fe78b3ce48f8942

See more details on using hashes here.

File details

Details for the file httpout-0.0.38-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.38-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0bbd6a06e57773a2c8ade168a3e6ba2775477fea3b22e0b8793a4b06ad68b652
MD5 3ad6bab257528f5a30318738ed2ab258
BLAKE2b-256 d8ac372f6ebfd41347151d889452b9a95762ad48fddfa100df30d45be2106ab4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.38-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 edbfbc0be7e61f023a509065451a8561d8baed1b3d6f2c74ac6ee917ef262187
MD5 91fe813927b0709df6adf9ebbb4ba434
BLAKE2b-256 23b047a80acc88d0a8da9cfa901c5f744aa1b646141f57be9bb7b3070389a195

See more details on using hashes here.

File details

Details for the file httpout-0.0.38-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.38-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 28de86ca6939bcd23fe688c7c35955a7e3c8bf4d22c12b4ae395115f6f36ca89
MD5 a6e0ba3cd13f8090fe053e007fe63ece
BLAKE2b-256 d6d493534b3a7bb74840d802508f507d8cc2f32b0517967d79a2c6188b0bea98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.38-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 126a92f80a54e8a6b3463cf530cc6fbfa70922de28514653becde1a7846a490a
MD5 0da62b0826523f8b0b9164f2caba9075
BLAKE2b-256 d10380b3bfbd9c87a41703cebacdc44ee6ef5ca0434f2b6023b573d73af2aa99

See more details on using hashes here.

File details

Details for the file httpout-0.0.38-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.38-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b9d3a9875b5dffbd83948e4fdda770433854aa0114283fd2725948be094682fd
MD5 79d60e61d5c918207150b0cd0d801e3a
BLAKE2b-256 9601b924f814710c4e41745c794c4781e68317467dc3030ede6bb27fe07e728f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.38-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3584259b6e4072c43583ba6ba86c5714c4746656db4ce8c8dcb555b4f3cad15f
MD5 d1ec13e43f3c7e8875b757f39dc029e6
BLAKE2b-256 d4b6e9f42badbf49e02ff897ee23dfcc78df49ebe6accf18b554b51684291095

See more details on using hashes here.

File details

Details for the file httpout-0.0.38-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.38-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 96d00eee46bf9a6f1cc135bd58b9a09d97f6934f94c3b704f7b76a5bdd2c382b
MD5 11c99d2f79a525831f6953d59f4e1f27
BLAKE2b-256 8be3123797d0f8d9831cf88ef6bc316b1f403c036d436efbdeb46a481a7f9c2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.38-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f02cf1b44c0c27be9705f50e1c99cf32aae5b5166cb5fa542edc62f7374a58b8
MD5 194c928f21a515b081deae313683cbf2
BLAKE2b-256 48eab1f44ecb87d5d3972a28808110c0e1396a58039995dc45e48876020a84d3

See more details on using hashes here.

File details

Details for the file httpout-0.0.38-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.38-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 91977bf62f04649bdfa01a563d716f94e811c188d287cb901349a0b9d7e8390d
MD5 267f2aca3efcbea563e3562f6df61e30
BLAKE2b-256 e58a8b82d8b911262d0f4391e2ab297b8fcfcd21bd7fda4be7e16798d68d01b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.38-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1e4f26a154bd5bc68cb42c05cbff3a15c8c63879c896a203f0d54ac9204381ab
MD5 b5c1b88b0321de4cec70121a8a043f8f
BLAKE2b-256 ae1a6ea7af4d9b6e6f8951c55b280568b3599eca975dac7ab7f54f783d820d81

See more details on using hashes here.

File details

Details for the file httpout-0.0.38-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.38-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18e3d5fda1fa9bde48cb787c45f6639b8f0b87993a946158920f7b5e16f62994
MD5 9c1d7b4d58290c304811f4137ae9a470
BLAKE2b-256 e0bbffc7712e551282db0e29d47af19d201d41dee55a58642903d938143d0091

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.38-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 99b75c62dfa4c8716ca1659dd0a6c06a3e0b82ea788f63cced5d24d75d1f3cfe
MD5 3c7522907dbcb0e410b070959b6eebaa
BLAKE2b-256 5e98faabb4b9ec1b0399cbbec0cb2efcb7abb9138c402ca4b53554434a66e469

See more details on using hashes here.

File details

Details for the file httpout-0.0.38-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.38-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 12078976e86846fe828d09538f5af30fcae21cf65cba1509e4782bd4613f795b
MD5 19e7da50a163ead5805afadea8afbe97
BLAKE2b-256 441758debd1bcae940c659eb572e599adbbe2b2d6cfb66be4b4abfc3af69fe3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.38-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f3deae8f5a7559b1997fcdeaa5096c10af4ba5749b94385e2a195273e537ccc1
MD5 c0d8c9bf5d912e10bf617b268bfca6d2
BLAKE2b-256 e945d2f07fda1e86dffb87c72e13d2eddc33260f05fd0d9fc82c0e54fb1f2e01

See more details on using hashes here.

File details

Details for the file httpout-0.0.38-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.38-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2e1d4df0f21e750a9751470cf02cb1eb6882f4787c504a119fb4ab143e3fd72f
MD5 4829fc5c798c3c22f03a5799ab2ebe0e
BLAKE2b-256 b9424f53b6f92fa68ac5882a2ca73d9b3cb7ca07441e0de23f07fee9ca17cfd8

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