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

Uploaded Source

Built Distributions

httpout-0.0.54-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.54-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.54-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.54-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.54-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.54-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.54-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.54-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.54-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.54-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.54-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (169.7 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

httpout-0.0.54-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.54-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.54-cp37-cp37m-musllinux_1_2_x86_64.whl (151.9 kB view details)

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

httpout-0.0.54-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.54.tar.gz.

File metadata

  • Download URL: httpout-0.0.54.tar.gz
  • Upload date:
  • Size: 73.3 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.54.tar.gz
Algorithm Hash digest
SHA256 7d48485bdc5364de225d7f1741714bb9a3c6da243d353596a728fdbf3ded505c
MD5 821812878031dee74fd5b9699e999930
BLAKE2b-256 d2fc91e880cb06f8d28b0a2826fccb8243a018a8c5e4148558f3fb5b6c70dfaa

See more details on using hashes here.

Provenance

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

Publisher: build_and_release.yml on nggit/httpout

Attestations:

File details

Details for the file httpout-0.0.54-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.54-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9dcb936d6cc2b614ac7df929004fab4ad4464125336456717b4a67eb1820013c
MD5 ed2f904a80dbf2efab1bdae9019173b4
BLAKE2b-256 4c7c7bff3f8313e842d1e4c76751016a898fb535ee124e9d193a007136ddb5a4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9596fe5c4dbd95fcbcc2bf8e6d93977081583ce38ec39d2f2352c6017c9ec411
MD5 b84600b32161e405228019147855c540
BLAKE2b-256 80dd030521c23228ecb1fad03b2c8f6e32fb5dba7d5058ebb9d00436b6fcb976

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 01874cb02d702bc23d9dbaa330f597da13f9e39393fe40f10877607021b33415
MD5 cc5519d3166282ecf0eada2fd2f22a19
BLAKE2b-256 319a74fad22ffba49cfde3f324e1d25ac7fc01f507f801a6a485500909f10821

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bd041b3cac2fa147cefb979d5e9ac888f5287dbd13abd383146329c6bc702f4f
MD5 9006f309e074d7047950755f17f8e549
BLAKE2b-256 8fea5cf77b1dbec9fd1c7dfc6f812e8bed44cef81d7b200159beae7d9c1de4fb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6d91746d9c5c6361d224eb4d76b4dbad8583de505500acd5bf48d3e968bdfbde
MD5 28074754d091e4437f7c45e7e69e3223
BLAKE2b-256 327b366b1f37b84245ab70846d25a58f929ea2968a15c1314c66c93dcf444f93

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5581692f2a19a31e0f12dbd5fac5cefba4cf669e01f5784653e451b5cc66cc8e
MD5 c415383ed4b86aad172995bbfc303e26
BLAKE2b-256 b6b391cc4b45bf4081b05c8aa9c8b1a7d01fe5fbec01c5e636424c0f77bc0370

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c6b16b39bd4d3ff7a25ef09e57297c5a26fdb87b9699d7ab1ae0fa70c1c3121d
MD5 f740141ba4715acc931d72ae4d1ebd00
BLAKE2b-256 5973578e01f9cf16727798cb1ea3de96e4a0da3f71a47236225ade03137e5608

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bd459aaa70709fa7457601282081b494fda2ff23ce3ea7181e16312fa8e81c60
MD5 039c3bff05ecf9cadb4a93f7f89dcf80
BLAKE2b-256 842636f5c7c6e24a4dd22fee6658a27db5e1cb30826f6213e6577bfd10b9a59c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc4b952f6057e967193a518e5afb90dd5821fa061ca9d2f3c0a7acca56e89c01
MD5 fdab9cd86d789cbe1ade049bfe30ed43
BLAKE2b-256 65a06320d3abf249cdfd8bca40c0989de0811f95035e13e9c6afdc6824b995ef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d6fd09b14bcde2a278517091f5fac86ec8f86b76f71945b3085e324beb55a82f
MD5 9a9a5b88e20b8ae20e212eb5e63a735c
BLAKE2b-256 30e7280b66fb23de4cf72536a30ee343e031bf284215f43988e8a6f987d16742

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a7e9fe407055453b3497a5fe9dda17bc0536c388c4e3dc9455708d7d0aca36aa
MD5 8ce9002c8cd1bbb7eda42fd8986e0160
BLAKE2b-256 790d1c657fd28aed74506b7e6d2bf993a929986fe634ced0502dad7d22367bd8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7fc40c2f55f404acaf10eee8d328a50eed1522f571c4b22d593ccf5dc84bf3d8
MD5 cd0bae9939ea789760fe660a80cd6b04
BLAKE2b-256 0edabc0f9fdc706a636301d9df2c18162cd817d7ef3541f52b65906b7c8a0b8f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55380b258c67316dc13dc4c7e643342f13bf140be104bbe785cee8a65ca3669f
MD5 271f2d6fe394fecdd0312b9ccc459f4e
BLAKE2b-256 5bbfeb3d1ef2ada940f82f50b570779b5313c47c1c29a0cde4715f0bab228dfa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5644f6dda9b5cf327a3e8e920b79cac1c7aaf0f2946182a564fe3b31d3961b69
MD5 427686eceab7c0e4fdfbb39dba416d1d
BLAKE2b-256 3d0ebe51326b5474d754bb925cee4351250e863461beb802ce03130fa84c2357

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for httpout-0.0.54-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 15a518d3f11afca75d1e991774e1d2e07d464b936f73851e1f2f66b2d31fdd6d
MD5 317936f5a8889b2d21044567faed8f3b
BLAKE2b-256 6e3d3980861c5bee19fb7bba0fad2c8c5d5e8d1c3c44921b1ee96ece824f5a12

See more details on using hashes here.

Provenance

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