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

Uploaded Source

Built Distributions

httpout-0.0.47-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.47-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.47-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239.0 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

httpout-0.0.47-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.47-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (250.4 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

httpout-0.0.47-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.47-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.47-cp310-cp310-musllinux_1_2_x86_64.whl (227.3 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

httpout-0.0.47-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.47-cp39-cp39-musllinux_1_2_x86_64.whl (226.9 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

httpout-0.0.47-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (228.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

httpout-0.0.47-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.47-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

httpout-0.0.47-cp37-cp37m-musllinux_1_2_x86_64.whl (210.6 kB view details)

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

httpout-0.0.47-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (212.3 kB view details)

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

File details

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

File metadata

  • Download URL: httpout-0.0.47.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.47.tar.gz
Algorithm Hash digest
SHA256 7b15e6776195fc2d9039bc85b6d505871281f0e6382611ed45b6f1cd87678af0
MD5 4d1e9e66e31dbe9ce640a6b2abad506c
BLAKE2b-256 c3801c29edef59294ca43a05e62715e2dc68f3c7a9e87459f9204eb99006cdfa

See more details on using hashes here.

Provenance

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

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.47-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.47-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9e3d11090961abeaf2793f4c23553c8895b073542e0e538f0d161ba11226df15
MD5 7daa4e7bd4a4e54b6e03aacd9136033c
BLAKE2b-256 7ac59311d6813ac84351153cd4a970b7aa3b6bc1f087766235ec7157b1444b46

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d0dc4146843281fad62202ded1982a32373a2b2b0581ac14ac62c35df5b738a9
MD5 75ed5e84630885d4561841bf3c967e52
BLAKE2b-256 c02c13f2cdaf3adc54d16249d51dfd0b77ab2a0fb4ceeceab86d016c3df7c6bd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c758b3e49ba32d76193e9391923f37eb4d145c31e68e0f424405e660a9fda3b8
MD5 b7a1e5363ed4967040c738b8022c9033
BLAKE2b-256 7b4e1dc6c084240326b7b90cab609303733a4866498666b6c617975f3349787b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 927c42faa331232e7b6034b00ae4f5e7b66248bc3a798081317d0b9728e37aa0
MD5 08ffc4c75a3eba337ad35117a30970b2
BLAKE2b-256 db87d2dda8d08d37ded743083dc055ffc02db11761661fed2300cc8317e099f7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a028f92004745e54850ba3276ab13fc6b3ba9bfb13d2e827ea5072ee1be5d0cb
MD5 15f99d48e2fd53f1359fe5a04c143d49
BLAKE2b-256 d428379139177bda8cd81825617df919b843c9beb20e3a31da92e6de3d010133

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2cdc78faf526358263ec6eb3050502ab3475760fd4c01bc76cd92b8b23fff443
MD5 9140abed4da78888ef79037aee0d07a5
BLAKE2b-256 f9f2842cb009c581f30ca9e03f981f57743ede36555d9d4353b56b5981c18c8f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 019cb4020bc9e1ffe138d191f820de77af7e2d299964704c2b2453f8c26bc24b
MD5 fa53e6dae7528788899b4b67fae86f9b
BLAKE2b-256 a5bdc199b391db534d6f08e57dddfa375e780b0b4cc44b7c35941d2bbad849cd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5012c618cfa9fd9b2fafa4857f3230d98fab9d2c3134679b0b0a8f90b3f7e33b
MD5 c2fdc1105db6fdda648842ec00ef0d55
BLAKE2b-256 a22346224e0a5ee489fb2c53e570166e6d83d981129c980271ada7ebbbf89873

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4017b7f90c73dfadb3a40d507645757f2b6613d20b1912b98b1f65f0fe250743
MD5 83c6b4b6bd2eb9c1f6c7d3c745cf0ac9
BLAKE2b-256 6b986a7cabbd79aa9aeba0cd6d9956fcfa84e94fe061be633c01ba2caacd3df0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0feaf0dfc4619c6b40b45194f32a07e2d079bf748bc3ebc8651a1deb5fa35bed
MD5 9691bac0af305d4478125b7982ced00b
BLAKE2b-256 b1e7196c77369a4fcd5eaf9cc3286be42a91b9051d5cfd27cbf18ffd34b38b43

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5dd9cf200101e2288ae65ad8e2154353406735db4c8b604d96382feccac29c02
MD5 443af979e11aa901d7d21e1c9393601a
BLAKE2b-256 da53c388f5d50f2349ab41a7810a8b6c83c1a10af78ab5a9edee7501be625136

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8120965d43cdf5785342fb1adcf887084273ea30c06e7dcc1f69f442d4de259d
MD5 89deca721472817e9477573d7d4df3df
BLAKE2b-256 22f7d0356651133b466d12e930acc786e224a274c79a6eee31fc7be1c39070e1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9a1fbf6748c50bfe3cf11757273de924c9a3f319be87fac46ffe9a84f12d9946
MD5 d0479bad414fe8a65f66f55f294a639e
BLAKE2b-256 e18f6b8f270371bf169182ebb7da13d2349de5233467bbc5fdeb2a3914639f87

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e5265823093096f641777ce2e2a10ff9d3aa7726630dc9f20527061440e56622
MD5 36ca12a4fc412ea17468adca3f38d8b1
BLAKE2b-256 c075ede44b6c4b18c6345f4b7f6c1daa04a2d99be12694bbdc66a58f175ed59e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.47-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d6aba50e9a5bb041d1af1805adae83f32006e412130149f6532ced2199d156f7
MD5 90f6d5fead6fe4181fc2b5927da3a14a
BLAKE2b-256 26ed4ddd7b48b5aacba41bf2bb68d38e426b70d1b1e3224b94e90e244a9c7fbc

See more details on using hashes here.

Provenance

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