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

Uploaded Source

Built Distributions

httpout-0.0.52-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.52-cp313-cp313-musllinux_1_2_x86_64.whl (238.7 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

httpout-0.0.52-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.52-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.52-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.52-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.52-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.52-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.52-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (229.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

httpout-0.0.52-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.52-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.52-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.52-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

httpout-0.0.52-cp37-cp37m-musllinux_1_2_x86_64.whl (210.5 kB view details)

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

httpout-0.0.52-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (212.2 kB view details)

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

File details

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

File metadata

  • Download URL: httpout-0.0.52.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.52.tar.gz
Algorithm Hash digest
SHA256 6e825f5a91bf39ea21c1b5936422213146221d4c1d44d4b6fa7f353b739b8678
MD5 0347644aaec640e4e3a91496834b6e0e
BLAKE2b-256 db8d02664dc4f9160c31342a1efbeb651fb47493cdc7eb8acff903f1440234ac

See more details on using hashes here.

Provenance

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

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.52-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.52-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a46c3d1da03f3f55d4ec02e87f751d81d1b7d3973e490f5f80e9d320d84da1f0
MD5 de6b8669c9c14faa7be7affa2a51dbe7
BLAKE2b-256 cca4fc6431d35327e1ce11b56ed2df936027c7890558bf43da14e99be0551dcb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ad027fb34e5121a686e0c1f12ef6fefde473079798fc00dbdf15f3f0df0ffef2
MD5 4b6cc3c45d34bd1ac5b1a95a5648fa80
BLAKE2b-256 2797cd543b1403840743d6c2dd57efca21e0ba679593b15a7d43a44dfdf9c05b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e598de7e0a83cabb967735b6d400c48a257cfe7a411046036c3f049498febd4e
MD5 c491477e48ab10c3a1e4e3a7d0373872
BLAKE2b-256 fcab486f994134b52948eac13560b2fefd5606387970b010129a10cfa699f5f3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 df58665e70866ad3e1ba4a643fa2776385e2d166f2140ff0eb7f8445dd11050d
MD5 48ebf2a8b6bdac48c3f430b7e6101f87
BLAKE2b-256 a72d6a767efb45871a16b4d135f7f1d7836c044dfb7db013fce9c451e5fc9d9d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f7dc05f9b89f848d3a985a4c2a62c0e6633dace97f50f28cf4312954e51f957
MD5 8c84af206413da52cdd176763e4e92f5
BLAKE2b-256 7e062761881c83cee726a1c0b83e3b3f74878ef273619cd0f4fde18d8035e04e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c11ec0bfe937689e96781661f575ebe24ef1bf747cf6a854678eeea6f98dc87f
MD5 e5e7be7a00a58ca3d41830506d710e5f
BLAKE2b-256 8f3b4c8a01ef72985043da3ce67657f2b88b1dccfb63409e8aef9fa2afa5c3f5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8e4de432a26d9b7b55a5a099b4a6231307df54f07060a7a078f7a9184839a7e7
MD5 15971eab5e49cc9528c7a220e46154b0
BLAKE2b-256 a83cf370e0049976da8c0ddaf65e67f8039ff961928674985f40428dbeb8fd5a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ec64b118734ee4a58bd0ecf7783b46b018f0c166f670a3fcd46288d590b68d55
MD5 76de98d5db2a46cfe69f6faa1637f35c
BLAKE2b-256 3eff071bdcdbc9b46291d73e54f51431f6f4885d7cfba972f29715f439faf2d3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b2b0d91228c331b2b4fb3bd423939fa6c246ca3935d856dd5b2887042310a34
MD5 d4ed47b09844973c4d29b6eeb3ac2fd0
BLAKE2b-256 3f0a42a7f8212796f99c18a582ecf9d63afd0df9b750adeae5508e47bec1377f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 44ea4ce1abb498ade73727de7a36cd02f47d29519fbed94db67e30cc4f92cb8c
MD5 93707a291e74aff24d3572239b33e1fb
BLAKE2b-256 094116aa63423ea4dc867fa9c8582e7570b4cb87b9371b603b26af989060b288

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d666e67d6262b60d67fa1504c76f52694c84b54bd8059b2f7b888ef3f11627a7
MD5 e3c29e5c3dee99cfe8734772ee018f1d
BLAKE2b-256 74a4df8107c13720739e3370966950c32b407f35f90c7100b3a9aeef57916be1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ebd97bcbbdebef8c340b5095b451e64390da51f666cbb4cb7bda9754ea764a86
MD5 d59a930e896158c589ac2dedb93b888c
BLAKE2b-256 355bd50a538c998b9772a7050386c7b356cec193b19e1da409a6f7334acca51f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2f2f877eb9dd65a96673779b99ab9b3a65fe34c89300bd52272192275d09543e
MD5 3bfc98eb6727c7c310817385c208e7a7
BLAKE2b-256 faa420cc22a68590bc558943ac03c3325a8df1be8b530bfc268e6829c26e1baf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 149c0035e87291ff1369a60c6a985c2b1fc4eeebf48cfe496b197017b381106b
MD5 d0fc553af0222f281db0f182748b9c5d
BLAKE2b-256 f4bcc2b857180d614c2df78bd9813a1909d2e949c7baa2a3d71fee69af381d43

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.52-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0c6b5360c439ef463b8c1cbe810ac651c6d91e2d8486cbf18ebda6a91d81c7c
MD5 8b3c765de109293d7b82d05515ef6e19
BLAKE2b-256 e43b2def6bd1aa54441f3a4d1e0c3d1a4286a5d9d6eb4701f3dc50b40bdcd3f1

See more details on using hashes here.

Provenance

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