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

Uploaded Source

Built Distributions

httpout-0.0.55-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.55-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.55-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.55-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.55-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.55-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.55-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.55-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.55-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.55-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.55-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.55-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.55-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.55-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.55-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.55.tar.gz.

File metadata

  • Download URL: httpout-0.0.55.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.55.tar.gz
Algorithm Hash digest
SHA256 fb0a8610d958d17bdcefdd6b734e6c035c110e74e81bb6318c32922af1feed63
MD5 32c6a4453cbd3164db5ccd6f3cc5f461
BLAKE2b-256 b31e4678fcbaaebe548dcf29f8cc6949a065e232061ed5bda8c0e9823af55e58

See more details on using hashes here.

Provenance

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

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.55-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.55-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a557b716ed944bded0a8db3e3b2e0f5306445e0c0fe92e57f572ec6406817e1e
MD5 1aa297275c7d4e653d2ff87591d545b0
BLAKE2b-256 baba6ce17eb7ddb0937469556d9bff3ba952a8d85f38032568297234679cb9d5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bdf901daffd540322c427ce5941f584e9832fb4600ce436d97e55f4c65ca1363
MD5 4a7a8ca805bef8bc59b7854bf613dfbf
BLAKE2b-256 3c28ac3e0d1022a68155023d5d7db406b8edde58f4d3deb4ffe99e6339c3220c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cdec1f65ef8dc770b81a7c867b937571c589336b537202e890e4e36cb192c82c
MD5 edd00c1f16a50620903f6f0dba184686
BLAKE2b-256 998ddd464498a308834496b98ee69e24911699ad2149c8a9af4b05663dca5db4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cd67d5b216aef57bc8108590f56e45fbdc0ea72b4a6ba0937197532e1227f479
MD5 74435d80dfeb5fb4f946c4c3fb3d8133
BLAKE2b-256 abbbe79902de2fd2fd7e5a9fd1066ec848a88b41b9923055d6cbbe6ae378a68c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2ba346b86b4c4d2a16558696dd364aaaa9fa71f3c316d8d44daedf4f19c6dbf1
MD5 259f8fe4f13e00f1a268ff3b5ddcb2ee
BLAKE2b-256 e649cb574516f5b479e3564cbb9a358df6407a8a49c561f63149a8cb7498f413

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fbbbe8ef90f558080639471a7d1a637bc1954faff9ed5b10ce09c9abf07faf25
MD5 df58b2a45247527a969e18325814696d
BLAKE2b-256 327190d34c9b446d39d04e893e9db947793ac6dfa86485cf8d38b93fd1f84934

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ee1394e91464bf29465760d2b85205557c7702f513c6cdd0e4d972e3fae2d9aa
MD5 80a8bd39ea39e95372bb3419faa351b4
BLAKE2b-256 44ac200829c9a3fd8411a6c8b57c1adca4a2df2a64b7e7fd930d8d04f9581056

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5c7eafcf231f125c8d543e202c9deae9853ede3b11bf9bc21397f7f15a09f85f
MD5 652cf11d4038b69a495588dda0bd236c
BLAKE2b-256 54fdfce1fad6b841b7ce37309bf35cf5a4a8f3c903889ae817a3bd657fcbcf1d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c8d423fd4ed8bbb84163438cc747b20e081877245b909aae1580a9b376cf9306
MD5 a0d50904a862464199c49732b8a13b77
BLAKE2b-256 3694d37d6f3d142da9ad2b29ae966cc6a8234dc0bba38ebd33d9fac1de845c16

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 63139dfd79dfd23572a20f2f3723eaf638e100ed8df20e045d02128c488ae0d1
MD5 13c4e8f9bc3f1a171639241e13242173
BLAKE2b-256 e8b0f2f1cdf1be8605f30116a0f0eb05c3190a5f508efab2e0d1d827ff81b9db

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 410548314487bdec5420b9342add3b6d71b7e32c1df6a98086a40cf2e7a8bc6a
MD5 22acc77567c2b2c028081596c6457fc4
BLAKE2b-256 e6a2613b061158536336f897c0a4c21f2da889370c8e8d18a153801b293ad477

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e3f504ec55500fdeac1a170ed35d3607a2cd235df5c44f246431d2908cac52b6
MD5 44d6043875d7b9aeda940df05e966bfe
BLAKE2b-256 c58ff671f62f2009576e31f29c8dba8d8cd74e9a8f6815500bf1950ad4480e43

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c3692d3e603bfe146c2e6a7b1351f3035932478970b67940e52ad69e850dd59d
MD5 4838028c810b4087c832ea67138f50c6
BLAKE2b-256 ac20774a2ce851169ff9eb434ccd4ffe4df3b1434852ee8919a977f818da94b1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9cef389b04f79b9ee89d5138f2c3bd9fd490d3aebd32651f0b8292e488fb1343
MD5 29507aa41af8196ea035af495b5656b3
BLAKE2b-256 d35d9f7df48474121edc037f008b922e83415d22d1533ff3e64d85dd86dd4ed5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.55-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f680e5963c8df216b68af8d0e807744863e035025a6033cb8b07cf2e685fb510
MD5 ab13faee7143d5070a39b3351aee8b64
BLAKE2b-256 1f7095030f9a9d891d149c5cab4441f90a0f95c595ee3313c9374ee70a89b3d2

See more details on using hashes here.

Provenance

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