[Python-ideas] A more useful command-line wsgiref.simple_server?

anatoly techtonik techtonik at gmail.com
Wed Mar 28 15:03:49 CEST 2012

On Wed, Mar 28, 2012 at 2:37 PM, Masklinn <masklinn at masklinn.net> wrote:
> Currently, calling wsgiref.simple_server simply mounts the (bundled)
> demo app.
> I think that's a bit of a lost opportunity

I remember the pain of using HTTPServer, CGIHTTPServer and friends
just to test a few html pages through a local browser, so I hear you.
Unfortunately, bug tracker is down for the maintenance for me to
search for similar reports for these libraries.

> it would be nice if wsgiref.simple_server could
> take such a file as parameter and mount the application provided:


> * This would allow testing that the script has no error without having
>  to go through mounting it in e.g. mod_wsgi
> * It would make trivial/test applications (e.g. dynamic responders to
>  local JS) simpler to bootstrap as there would be no need for the
>  half-dozen lines of wsgiref.simple_server bootstrapping and "hard"
>  dependency on wsgiref,

All points valid. That was also my use case for the CGI/HTTPServers.

> Since wsgiref already supports `python -mwsgiref.simple_server`, the
> change would be pretty simple:

Is it possible to choose a more intuitive name if it is for Python 3.3
only anyway?

> * the first positional argument is the wsgi script
>  if it is present it is `exec`'d, the `application` key is
>    extracted from the locals and is mounted through make_server;
>  if it is absent, then demo_app is mounted as before
> * the second positional argument is the host, defaulting to ''
> * the third positional argument is the port, defaulting to 8000

To summarize:
python -m wsgiref.simple_server [[wsgi_script.py] [[host] [port]]]

A better way:
python -m wsgiref.simple_server <wsgi_script[.py][:application]> [-h
host] [-p port]

But for good API it would be nice to see an overview of command line
params of other WSGI servers for some kind of convention.

> This way the current sanity test/"PHPInfo" demo app works as it did before,
> but it becomes possible to very easily serve a WSGI script with almost no
> overhead in the script itself.
> Thoughts?

1. Even more awesome if any WSGI application could be tested
(bootstrapped) this way.
2. Let test/"PHPInfo" serve forever and add few more tabs (pyrasite
for the current Python?)

anatoly t.

More information about the Python-ideas mailing list