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

Uploaded Source

Built Distributions

httpout-0.0.42-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.9 kB view details)

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

httpout-0.0.42-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.42-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.42-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.42-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.42-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.42-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.42-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.42-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.42-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.42-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.42-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.42-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.42-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.42-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.42.tar.gz.

File metadata

  • Download URL: httpout-0.0.42.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.42.tar.gz
Algorithm Hash digest
SHA256 faf0853103b083a95817ee9d73e4214a83e6ccd29cc4597fb2e197c29f213794
MD5 60e4f7a09af711278b3f1408502a9e9f
BLAKE2b-256 1badabed5a3a5013700219ad11af20d3402a4eb8243930649ce77e6351662f49

See more details on using hashes here.

File details

Details for the file httpout-0.0.42-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.42-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 464d9ba6b0c5f6a37965698a1c4d37374ce7b2b7bd3cbc70eb45c966689ce3cc
MD5 b4464426f9f01964ac36ec17d75b6d61
BLAKE2b-256 793721df10aa1d5d6610ffb67a4558b6bdf87b86dc40246ae57391e2fafd33e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.42-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 22a7c73e6c5fbaa61d97bb6c0746764ce1191da936726940febb03fe076ba6bc
MD5 808e392b57cce193e5754f0ee0a322f1
BLAKE2b-256 d53c79fe66500d87b4d1b378bbf35ff34767edc23bb5ec01d35ec7b19ccecf74

See more details on using hashes here.

File details

Details for the file httpout-0.0.42-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.42-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8afeafc78c0071c3829047e9feca1241b213fd5dbd6f0a74206a89fb907a029b
MD5 cafeceac772215d083240d873f1a8a55
BLAKE2b-256 8cafad198e10a1b3917750056e810c8508647cf9cb6cd44eb94e2eb4cff4701f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.42-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fcb18d5f59ca9eac9de053a5a2daa50ed706c218e9c661bf83468d29db9c7222
MD5 a265e8fa1b25ad68a4e3e561c0928128
BLAKE2b-256 fb595c81db11ab97df1b309247adf3ff052ed31c3c784e54526ccd141c2bb6ec

See more details on using hashes here.

File details

Details for the file httpout-0.0.42-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.42-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e1e71eb8d9d1388219d600e381b62c1ac479fa651ac1798eeb72c80b2df546b8
MD5 69b8acdeb784d7f60ce710ccd9824487
BLAKE2b-256 65f0811510305396dbdcf687f0f8483e04500262c33353ba42e1e4a79405b3b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.42-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 99a6e250c4d140999ce4ad7618553bd5c5e38cfc06a4fe563093d85d46b12a40
MD5 9392e3f6676f8b45e3f4f6fb6cc917c2
BLAKE2b-256 fc503bfac05c28c63d9ec0c7dcb447834d39747d3e38ca60e3cff8318bb6a368

See more details on using hashes here.

File details

Details for the file httpout-0.0.42-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.42-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3e75644933f142d6873917d7db85f7a12edc01606c8382b776b82c017741fa23
MD5 2bc3e0cf0a4cf0b1cfa7d183507143ac
BLAKE2b-256 7bea49fdfa84b9e676483cccd6d356e17950e71120a764f3ea51878cc15eb098

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.42-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 85aa6aa07a7e05d334f5f191b7847783f0c65b2277f6d99f371bfefa72db2395
MD5 d71ae6e11c3492c79fc5ac8cc180c6a6
BLAKE2b-256 db5c8ded50b13e280e4cc4239da2fb2880ab577b4375a895270fa7701181aa05

See more details on using hashes here.

File details

Details for the file httpout-0.0.42-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.42-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 19d2a4aabe8aef65097ad656ec5c159ae003055041d23fc49b6e7ef5af66a925
MD5 3c8ee52a53797db2453f45cf3c27c352
BLAKE2b-256 88a7287c032c76c41cb77502a5e9d880e5006d9bd74913c99971fbe6228b33f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.42-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1b344dbea8de616e67c7f3f9dbb20a0c2ace7a4c6a2db7737281642dcc2e0092
MD5 ffd03631debcbcdd7af24adfc3ba3fe9
BLAKE2b-256 07bcf3857d3572163b3d0800d133a8a4687eb9650db073bdf295c07a84c40196

See more details on using hashes here.

File details

Details for the file httpout-0.0.42-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.42-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 120669a06c3474a728a6895ae8b9e709f2cecfdc80681ea0876242fb7cd1f922
MD5 287a837e764cf2e4bf9c608fdee90a85
BLAKE2b-256 6537e7ca3614bafcefe88d9162fc67868d717ba6f22497c4477b53d6a47d5aa8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.42-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 25ad3317bfea84d465ee4319f0aee96a0d72149f9e2ac83efc3ad068ef7127d9
MD5 5a333162111864a143484997809120e2
BLAKE2b-256 f1cf635ae84a39ddfc13987d4188906cbaf8e6ea520ed815df4106dcd17cb658

See more details on using hashes here.

File details

Details for the file httpout-0.0.42-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.42-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b073d895a151af60dbb0f1c802d6bdc6eed68da2b22a2133f6504874476cb8c
MD5 1d7fdd8663df6c92c247cc67cb66e361
BLAKE2b-256 072e890398408c76b4923ee43ec0ad7887c262d19497b962e2b807df779bf079

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for httpout-0.0.42-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d94206256633d97366367b4a4d0a1140fcd6b1d7c12e11748c9805369252f980
MD5 6d40031e27cdb5a841bb9c849d4cc6c8
BLAKE2b-256 70f41ef14cbadbfb5e1b4abdc118d36adc8f9cd290f4c03efc0938a04c8888ad

See more details on using hashes here.

File details

Details for the file httpout-0.0.42-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.42-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f35f31f3b5eed9196065fde212a38b85b132d64c47815329c346c5b83737e7bf
MD5 1344e4b80cb32b0f37ab9ffb59cd4eca
BLAKE2b-256 927e71d211ab53c7ebf7b773a3ee3304a829a24dbede6f26953c2e7780d80e75

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