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:
web2py.py
gluon/__init__.py gluon/highlight.py gluon/restricted.py gluon/streamer.py
gluon/admin.py gluon/html.py gluon/rewrite.py gluon/template.py
gluon/cache.py gluon/http.py gluon/rocket.py gluon/storage.py
gluon/cfs.py gluon/import_all.py gluon/sanitizer.py gluon/tools.py
gluon/compileapp.py gluon/languages.py gluon/serializers.py gluon/utils.py
gluon/contenttype.py gluon/main.py gluon/settings.py gluon/validators.py
gluon/dal.py gluon/myregex.py gluon/shell.py gluon/widget.py
gluon/decoder.py gluon/newcron.py gluon/sql.py gluon/winservice.py
gluon/fileutils.py gluon/portalocker.py gluon/sqlhtml.py gluon/xmlrpc.py
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), andhtml
(the helpers) have no dependencies and can be used outside of web2py.
The tar gzipped scaffolding app that ships with web2py is
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
gluon/tests/
There are handlers for connecting with various web servers:
cgihandler.py # discouraged
gaehandler.py # for Google App Engine
fcgihandler.py # for FastCGI
wsgihandler.py # for WSGI
isapiwsgihandler.py # for IIS
modpythonhandler.py # deprecated
(“fcgihandler” calls “gluon/contrib/gateways/fcgi.py” developed by Allan Saddi) and
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:
options_std.py
routes.parametric.example.py
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
app.example.yaml
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:
gluon/contrib/__init__.py
gluon/contrib/feedparser.py
markdown2[markdown2] by Trent Mick for wiki markup:
gluon/contrib/markdown/__init__.py
gluon/contrib/markdown/markdown2.py
markmin markup:
gluon/contrib/markmin
(see MARKMIN syntax for more)
fpdf created my Mariano Reingart for generating PDF documents:
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:
gluon/contrib/pysimplesoap/
simplejsonrpc is a lightweight JSON-RPC client also created by Mariano Reingart:
gluon/contrib/simplejsonrpc.py
memcache[memcache] Python API by Evan Martin:
gluon/contrib/memcache/__init__.py
gluon/contrib/memcache/memcache.py
redis_cache
is a module to store cache in the redis database:
gluon/contrib/redis_cache.py
gql, a port of the DAL to the Google App Engine:
gluon/contrib/gql.py
memdb, a port of the DAL on top of memcache:
gluon/contrib/memdb.py
gae_memcache is an API to use memcache on the Google App Engine:
gluon/contrib/gae_memcache.py
pyrtf[pyrtf] for generating Rich Text Format (RTF) documents, developed by Simon Cusack and revised by Grant Edwards:
gluon/contrib/pyrtf/
PyRSS2Gen[pyrss2gen] developed by Dalke Scientific Software, to generate RSS feeds:
gluon/contrib/rss2.py
simplejson[simplejson] by Bob Ippolito, the standard library for parsing and writing JSON objects:
gluon/contrib/simplejson/
Google Wallet [googlewallet] provides “pay now” buttons which link Google as payment processor:
gluon/contrib/google_wallet.py
Stripe.com [stripe] provides a simple API for accepting credit card payments:
gluon/contrib/stripe.py
AuthorizeNet [authorizenet] provides API to accept credit card payments via Authorize.net network
gluon/contrib/AuthorizeNet.py
Dowcommerce [dowcommerce] credit card processing API:
gluon/contrib/DowCommerce.py
PaymentTech credit card processing API:
gluon/contrib/paymentech.py
PAM[PAM] authentication API created by Chris AtLee:
gluon/contrib/pam.py
A Bayesian classifier to populate the database with dummy data for testing purposes:
gluon/contrib/populate.py
A file with API for running on Heroku.com:
gluon/contrib/heroku.py
A file that allows interaction with the taskbar in windows, when web2py is running as a service:
gluon/contrib/taskbar_widget.py
Optional login_methods and login_forms to be used for authentication:
gluon/contrib/login_methods/__init__.py
gluon/contrib/login_methods/basic_auth.py
gluon/contrib/login_methods/browserid_account.py
gluon/contrib/login_methods/cas_auth.py
gluon/contrib/login_methods/dropbox_account.py
gluon/contrib/login_methods/email_auth.py
gluon/contrib/login_methods/extended_login_form.py
gluon/contrib/login_methods/gae_google_account.py
gluon/contrib/login_methods/ldap_auth.py
gluon/contrib/login_methods/linkedin_account.py
gluon/contrib/login_methods/loginza.py
gluon/contrib/login_methods/oauth10a_account.py
gluon/contrib/login_methods/oauth20_account.py
gluon/contrib/login_methods/oneall_account.py
gluon/contrib/login_methods/openid_auth.py
gluon/contrib/login_methods/pam_auth.py
gluon/contrib/login_methods/rpx_account.py
gluon/contrib/login_methods/x509_auth.py
web2py also contains a folder with useful scripts including
scripts/setup-web2py-fedora.sh
scripts/setup-web2py-ubuntu.sh
scripts/setup-web2py-nginx-uwsgi-ubuntu.sh
scripts/setup-web2py-heroku.sh
scripts/update-web2py.sh
scripts/make_min_web2py.py
...
scripts/sessions2trash.py
scripts/sync_languages.py
scripts/tickets2db.py
scripts/tickets2email.py
...
scripts/extract_mysql_models.py
scripts/extract_pgsql_models.py
...
scripts/access.wsgi
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.
Makefile
setup_exe.py
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.