Jump to content

web2py

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Marcuscalabresus (talk | contribs) at 21:07, 5 June 2012 (External links). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
web2py
Developer(s)web2py developers
Initial releaseSeptember 27, 2007 (2007-09-27)
Stable release
1.99.7 / March 4, 2012 (2012-03-04)
Repository
Written inPython
Operating systemCross-platform
TypeWeb application framework
License GNU Lesser General Public License version 3 (LGPLv3)
Websitewww.web2py.com
mailing list

Web2py is an open source web application framework. Web2py is written in the Python language and is programmable in Python. Since web2py was originally designed as a teaching tool with emphasis on ease of use and deployment, it does not have any project-level configuration files. Web2py was inspired by Ruby on Rails (RoR) and Django frameworks. Like RoR, it focuses on rapid development, favors convention over configuration approach and follows Model–View–Controller (MVC) architectural pattern.

Overview

Web2py is a full-stack framework in that it has built-in components for all major functions, including:

Web2py encourages sound software engineering practices such as

Web2py uses the WSGI protocol, the Python-oriented protocol for communication between web server and web applications. It also provides handlers for CGI and the FastCGI protocols, and it includes the multi-threaded, SSL-enabled Rocket[4] wsgiserver.

Web2py has frequent releases and is easy to update.

Distinctive features

Web-based integrated development environment (IDE)

All development, debugging, testing, maintenance and remote database administration can (optionally) be performed without third party tools, via a web interface, itself a web2py application. Internationalization (adding languages and writing translations) can also be performed from this IDE. Each application has an automatically generated database administrative interface, similar to Django. The web IDE also includes web-based testing and a web-based shell.

Applications can also be created from the command line or developed with other IDEs[5]. Further debugging options[6]:

  • Wing IDE allows graphical debugging of web2py applications[7] as you interact with it from your web browser, you can inspect and modify variables, make function calls etc.
  • Eclipse/PyDev — Eclipse with the Aptana PyDev plugin — supports web2py as well[8][9].
  • The extensible pdb debugger is a module of Python's standard library.
  • With the platform-independent open-source Winpdb debugger, you can perform remote debugging[10] over TCP/IP, through encrypted connection[11].

The Hello World program with web2py in its simplest form (simple web page[12] with no template) looks like:

def hello():
    return 'Hello World'

Web2py includes pure Python-based template language, with no indentation requirements and a server-side Document Object Model (DOM). The template system works without web2py[13]. Joomla 1.x templates can be converted to web2py layouts[14].

Web2py also includes the markdown2 text-to-HTML filter, which converts Markdown markup to HTML on the fly.

A controller without a view automatically uses a generic view that render the variables returned by the controller, enabling the development of an application's business logic before writing HTML. The "Hello World" example using a default template:

def hello():
    return dict(greeting='Hello World')

Ticketing system

Each web2py application comes with a ticketing system:

  • If an error occurs, it is logged and a ticket is issued to the user. That allows error tracking.
  • Errors and source code are accessible only to the administrator, who can search and retrieve errors by date or client-IP. No error can result in code being exposed to the users.

Portable cron

Cron is a mechanism for creating and running recurrent tasks in background. It looks for an application-specific crontab file which is in standard crontab format. Three modes of operation are available:

  • Soft cron: cron routines are checked after web page content has been served, does not guarantee execution precision. For unprivileged Apache CGI/WSGI installs.
  • Hard cron: a cron thread gets started on web2py startup. For Windows and Rocket/standalone web2py installs.
  • System cron: cron functions get force-called from the command line, usually from the system crontab. For Unix/Linux systems and places where the cron triggers need to be executed even if web2py is not running at the moment; also good for CGI/WSGI installs if you have access to the system crontab.

Bytecode distribution

Web2py can compile web applications for distribution in bytecode compiled form, without source code. Unlike frameworks that use specialized template languages for their views, Web2py can also compile the view code into bytecode, since it is pure Python code.

Supported environments

Operating systems, Python versions & implementations, virtual machines, hardwares

web2py runs on Windows, Windows CE phones, Mac, Unix/Linux, Google App Engine, Amazon EC2, and almost any web hosting via Python 2.4[15]/2.5/2.6/2.7.

Release versions of web2py include Python 2.5, but the source version can be run on 2.4 through 2.7.

web2py since v1.64.0 runs unmodified on Java with Jython 2.5, without any known limitation[16].

web2py code can run with IronPython on .NET[17]. Limitations:

  • no csv module (so no database I/O);
  • no third party database drivers (not even SQLite, so no databases at all);
  • no built-in web server (unless you cripple it by removing signals and logging).

The web2py binary will[18] run from a USB drive or a portable hard drive without dependencies, like Portable Python.

Web servers

Web2py can service requests via HTTP and HTTPS with its built-in Rocket server[19], with Apache[20], Lighttpd[21], Cherokee[22], Hiawatha, Nginx and almost any other web server through CGI, FastCGI, WSGI, mod_proxy[23][24][25], and/or mod_python.

IDEs and debuggers

Web2py has a built-in web-based IDE.

Database handling

The database abstraction layer (DAL) of web2py dynamically and transparently generates SQL queries and runs on multiple compatible database backend without the need for database-specific SQL commands (though SQL commands can be issued explicitly).

SQLite is included in Python and is the default web2py database. A connection string change allows connection to Firebird, IBM DB2, Informix, Ingres, Microsoft SQL Server, MySQL, Oracle, PostgreSQL, and Google App Engine (GAE) with some caveats. Specialities:

  • Multiple database connections.
  • Automatic table creates and alters.
  • Automatic transactions.
  • Distributed transactions:
    • Since web2py v1.17 with PostgreSQL v8.2 and later[26][27], because it provides API for two-phase commits.
    • Since web2py v1.70.1 with Firebird and MySQL (experimental).
  • GAE is not a relational store, but web2py emulates certain operations.

The DAL is fast, at least comparable with SQLAlchemy and Storm[28].

Web2py implements a DAL, not an ORM. An ORM maps database tables into classes representing logical abstractions from the database layer (e.g., a User class or a PurchaseOrder class), and maps records into instances of those classes. The DAL instead maps database tables and records into instances of classes representing sets and records instead of higher-level abstractions. It has very similar syntax to an ORM but it is faster, and can map almost any SQL expressions into DAL expressions. The DAL can be used independently of the rest of web2py[29].

Automatic database migrations

web2py supports database migrations—change the definition of a table and web2py ALTERs the table accordingly. Migrations are automatic, but can be disabled for any table, and migration is typically disabled when an application is ready for live distribution. Migrations and migration attempts are logged, documenting the changes.

Limitations:

  • SQLite does not understand migrations well. In particular it can't alter table and change a column type, but rather simply stores new values according to the new type.
  • GAE has no concept of alter-table, so migrations are limited.

Licenses

Web2py code is released under GNU Lesser General Public License (LGPL) version 3 as of web2py version 1.91.1[30].

Web2py code before version 1.91.1 was released under GNU GPL v2.0 with commercial exception.

Various third-party packages distributed with web2py have their own licenses, generally MIT or BSD-type licenses. Applications built with web2py are not covered by the LGPL license.

Web2py is copyrighted by Massimo DiPierro. The web2py trademark is owned by Massimo DiPierro.

Publications

web2py Book

The base web2py documentation is The Official web2py Book, by Massimo DiPierro. The manual is also available in printed form or as a read-only PDF.

  • 1st Edition: out of print. Wiley; September 16, 2008; 256 pages; ISBN 978-0-470-43232-7.
  • 2nd Edition: web2py Manual. Wiley; August 26, 2009; 341 pages; ISBN 978-0-470-59235-9. Read it online. Errata for the book.
  • 3rd Edition: Lulu; September 25, 2010 357 pages; Read it online.
  • 4th Edition: Lulu; December 9, 2011 583 pages; Read it online.

Online documentation

Online documentation is linked from the web2py home page, with cookbook, videos, interactive examples, interactive API reference, epydocs (complete library reference), FAQ, cheat sheet, online tools etc.

Videos

Printed

  • Web programming with web2py; Python Magazine; Marco Tabini & Associates, Inc.; June 2008

Background

Support

Community support is available through the web2py knowledge base, the web2py mailing list at Google Groups, and the #web2py channel on freenode[31]. As of 2009-10-02, commercial web2py support is provided by fifteen companies worldwide.[32]

Developers

The lead developer of web2py is Massimo DiPierro, an associate professor of Computer Science at DePaul University in Chicago. As of 2011, the web2py homepage lists over 70 "main contributors".[33]

Development source code

The web2py development source code is available from two repositories:

Third-party software included in web2py

History and naming

The source code for the first public version of web2py was released under GNU GPL v2.0 on 2007-09-27 by Massimo DiPierro as the Enterprise Web Framework (EWF). The name was changed twice due to name conflicts: EWF v1.7 was followed by Gluon v1.0, and Gluon v1.15 was followed by web2py v1.16. The license was changed to LGPLv3 as of web2py version 1.91.1 on 2010-12-21.

Applications built on Web2py

Notes