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

Uploaded Source

Built Distributions

httpout-0.0.53-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (40.3 kB view details)

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

httpout-0.0.53-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.53-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.53-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.53-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.53-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.53-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.53-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.53-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.53-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.53-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.53-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.53-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.53-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.53-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (153.5 kB view details)

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

File details

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

File metadata

  • Download URL: httpout-0.0.53.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.53.tar.gz
Algorithm Hash digest
SHA256 a488fb27f357f4702243dd06afb2b22af2c310b7a704139828cf3c300e25f087
MD5 3a9ef50d4c180291eb097d8a20a0173d
BLAKE2b-256 a3216ebd585e4e71c8a90e9b8165a21e9c289f4f5f73f547de76434156853a8c

See more details on using hashes here.

Provenance

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

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.53-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.53-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 616952a5866c5dd7ca16deef0b8959501abecbfaabef2fab907dd679c3d947a6
MD5 381e1d50924cb693e78f514cbb191f08
BLAKE2b-256 42680b5d27a8bd8b1189071c5b4a15eb2121a1a9664966f6c3f358b0c9979f4f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9a27c4b74477aef58e97b0b9d2c51943ebc175906c661767606f2afa099af529
MD5 b852fee28a18e7f4823c2005a9b7733d
BLAKE2b-256 0c0169a5b4b89f132d0d9d540d5e0f8985e7ec2f839d7be537312c224e69c94e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 16db1a885dd236d103bfe9e3b417e52b57d582d886ff8a0a3d9fe0431aeafcb7
MD5 d4015c89b95ed6ec718a848d4dbcf1ae
BLAKE2b-256 a11eb0af026b0ac378e0a5fd1e3def725eb650979f92e60c90d9f519716fec93

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bfb8bdba28fdfb9594286c0ddb48e39340867f786bd534fd52b4092915ddbf5a
MD5 aae362b2bbe2bd1462387e1d7cae6ad6
BLAKE2b-256 39c069a18cd9bcae2e4bbe8096cae363ba0bd9de27fb895111ff71133c6e31ab

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8c854e2c247ab4dc87bf47cc20abde843af4b8d14f2704a10a78d49a8a95c1c8
MD5 a5ac17862c2829d993fcc9b29a409ae2
BLAKE2b-256 189b1399332fa1dc9c7f266985864e1077b2c243fae147e85d444dc9f047b201

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d1092c2c08443a0fb9a6c5fe8204315b6cf3c371548708b2621330c823131787
MD5 d5b6b64625d3fad8446dec685847055f
BLAKE2b-256 96bf40a57fef627869c34f7b201ed8dd1ebba33adacac978a819035210942c28

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b9588a8c5c143a0128d99f6dd01245461775cae31fdb295d9fd48c04d0f02280
MD5 5ee94f73847c6a694766b9d81b6784c3
BLAKE2b-256 76f0dbec31d4e14aa9cf82921792a091c48ead9a3f9bc8d919513886f06e2379

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c2cd22bf4ac178e46bf38baabe22354001e3c5fa8a8bbb8a2e1a4f71ae6758c6
MD5 3525c3a33b37ce351ca7ab1d698e2d7e
BLAKE2b-256 aae57103fb9f7ab92d839c7ccbe1682161ff67822f7706c526d4de2386e2d74a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4c939b8b933b669175c8d5b7223e60b992c3022af1c1e25cf67294c3cee539d0
MD5 adc066b9f1e190aade27394c344316bf
BLAKE2b-256 e3284c2012ee42a057ac5045bfeb9156df0fd9ceddb8bd053d52db30d7cd4ae5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a256f5d2c1108c7fe39c104a18dae66168212ba416acc24d238e4570880c37ac
MD5 59f7eaea508fe7d77e5b41959d1092fe
BLAKE2b-256 9566c520872e18a05f471dd8889ac71974c8bcc8e2e01f2fe49bdba93f115627

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6bdddf583a3f467fbbb57a07af5fcb79ddf9f1035f6d472ada5554bf6d0674d
MD5 8dbf01521072b79240d219b9c1144c2c
BLAKE2b-256 1e66e9abe114dc7d2f2a74d5b861c376c8e71ec37a4ff92f4de350bf3c00ee71

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 21ac0ff8fc2659bc5ec43f796172102981e5e8a5393308a82d91c348d49e7c59
MD5 0c951bbfe9a4f4242087d432a8007bf7
BLAKE2b-256 95a07996883204dc075d914d7d9855b47599ebaca3e7b06c062d0a837cf913f1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3d7c31bfb81ffc25fd93361ccd7c0317b8f506f7711fbe8044475c198781199b
MD5 932d9860048655bac1b64114e3557d4d
BLAKE2b-256 64432db7a6b933ef7473cc5acedeeb65645284a492b2d5f87722d62c1f3d27e1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 43a2864faf00fcca3485c96268e4a78d79925f43f375b90347d0f88c559c3745
MD5 0c7ac8803eb4685096c1de28ffd134df
BLAKE2b-256 8a767630a4defc44b276ab8d0e87cb6e2e3e46c5e137f1e9dbeca36d8ce96281

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.53-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 74b0da7def082730f888b11108f9114216a80667fda7627f5b7f2205d3d8cfab
MD5 fffd4494cdc824347cea4926cc8505e8
BLAKE2b-256 d5eff22e49a7afb14143fcf30f2df492c6477287157e3965715d7c965ce36779

See more details on using hashes here.

Provenance

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