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

Installation

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
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')
    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
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')
    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.1.1.tar.gz (81.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

httpout-0.1.1-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (42.7 kB view details)

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

httpout-0.1.1-cp313-cp313-musllinux_1_2_x86_64.whl (193.4 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

httpout-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (195.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

httpout-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl (208.5 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

httpout-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (209.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

httpout-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl (203.0 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

httpout-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

httpout-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl (191.6 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

httpout-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (187.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

httpout-0.1.1-cp39-cp39-musllinux_1_2_x86_64.whl (190.2 kB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

httpout-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (185.2 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

httpout-0.1.1-cp38-cp38-musllinux_1_2_x86_64.whl (184.6 kB view details)

Uploaded CPython 3.8musllinux: musl 1.2+ x86-64

httpout-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (181.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

httpout-0.1.1-cp37-cp37m-musllinux_1_2_x86_64.whl (169.5 kB view details)

Uploaded CPython 3.7mmusllinux: musl 1.2+ x86-64

httpout-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (173.2 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: httpout-0.1.1.tar.gz
  • Upload date:
  • Size: 81.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for httpout-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e949b7166a012fee82bc0dfc94b65b76bd806889fd92119ae1104d52e1e1b469
MD5 ed41e4f1bb4386ce71f8e5e886e6d8b2
BLAKE2b-256 264a8558bc111f6cd186794ded8702725877e667faea946a34e254b61a7608b9

See more details on using hashes here.

Provenance

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

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file httpout-0.1.1-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.1.1-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c4e93baba41ddb82cc1f7a344e05f122626566ff3fbb461a22d8092f221d206f
MD5 80444f96ea162ba77a9bafa27b5adad8
BLAKE2b-256 fb2a1a09227192378874036e239071bf64e4e5b5d2e2aba0b60dfc705953265a

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-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: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for httpout-0.1.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 abf0c0574f097645cc0eac4ba6736e3b5be3a0be7aa0e1a4b52f66d2a5e5b979
MD5 49a8ecb52b0447d70a1b1b6941ca0bf4
BLAKE2b-256 59877c2079a4e21ff9e2a901eb3266b61c871dfc9deb07f1389e012882a04203

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file httpout-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6b770235f1c6eabfaa5123efe0fb1e292507a352b76d95560741f66ea3b9eedb
MD5 60a488b3fe0b564f4ffe3c74420f27e6
BLAKE2b-256 4cc8b98ac4ff8cbd96610b464989e656bca393865769c94e428f1fb997e76148

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for httpout-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 02545c22580c2e1861c6d1fc7d899c92947ee4ca1b27831e58ec0c3f00f410d3
MD5 925192e648fd13a22750e720d349cd84
BLAKE2b-256 509f376a30deaff375ed64cd1fd440269692e3e2f9c75a8dbe435b8e49926c0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file httpout-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5885eb1034796346f28289c770fc9fdb0557639a0cd8c4d4cbec5bca6b2ef30
MD5 612438c2c1e62b9c14df06c4a9f13560
BLAKE2b-256 9177c53e1ef009e1fb73d9cc62c60182d738d5e4ef8504e9e7c8013a1b4c7de1

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for httpout-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c2772c539d0f190057a7925c5b9a3d8868ced9cff77ef37fbfadfc68bcef91ef
MD5 d278ef94a1f01520f5d648db71aa1c8b
BLAKE2b-256 d22bf89f53e9377e7a696993658302459751e595a14281281d955a98ee6fcbaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file httpout-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0c328467e0b25fb70d30b9cc73d25414fc39587ec1ff8c756732cbebf1a33f2
MD5 2fff083660f10d5f7d55e390a7d7c117
BLAKE2b-256 26443115dda9786bd1cc957de1bcabe263da19d8a7f20213e7ed57c194a2b633

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for httpout-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4220d3953df4b9ee798463a40d0ad9052184d8a4d95075e4549c28afbff41605
MD5 850f21fa7960199dee17c57dc4900b8a
BLAKE2b-256 05f208ef59ed0d5dfb80b78f880fac4245c6c0810618235b996727cb26b9aaab

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file httpout-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 16c69a8732125dcf26d6ad1fefa6f62146ceb337caf26e19c3b45af0155b82d8
MD5 63f3ba59bb922a5e1f8b154f19a38427
BLAKE2b-256 e2eeea23cbd75876bb271a81f5cd73b3555eec56ea05390a0dfee6a32d4632aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for httpout-0.1.1-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8d16806bb0587ca15e0ef630cf1f0009684a16282280f6a99da36222bb8cb83f
MD5 a8d73d8d334d002b2e64aa5b29236b5a
BLAKE2b-256 3e613fc3ea930f2462b7ce21d0ffe78a259099caa2ce714db0d5e18d0a65ded8

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp39-cp39-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file httpout-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9d17afc212944e346448c23ccc59fe8880b5947fe60e93b99c384ee7deab9b2
MD5 62deabe988e8253ef32ea9003f8095a5
BLAKE2b-256 5778fb16b7160829ded0acd55f2da49f4cfc5a6d7232980f3e6ddfb8f74806f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for httpout-0.1.1-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9d9308184be3607f4193c523bc082d5740a2e1e762c08b4305f06db459450f11
MD5 081547bc8801d59e6a8571eff688a53c
BLAKE2b-256 e97616259c407aead4b9b4e53ff99ab7536074ddb8be35c4f79791faf36ed7cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp38-cp38-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file httpout-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 21a8e4b4b64b4bd6df703eadde55846df772e8b2dffbeb7c7deb6650620f2956
MD5 63e5611c8e8214854d3b0c0c6bd74e0e
BLAKE2b-256 3e0afe7fb3253b0261edeec36c0ac0bf26c5095156170d05365889cfe61469df

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for httpout-0.1.1-cp37-cp37m-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 03269e726e13292b5bccf05d9af13d862f230f37e9935528c9cf52ea0305a013
MD5 794865930c033c1b0f1435dfc92cd8c0
BLAKE2b-256 268324b9a3b7d6fa09c194bf6f93031475e844a3deab0702688c44c537eb0758

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp37-cp37m-musllinux_1_2_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file httpout-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpout-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8379ce2a49d2df5327de551d122089bac71541ecaf9f84d2c461ed18bcc35ea7
MD5 cd8dbbccc39973f579d35c247b62be4d
BLAKE2b-256 211b3a11d457e84f755ae17cfb5f8b76954303d3755f42522b59fe9ee74f09b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpout-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_release.yml on nggit/httpout

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page