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

Uploaded Source

Built Distributions

httpout-0.0.35-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.8 kB view details)

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

httpout-0.0.35-cp313-cp313-musllinux_1_2_x86_64.whl (24.0 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

httpout-0.0.35-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.0 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.35-cp312-cp312-musllinux_1_2_x86_64.whl (24.1 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

httpout-0.0.35-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.1 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.35-cp311-cp311-musllinux_1_2_x86_64.whl (23.8 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

httpout-0.0.35-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.8 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.35-cp310-cp310-musllinux_1_2_x86_64.whl (23.6 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

httpout-0.0.35-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.5 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.35-cp39-cp39-musllinux_1_2_x86_64.whl (23.4 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

httpout-0.0.35-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.4 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.35-cp38-cp38-musllinux_1_2_x86_64.whl (22.9 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

httpout-0.0.35-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httpout-0.0.35-cp37-cp37m-musllinux_1_2_x86_64.whl (22.5 kB view details)

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

httpout-0.0.35-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.4 kB view details)

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

File details

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

File metadata

  • Download URL: httpout-0.0.35.tar.gz
  • Upload date:
  • Size: 15.6 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.35.tar.gz
Algorithm Hash digest
SHA256 5024a2fa8d5d6d87336bf5551f4f52c81ff15ed0c2fefc6bb6f1f3bba0b74cb8
MD5 e189e5f13f12500d643730ea3d8ba437
BLAKE2b-256 63ff3d381ac5ede77ce99a3ba1d1645ea402a597ee647ad570a95b9768872d6b

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-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.35-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b2cd2a16474eb32e82067f06b31f230bfb13033f7dcb12bbbcd564c464fb844
MD5 c4e646d3ee42a346e8f8d7ec7e43ac22
BLAKE2b-256 564c44a72c83ac1d3fb90388482a154e39dc64dc65adefd623972ae50fbb0ef9

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.35-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2678498533eab16c980edc3c65b660a49e8484013bdb2e045f474d0c97f82088
MD5 972135bc6d3133739c031660ad0b2253
BLAKE2b-256 9299203c5fed12d08953f0bf24a106970eba4805f2a07261238c08cd1f9353e0

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp313-cp313-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.35-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 56c0632584a8a771a96da69cdac5a397cea98af066431d702081c29424aa3597
MD5 66587875d93ad7b4b44b63d022cb8323
BLAKE2b-256 2bcdae04aa288884ea80dc4ca5eb10380f6938e060d01acefdc242d987e4444b

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.35-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 84af3d2dc8af93d973cd4aa6c3dcb4b02673110e5a3ac4179ff9bafa7f6f5301
MD5 b0e087fd66bcfa75cc860c0c164f6f08
BLAKE2b-256 2bc44d57f8712fd1cda531d6acba1edb656623845e775b9e54a2aa53e2d23967

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp312-cp312-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.35-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4ed298f97b3e3c3553661ad76a4bf0c2b1681b7456a2df44c51987cdf01875ee
MD5 0f780379b947dee440d22cfe9f0c2b75
BLAKE2b-256 2690a937223154f3da4a6e314a00950973cdb6a14072dbe843495988d1f711e2

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.35-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 041c9bbf4064aad12c33cb584764bea21b1aa1586f159f22c33005bbcfdf6d33
MD5 161548033d45b80ceb9efefb24af30c2
BLAKE2b-256 69f50d8dff6b0481ec6ba586a8ebfa504b2e0fcf28300e33ee984c9c9d4ff1d2

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp311-cp311-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.35-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4af4a04e277e62a21a3950bf9382670a5b66ea031936d5b35eda155dd4b23c0f
MD5 eb536c9e06e0c94721b4ab99a4619ed6
BLAKE2b-256 40158ec3d5f71a01b368d5973c34ba7e493a63a8251e90f1c61bbcf7ee0dc934

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.35-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f4d35bf6e423d6cd0d8759deb327a6eb254cd5fdfa1c91becd62ff0d7f0acf50
MD5 b843bba7625fba09c2f130ea056fb300
BLAKE2b-256 845b1b87bda4307d5d5f87ea56c265c78100900213712f0ab10b3f43479c0d1c

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp310-cp310-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.35-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ba643d7f47d9bd47d2a83fb8a267eb0edb4c61ca71f436cdf5259ba31a760a3e
MD5 921b65f767569a26f92f5fefcdf444b9
BLAKE2b-256 3ed25f262188fc91b1c1f0506778eccc16e72d1448dd1106971cc040325dfeec

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.35-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e5342fda4e355f751f8ad7e2e71e620e277e9d482a195688d0ee53222104c0b8
MD5 49f061e296a09a7e003e8ae1d5bddc72
BLAKE2b-256 62e28b69fff0e52725fd02d901467dd83ad260b780606489c8213e08a7eb2489

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp39-cp39-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.35-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 561ef0c3c0512759ad3f99ab413c4be9278396a8120355d06e25293ea6118b1b
MD5 e0914038efa76b2f04c72f07d03f1053
BLAKE2b-256 ea8075b5d3d4cdeb1f74126bf7a9167813e967bb2816aad7edbef47efea56a71

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp38-cp38-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.35-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a6d31fa1acb9e53508ee26aa5d1b13e08f870e41ca75fbc28b483ad7094cebf4
MD5 3c123b976474a2294cdc9d1f0ab7b6ea
BLAKE2b-256 93297df453414aa79adf5416c51ab201cf7998d6816aa85ef3db782a7eefbcaf

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp38-cp38-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.35-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f61cf2ad3df65afe222f17c4d43fb4a85ffe9df81767305360b637c3db14a639
MD5 0c4e2e373d005442a1c62b6c261b52f6
BLAKE2b-256 c8fc34c441c89a28e1a33ec785e6ba647791ed67f99df1f1ab98a52f9a197603

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp37-cp37m-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.0.35-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 36eb17d6def5c00d1b19dabb08fb0fed7f33df7aae85813fe3e9afa4aec75a3f
MD5 b5737dd494f8262af21fe58d77c9f5d3
BLAKE2b-256 4f03ecee209d5b1587d76ec69df36f870ca653f0178c34f1b8e0eb4abf7c65e4

See more details on using hashes here.

File details

Details for the file httpout-0.0.35-cp37-cp37m-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.35-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5ce789409c19dae7363da75537190c317f2ee682374d99249fd71f302ec6f939
MD5 36e7efa5caeb78d6df68424d996e3f90
BLAKE2b-256 eae0a7834286d6602cfe4d4d77cc0d2cab2f406d9c1740b60b548fbb802f8c1d

See more details on using hashes here.

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