Lably
Skip to content

TurboGears

Python web framework

  • 7 min read
  • 4 chapters

Related on Lably

Through Python (programming language), Library (computing) and Data model

TurboGears is designed around the model–view–controller (MVC) architecture, much like Struts or Ruby on Rails, designed to make rapid web application development in Python easier and more maintainable. Since version 2.3 the framework has also been providing a "minimal mode" which enables it to act as a microframework for usage in environments where the whole stack is not required nor wanted.

TurboGears components

TurboGears is built on top of numerous disparate libraries and middleware. The default tools have changed between the 1.x, 2.x and 2.3+ series, but most of these components can be used in either as there is support for many alternative configurations. The following are the primary components a developer would interact with.

TurboGears 2.x components

  • SQLAlchemy (Model) - defines the table structures of the user's database and how to link them to Python objects the user's controller can interact with.
  • Ming (Model) - provides the data access layer for MongoDB, much like SQLAlchemy defines how to link MongoDB collections to Python objects the user's controller can interact with.
  • Kajiki (previously Genshi) (View) - defines templates for the HTML or XHTML the user will generate. This is where the user defines the front-end the client will interact with.
  • Repoze - Repoze.who is used to handle security (identification and authentication). Users can define authorization rules based on predicates attached to controllers, the framework already provides some built-in predicates, but custom ones can be written.
  • ToscaWidgets - is the primary widget library for creating forms and complex GUIs. Tosca by default will generate simple HTML forms, but can also be used as a middleware to connect to more advanced JavaScript widgets and toolkits. Unlike TurboGears 1.x, there is no longer a preferred/integrated JavaScript library.
  • Gearbox - is the toolkit used by TurboGears to manage projects, create new ones and serve TurboGears applications but the user can also connect to Apache, Nginx, or any other WSGI-compatible web server.

Versions before 2.3 would also use:

  • Pylons (Controller) - this middleware handles all the user's back-end logic and connects to the user's web server to offer up data to the web.
  • Paster was the command toolkit and web server used in place of Gearbox.
  • Repoze.what - Used to handle authorization respectively. When defining elements of the user's controller to be exposed to the web, repoze.what predicates define who can access them and under what conditions.

TurboGears 1.x components

  • SQLObject (Model) - data backend that can create a database or interface with existing data on many database servers.
    • SQLAlchemy is slated to become the default in TurboGears >= 1.1.
  • Kid (View) - XHTML frontend templating engine where all templates are valid XHTML or XML files that are usually made in a way that allows opening these templates as simple XHTML files to check the design. At the same time features are provided to embed snippets of Python in a XMLish manner.
    • Genshi is the successor to Kid and will replace it as the default templating engine in TurboGears >= 1.1. It is nearly 100% syntax-compatible to Kid.
  • CherryPy (Controller) - middleware that allows web applications to be programmed by writing event handlers that return data to (in TurboGears case) templates. The same data can also be received in Ajax fashion as a JSON data stream.
  • MochiKit is the preferred, but optional JavaScript library for TurboGears 1.x. It is a designed to make programming in JavaScript more pythonic. It is mostly used for implementing Ajax features and widgets as it provides an interface to get JSON data streams in asynchronous manner.

Sign in to keep reading

3 more chapters are free with a Lably account.

More in Computing and communication