Libraries

The web2py libraries are exposed to the user applications as global objects. For example (request, response, session, cache), classes (helpers, validators, DAL API), and functions (T and redirect).

These objects are defined in the following core files:

  1. web2py.py
  2. gluon/__init__.py gluon/highlight.py gluon/restricted.py gluon/streamer.py
  3. gluon/admin.py gluon/html.py gluon/rewrite.py gluon/template.py
  4. gluon/cache.py gluon/http.py gluon/rocket.py gluon/storage.py
  5. gluon/cfs.py gluon/import_all.py gluon/sanitizer.py gluon/tools.py
  6. gluon/compileapp.py gluon/languages.py gluon/serializers.py gluon/utils.py
  7. gluon/contenttype.py gluon/main.py gluon/settings.py gluon/validators.py
  8. gluon/dal.py gluon/myregex.py gluon/shell.py gluon/widget.py
  9. gluon/decoder.py gluon/newcron.py gluon/sql.py gluon/winservice.py
  10. gluon/fileutils.py gluon/portalocker.py gluon/sqlhtml.py gluon/xmlrpc.py
  11. gluon/globals.py gluon/reserved_sql_keywords.py

Notice that many of these modules, specifically dal (the Database Abstraction Layer), template (the template language), rocket (the web server), and html (the helpers) have no dependencies and can be used outside of web2py.

The tar gzipped scaffolding app that ships with web2py is

  1. welcome.w2p

This is created upon installation and overwritten on upgrade.

The first time you start web2py, two new folders are created: deposit and applications. The deposit folder is used as temporary storage for installing and uninstalling applications.

The first time you start web2py and after an upgrade, the “welcome” app is zipped into a “welcome.w2p” file to be used as a scaffolding app.

When web2py is upgraded it comes with a file called “NEWINSTALL”. If web2py finds this file, it understands an upgrade was performed, hence it removes the file and creates a new “welcome.w2p”.

The current web2py version is stored in the file “VERSION” and it follows standard semantic versioning notation where the build id is the build timestamp.

web2py unit-tests are in

  1. gluon/tests/

There are handlers for connecting with various web servers:

  1. cgihandler.py # discouraged
  2. gaehandler.py # for Google App Engine
  3. fcgihandler.py # for FastCGI
  4. wsgihandler.py # for WSGI
  5. isapiwsgihandler.py # for IIS
  6. modpythonhandler.py # deprecated

(“fcgihandler” calls “gluon/contrib/gateways/fcgi.py” developed by Allan Saddi) and

  1. anyserver.py

which is a script to interface with many different web servers, described in Chapter 13.

There are three example files in the “examples” directory:

  1. options_std.py
  2. routes.parametric.example.py
  3. routes.patterns.example.py

They are all meant to be copied to the root dir (where web2py.py or web2py.exe is) and edited according to your own preferences. The former is an optional configuration file that can be passed to web2py.py with the -L option. The second is an example of a URL mapping file. It is loaded automatically when renamed “routes.py”. The third is an alternative syntax for URL mapping, and can also be renamed (or copied to) “routes.py”.

The files

  1. app.example.yaml
  2. queue.example.yaml

are example configuration files used for deployment on the Google App Engine. You can read more about them in Chapter 13 and on the Google Documentation pages.

There are also additional libraries, some developed by a third party:

feedparser[feedparser] by Mark Pilgrim for reading RSS and Atom feeds:

  1. gluon/contrib/__init__.py
  2. gluon/contrib/feedparser.py

markdown2[markdown2] by Trent Mick for wiki markup:

  1. gluon/contrib/markdown/__init__.py
  2. gluon/contrib/markdown/markdown2.py

markmin markup:

  1. gluon/contrib/markmin

(see MARKMIN syntax for more)

fpdf created my Mariano Reingart for generating PDF documents:

  1. gluon/contrib/fpdf

This is not documented in this book but it is hosted and documented at https://github.com/reingart/pyfpdf

pysimplesoap is a lightweight SOAP server implementation created by Mariano Reingart:

  1. gluon/contrib/pysimplesoap/

simplejsonrpc is a lightweight JSON-RPC client also created by Mariano Reingart:

  1. gluon/contrib/simplejsonrpc.py

memcache[memcache] Python API by Evan Martin:

  1. gluon/contrib/memcache/__init__.py
  2. gluon/contrib/memcache/memcache.py

redis_cache

is a module to store cache in the redis database:

  1. gluon/contrib/redis_cache.py

gql, a port of the DAL to the Google App Engine:

  1. gluon/contrib/gql.py

memdb, a port of the DAL on top of memcache:

  1. gluon/contrib/memdb.py

gae_memcache is an API to use memcache on the Google App Engine:

  1. gluon/contrib/gae_memcache.py

pyrtf[pyrtf] for generating Rich Text Format (RTF) documents, developed by Simon Cusack and revised by Grant Edwards:

  1. gluon/contrib/pyrtf/

PyRSS2Gen[pyrss2gen] developed by Dalke Scientific Software, to generate RSS feeds:

  1. gluon/contrib/rss2.py

simplejson[simplejson] by Bob Ippolito, the standard library for parsing and writing JSON objects:

  1. gluon/contrib/simplejson/

Google Wallet [googlewallet] provides “pay now” buttons which link Google as payment processor:

  1. gluon/contrib/google_wallet.py

Stripe.com [stripe] provides a simple API for accepting credit card payments:

  1. gluon/contrib/stripe.py

AuthorizeNet [authorizenet] provides API to accept credit card payments via Authorize.net network

  1. gluon/contrib/AuthorizeNet.py

Dowcommerce [dowcommerce] credit card processing API:

  1. gluon/contrib/DowCommerce.py

PaymentTech credit card processing API:

  1. gluon/contrib/paymentech.py

PAM[PAM] authentication API created by Chris AtLee:

  1. gluon/contrib/pam.py

A Bayesian classifier to populate the database with dummy data for testing purposes:

  1. gluon/contrib/populate.py

A file with API for running on Heroku.com:

  1. gluon/contrib/heroku.py

A file that allows interaction with the taskbar in windows, when web2py is running as a service:

  1. gluon/contrib/taskbar_widget.py

Optional login_methods and login_forms to be used for authentication:

  1. gluon/contrib/login_methods/__init__.py
  2. gluon/contrib/login_methods/basic_auth.py
  3. gluon/contrib/login_methods/browserid_account.py
  4. gluon/contrib/login_methods/cas_auth.py
  5. gluon/contrib/login_methods/dropbox_account.py
  6. gluon/contrib/login_methods/email_auth.py
  7. gluon/contrib/login_methods/extended_login_form.py
  8. gluon/contrib/login_methods/gae_google_account.py
  9. gluon/contrib/login_methods/ldap_auth.py
  10. gluon/contrib/login_methods/linkedin_account.py
  11. gluon/contrib/login_methods/loginza.py
  12. gluon/contrib/login_methods/oauth10a_account.py
  13. gluon/contrib/login_methods/oauth20_account.py
  14. gluon/contrib/login_methods/oneall_account.py
  15. gluon/contrib/login_methods/openid_auth.py
  16. gluon/contrib/login_methods/pam_auth.py
  17. gluon/contrib/login_methods/rpx_account.py
  18. gluon/contrib/login_methods/x509_auth.py

web2py also contains a folder with useful scripts including

  1. scripts/setup-web2py-fedora.sh
  2. scripts/setup-web2py-ubuntu.sh
  3. scripts/setup-web2py-nginx-uwsgi-ubuntu.sh
  4. scripts/setup-web2py-heroku.sh
  5. scripts/update-web2py.sh
  6. scripts/make_min_web2py.py
  7. ...
  8. scripts/sessions2trash.py
  9. scripts/sync_languages.py
  10. scripts/tickets2db.py
  11. scripts/tickets2email.py
  12. ...
  13. scripts/extract_mysql_models.py
  14. scripts/extract_pgsql_models.py
  15. ...
  16. scripts/access.wsgi
  17. scripts/cpdb.py

The setup-web2py-* are particularly useful because they attempt a complete installation and setup of a web2py production environment from scratch. Some of these are discussed in Chapter 14, but all of them contain a documentation string inside that explains their purpose and usage.

Finally web2py includes these files required to build the binary distributions.

  1. Makefile
  2. setup_exe.py
  3. setup_app.py

These are setup scripts for py2exe and py2app, respectively, and they are only required to build the binary distributions of web2py. YOU SHOULD NEVER NEED TO RUN THEM.

web2py applications contain additional files, particularly third-party JavaScript libraries, such as jQuery, calendar, and Codemirror. Their authors are acknowledged in the files themselves.