Search code examples
pythonpyramid

Pyramid server port in environment variable or argument to pserve


I want to specify the server port for pyramid (using default pserve) through an environment variable or as a command line argument. Anyone done this before?


Solution

  • The command pserve --help tells us:

    Usage: pserve-script.py config_uri [start|stop|restart|status] [var=value]

    This command serves a web application that uses a PasteDeploy configuration file for the server and application. If start/stop/restart is given, then --daemon is implied, and it will start (normal operation), stop (--stop- daemon), or do both. You can also include variable assignments like 'http_port=8080' and then use %(http_port)s in your config files.

    So, for example:

    [server:main]
    use = egg:waitress#main
    host = 127.0.0.1
    port = %(http_port)s
    

    and run pserve mydevapp.ini http_port=1234