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 its corresponding file 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.60.tar.gz (73.4 kB view details)

Uploaded Source

Built Distributions

httpout-0.0.60-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (40.4 kB view details)

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

httpout-0.0.60-cp313-cp313-musllinux_1_2_x86_64.whl (180.1 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

httpout-0.0.60-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (180.2 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

httpout-0.0.60-cp312-cp312-musllinux_1_2_x86_64.whl (190.6 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

httpout-0.0.60-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (191.7 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

httpout-0.0.60-cp311-cp311-musllinux_1_2_x86_64.whl (184.1 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

httpout-0.0.60-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (183.2 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

httpout-0.0.60-cp310-cp310-musllinux_1_2_x86_64.whl (168.6 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

httpout-0.0.60-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (170.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

httpout-0.0.60-cp39-cp39-musllinux_1_2_x86_64.whl (168.1 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

httpout-0.0.60-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (169.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

httpout-0.0.60-cp38-cp38-musllinux_1_2_x86_64.whl (163.9 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

httpout-0.0.60-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (164.1 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

httpout-0.0.60-cp37-cp37m-musllinux_1_2_x86_64.whl (152.0 kB view details)

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

httpout-0.0.60-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (153.6 kB view details)

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

File details

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

File metadata

  • Download URL: httpout-0.0.60.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.60.tar.gz
Algorithm Hash digest
SHA256 59ce86484f40adb761de572b2b9e93591ad7ed672190ed2a304374f7a1464546
MD5 520efaa0964c335b8c85e421b6bbb600
BLAKE2b-256 0fcb8d3f39c315558c43eaa6de3c6bf10a93c3ca59bfa8732f564cf49e46ef8e

See more details on using hashes here.

Provenance

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

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.60-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.60-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0c07c19c143c250d310ff3edf1f42dc8dfea18498a3cdd03a90b9657b972bd8d
MD5 c938501f8e22354757991136da13ad1f
BLAKE2b-256 d78b2191073a8fc9b9873bc952b6816dbd4fe18f699cd58e0cff567f9e6ac154

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2afc86c41bf239fa8d15865a4ff0b3b9564cd100e1894da7c5226edf87375c5b
MD5 bf8be2da3ffccf8796523aa248af649f
BLAKE2b-256 3a62bc2bdba5429df1d66b9f5651b807fc89e1b9fbe030fe6bb1b6a656a7d210

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 814d175647219bff2bc2bcf1ee99b78ac1168cfb755a58b4748fbc75a9dc04ec
MD5 31db882109d18ec6d49fe7c3fea187f0
BLAKE2b-256 c77bd36737d06b52e88598a786e7c1b794f8f9dd412305e26e696743ca764c18

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 85cdcb671998f1a5a2eb3a6dae6f835e66259d3c80307c47b1469221dd2d52d0
MD5 33b6d01f1eb099d2f68acb098d849f16
BLAKE2b-256 1b97c689511faf4f1016286e7000e27e600a829229ccd3f6fb779e53e6c699e4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0e5b5ba61652270454eca23dcfddada5225eeaad11cc1842b251b77fe2d3efaa
MD5 78d9aba186408bf1aa3bc6afc5670b57
BLAKE2b-256 78b2423cd6095dd9b82acce2e3442290d031cd52131063f1ea3074de19a6b4c7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6aff6b631c93e5b1b60e920082f586d7563f0f0ebd26fffcd1cbe0c1998cc2a8
MD5 07a98bf21734e762d69c192bb91e4f94
BLAKE2b-256 52c659a5d4acc78be1fac96dd437f32d0441dfcd9aeb129d46c03bd07984b8f4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 549217e24fbe167728b5973756e26f5131524cda719f956cea9945185579ca72
MD5 cf49e7f45849c8fd031ba4f3e8388a65
BLAKE2b-256 fe46af1b96aa430b51ae24e89be965f4cbe62d262f98c4abba58c2208f7ce78f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 187f237322da15a9deacf69f5c261bddf6a34565f47ef5993bd202b275f84e3d
MD5 b67b5ff73d9cfffd21c102d5f6ef2857
BLAKE2b-256 b5ec8f96316f233634fe60ad19b6296552e1d750c1b4a58c6a90c4d7ed735a3c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 723ab927c1d76cba278da43f76cb079a424b2360228c10821e58cc732be53689
MD5 0a6a0090657454f28c484daa1e8f6558
BLAKE2b-256 84c1300818709d5f4b3f904c6f9e502bd7fa821052f0a7bffdfb8efa6890b12d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0fb3f7453ab6bf09965ff242c6b206f2fc4a2833693543944edf1158e3b2f159
MD5 72e5aacc5c38b34fa320b29bc43eeec7
BLAKE2b-256 defa52c00f936b1d3ff03de54f5ed9088da52031b5ee790e217c10a823cbe3a6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fe67db2440fc613486e6a2a3714868608f18f50e23e653a68a7ac0890d28475c
MD5 43f2d53a077ad8bb74996bd08cf0cd6e
BLAKE2b-256 21e86fccfcfa5a5cca724558d088e391939f68572ad85451076a56cce65a1f8d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b9628a54d74e7d2996d8986651c81abc8a535b4cf1b50413f965a3bb36f45cbd
MD5 5834a2571ce4760df15a62ba96e09e8e
BLAKE2b-256 2affb65b1553163f95ab979550fd2ef29d60564c4b444432d5b3ecc308724c03

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 78d6f3ec5f29f53cd69a027d4ffb050959cc8e0a639272ba323bd200321d80ef
MD5 486f66196246c8c58f33d76ffd4b35fa
BLAKE2b-256 18261a647a9e9a33d5813a02f4f0bf04b4fc856d79083e30af2ae95325cc9570

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ef5c7e6b9cffa2d68add32df9214cdf9bc3810b24c80223f18ecf4bc3598f399
MD5 9e7a81565c5677ebce3afab8b6fa5c39
BLAKE2b-256 7b850fa318cd9639580a8a30f903e718b067dad3c425c603dc490af18756b756

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.60-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cf6a6ba1e7a64279341d4f4e2d228f6fbeb9bf13e1879bf046b2d22b31d39559
MD5 f044f324f1711dbb00a069e0464721d9
BLAKE2b-256 ac9ebf8c9635902f0acd1aaf1611060f6a4938fa7043665dc9afec5831752703

See more details on using hashes here.

Provenance

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