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

Uploaded Source

Built Distributions

httpout-0.0.51-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.51-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.51-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (238.9 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

httpout-0.0.51-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.51-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.51-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.51-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (243.0 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

httpout-0.0.51-cp310-cp310-musllinux_1_2_x86_64.whl (227.2 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

httpout-0.0.51-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.51-cp39-cp39-musllinux_1_2_x86_64.whl (226.8 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

httpout-0.0.51-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (228.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

httpout-0.0.51-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.51-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.51-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.51-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.51.tar.gz.

File metadata

  • Download URL: httpout-0.0.51.tar.gz
  • Upload date:
  • Size: 73.3 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.51.tar.gz
Algorithm Hash digest
SHA256 3f5d7bc5ccab5a758176888ab171570d8f2289edb88951ac0ac856602d0b133a
MD5 200b28fb496e1c0f0bcbfa8cf523f838
BLAKE2b-256 25f897941320d75dcefbe292ba2be77c3ed8f33d74fb55e0cd67d9fd406d1dd0

See more details on using hashes here.

Provenance

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

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.51-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.51-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b3c0058350819406b86facd69541e3d08e40b0232fec9762094627b6ab8b0cc
MD5 312885029ee0198f7b608ecd938c6c0f
BLAKE2b-256 23b5842a31024bb7a4de1a54142e5257f58f566e1f9c7fe5485bf190b04c7c51

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 aeef6745eb36c35d841b677d9099d9a03fbb4dfd113b941d82761a1574a9d8fa
MD5 0bcdc2fa928728882f518edda4252635
BLAKE2b-256 1a8941a837576a0bffbb9e6119dc87f7db28ec341f27bfcb836c510d6efba3d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 133db7bb5b10c59bc155fcf36440a70812a23d20005e09756ee6394179e2d265
MD5 8a7a42e4124068ab7ad527e58b0c25e0
BLAKE2b-256 9fb30bb68fe33ecfcd48e8e2cbf13a740b2dcd9bc5718c5a7fd53e1706138c22

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 51c51946081b707fb7dea7905ec5e96ab131b32e92555a3f2d096c0c457b6290
MD5 dfb1b09281771e73ece5afa4a4fae9cc
BLAKE2b-256 1f1be8d987aebf7735b6a78f48a18ab39720df45a0d958019abd155d24de7bf2

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 498b7c8fef97928d67017c3989b00a6786dd1772b23a1c0c5e2ec177738cabfb
MD5 4d20d684f0041c392ea6bfcf67a43812
BLAKE2b-256 8602482fcec31b82290e9b7e92ced24230697444effb0aa65056cd69c201b6ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9115c74464109bd5c5f08128bd429d132c8659be71f3ed9ecff835d4ca9ead0a
MD5 d0c1c82067392902f8ed3b1d637859b3
BLAKE2b-256 23cc3ede14fa69a7a69c30c359bd7e80c2c3ff0d6b9357ed62a8d8c6d581d76e

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bca41aecf7aeb6873e5210bda3e6b8591dd07be1666e35bc5472da16235ff0c7
MD5 d63fb0f6b4f7db7e6e55f584da2441b6
BLAKE2b-256 461e78f90a239622066fe5b76e34a2c15c86d66f6d2bbeea12fe14261ed6fb48

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fbc0309b8d3605af8774f9e156e2feee658d60d419a7a9bf0158eb0157d26c96
MD5 d9ca00f81be7a3409a1c02eb3b0603db
BLAKE2b-256 65be34d39a2398154ddcbf4ddbd88b71dfe62928a90254cbd64417a550f2c6ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d705b4c97a8449b8ffecd6cf89d3740ba0a7cecf5fe143b9922b1b784a295723
MD5 31a01b853d3db441a088b783e50c7a62
BLAKE2b-256 da1a606f1a872bd1e9b2103c052fcbe49cc63fa27e34699504d9c6d70a5219b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f8e6402fd07f1189c08f729a36381c0584f4a33248e4ab7f493a01949452f319
MD5 7a7404ae5c3acec7984fef98f80d35d2
BLAKE2b-256 42ccfaec66c186865ebb356c47f27eda2e8269b348d6169f612e3a40ac83c2dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7dc2ea1ffe30025ea3d4218bd31ca69478c5c864bbb996141cf12baf24c19cd3
MD5 0af0a69a45f1e4ef0ca622b4c963cbab
BLAKE2b-256 aada9c4b1b8659b75f22293c1151d7903f27b7c45138bb22a15fd3485213d933

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp38-cp38-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 aac8f71ac772069a260880c6fd7ccae37f6c327e6c9e8ce250057cfe1e1ae199
MD5 1eac42a0c2bd4fe49506e1c9561fe402
BLAKE2b-256 3afa66a258644c21429dd25319dff55ff384d15d4f97d3304ea8ca12cb747f8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f2faf8a1f1f57b903336bcf732911ede60f79421b27cc978879405780818f964
MD5 c095b973680c069a64f8abce3617fea0
BLAKE2b-256 a0df96a6f04c6232f476cf09e391ebd3a428793cfedeaad96c4deff79a71f0d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp37-cp37m-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 51ac50bc2b069b4f64e37ea55f91cefe05c915fec40ee145b8424757875dda58
MD5 9b156c64353ee689ffc434056e31b23f
BLAKE2b-256 2565fa3fa7de475acb69a797bff0809afee257f7b768ef3bc1f1cb707e23f988

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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.51-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.51-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 168c34a175b170441f231cf9a59dc2fd146cf7208bffdd539010a62f9db0d5e7
MD5 8879cb8eb3bd7063a1dbc92a9cd6c099
BLAKE2b-256 e4f34e29ed6c15baa18759506289670ed54191e9901090c67c9ba3a8f0a99c74

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.0.51-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