1. Home
  2. Python
  3. Pyramid Quickstart

Pyramid Quickstart

Overview

Pyramid is a Python framework that is the spiritual successor to Pylon and Zope, frameworks popular in the mid-to-late 2000s. Pyramid is supported with on v6+ platforms using any Python version from 2.7 onward with Passenger.

Quickstart

All commands are done from the terminal for convenience.

  1. PREREQUISITE: create a suitable Passenger-compatible filesystem layout
    • cd /var/www && mkdir -p pyramid/{tmp,public}
  2. OPTIONAL PREREQUISITE: determine a suitable Python version using pyenv
    • cd pyramid && pyenv local 3.3.5
  3. Install Pyramid.
    In the above example, using pyenv to set 3.3.5, Pyramid will be installed as a Python 3.3.5 egg.

    • pip install pyramid --no-use-wheel
  4. Create a startup file named passenger_wsgi.py, the de factor startup for Python-based apps. This is a simple “Hello World” application with routing that will, depending upon the route, respond with it. You can use vim or nano as a text-editor from the shell.
    from wsgiref.simple_server import make_server
    from pyramid.config import Configurator
    from pyramid.response import Response
    
    
    def hello_world(request):
     return Response('Hello %(name)s!' % request.matchdict)
    
    config = Configurator()
    config.add_route('hello', '/hello/{name}')
    config.add_view(hello_world, route_name='hello')
    application = config.make_wsgi_app()
    
    if __name__ == '__main__':
     server = make_server('0.0.0.0', 8080, app)
     server.serve_forever()
  5. Connect public/ to a subdomain
  6. Inform Passenger to serve this as a Python application:
    • echo "PassengerPython /.socket/python/shims/python" > public/.htaccess
  7. Enjoy!

Viewing launcher errors

In the event an application fails to launch, errors will be logged to passenger.log. See KB: Viewing launcher errors.

Restarting

Like any Passenger app, you can follow the general Passenger guidelines to restart an app.

See also

Updated on July 8, 2019

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help! If you get an error, visit https://lithiumhosting.com/support instead.
Contact Support