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

Uploaded Source

Built Distributions

httpout-0.0.45-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.45-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.45-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.45-cp312-cp312-musllinux_1_2_x86_64.whl (249.6 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

httpout-0.0.45-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (250.3 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

httpout-0.0.45-cp311-cp311-musllinux_1_2_x86_64.whl (242.4 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

httpout-0.0.45-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (243.1 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

httpout-0.0.45-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.45-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.45-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.45-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.45-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.45-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.6 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

httpout-0.0.45-cp37-cp37m-musllinux_1_2_x86_64.whl (210.4 kB view details)

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

httpout-0.0.45-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (212.0 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

File details

Details for the file httpout-0.0.45.tar.gz.

File metadata

  • Download URL: httpout-0.0.45.tar.gz
  • Upload date:
  • Size: 73.4 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.45.tar.gz
Algorithm Hash digest
SHA256 803d2d9d107c1610858bcdb3e89e59bccc75e53bb6a5acf2867f257c8903665f
MD5 5a1e9f44deb1e29e2cfcaa71e7ee5b13
BLAKE2b-256 0c105902ce6399bf37b65ca929e4b9863a33fc786743d0b2db9c52e2ae17dae3

See more details on using hashes here.

Provenance

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

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.45-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.45-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cb1b21a3d1d9d904c07e64c62cf0869c2d14468d5296e3e8eca753016ff9f674
MD5 9ac949123a6b9607ba2d7d59bd653a9e
BLAKE2b-256 37a6ea9c0c661fee8df957c5b70ea851a15ebb003a5de6587607dec55efa3790

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 deeff02adc868e64fda4db7f22b070ad695f44ce2b16fe274d0410a9de6f6cc5
MD5 2f49f8b985f8c929c2c47ff551429ba7
BLAKE2b-256 8c2ab8905b7f353844f5ba5bd3a57d15c47862c4750d519499b8f57be2c9c485

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d786e29fbfc3a534e4d0fe4eab2744b8e200e4e5865c83425ecf2f9bf96d0544
MD5 baeaf9e82899dfc31584b9a798022774
BLAKE2b-256 ce0cbe50414a49c55a3f0c4f401784a80dd02c3ce77b60fabf212c9a71c35024

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1fc4d9f5446ba11e258f00c26b5c9404f85b598e7ef10a957523b34374531c9f
MD5 6f2c2476f675d2675afd1e78cfa1e6cc
BLAKE2b-256 be9bc743bf4bf80d56091ae32d091c10e265cee9097fb2ff34fe8a6d05243fda

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0670aba45229a074ad47a2933fdd78183c5580ab24aa10edcbabcbabda50ab41
MD5 7ce6e5a660d9a3b1f6a6d99a19671f91
BLAKE2b-256 8e0433db6888d0a14dfba5298b8973bfc185f55688f50cebaa2dd96e08a186ac

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 eaafe8eb99a3e7367843d9cee4ade5101e9bb91a1cd7282a83ddaa2a0c071c96
MD5 0674710eca7bb699ccd355e3745e2c87
BLAKE2b-256 8c62157c48c2997b1cca808a2808a8dbcedaf552272c5da84e8ce4798bcd3ca7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8db350723084a2dcea6dc0cd95759700b94000785bb2a465bce7621ef4fea5e7
MD5 2da9395837cb98e429dbeb634a8a542f
BLAKE2b-256 ea2cca6d08e90e3890ad2a2a51c230ade5711672f17f66c2dba7d724baa8d844

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d8b710a1108080d4a61005e46cc49c4c9b0e6c73a620262ef2f51a394252c885
MD5 4bad62fe96ba1c181731667ba586338d
BLAKE2b-256 2ba27de690e7c019001769b7d1bdfc6180760496ed4fe0189b48679bf2ea128b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dca8b2f76a5996df2ef49e8beb490443a3b5dec07f09749dd1b3c8ffc819be5a
MD5 2eb592cc2b2d26edb1e62c5d18908607
BLAKE2b-256 60129eea44d9c15d3849964bcbe5479dea8045166cb5fce217f05c46a78a1b11

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3af5610c699e0c553d5affc5a7f6e1fc348480891d62244bcc36c77965974d36
MD5 0217b29860b217b5b8770ff7e8bbe4f1
BLAKE2b-256 fdf11778b2373ecca6a3330985105a895ecfaeba7c7139dff3c712fa16c2d2ea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b8242ebcafb8d3652d1df623fc521433cdaad0f3b48e512e637812390abc8c63
MD5 086c70bee6fd979c6f39b65fea86c00e
BLAKE2b-256 716685622b6e96503becdf62bd93c312fa4a2f7ad51b28bbebd2e8d735b6b439

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7bc6427399b002b7a7e21c573109af2fb2fff099c687645ed13b945b93e54cc8
MD5 cf310b9b82b604fe6a529ba1a14b4bf3
BLAKE2b-256 09e59675ed603b72089c952d8b865ddca15fff20db38d43ae6cfc00629feb23f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2e702fb023c2f0c51161b9d26ad0039bc423884352b09c5a81a6defe4b8015da
MD5 601a704da7f448dd378f401f826bdf02
BLAKE2b-256 4ceb0dcbb40666de8373473af2ea5026c0e30c83457c0f2adf286cf865876d13

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e476287814655844be98bf62f769a468dca2ba9a38bda25353adf1eb96bd9cc0
MD5 b37a9e5f678f8a5ce88e49e290bb258a
BLAKE2b-256 f4ab2608bb7a119ce0932a9413163a99575fa3202f2b9772d94fe1bc0f3056ed

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.45-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 766b852c818c43751c17fbf656882b5b58b479bd82389362c652a66cb30aa5ea
MD5 43ca93d579fa0ff68f839b88accfb6fe
BLAKE2b-256 99876af7b98f8156a37612ac1439390c8a12ae86017f5ab1be34e2f340ff44fc

See more details on using hashes here.

Provenance

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