Tree [ff7730] default / examples / web_framework /

Read Only access

File Date Author Commit
 TurboGears2 2008-08-30 mtnyogi mtnyogi [97f053] Commit in preperation for release.
 README 2009-03-19 mtnyogi mtnyogi [28aa4e] - Fixed bug in examples/web_framework/README 2008-12-29 mtnyogi mtnyogi [5d0d34] - Changed second param to engine.__init__ to be...
 director.html 2009-10-19 mtnyogi mtnyogi [f3d7de] Changed all references to svn to hg.
 movie.html 2008-03-06 mtnyogi mtnyogi [e67fdb] 1. Moved pyke/ to pyke/knowledge_en...
 movie2.html 2008-03-06 mtnyogi mtnyogi [e67fdb] 1. Moved pyke/ to pyke/knowledge_en... 2009-03-26 mtnyogi mtnyogi [124b5d] - Yet another attempt at making web_framework.t... 2009-10-25 mtnyogi mtnyogi [87e5be] Dropped all of the sub-testX scripts.
 siege.urls 2008-07-01 mtnyogi mtnyogi [eb84e0] 1. Added Schema.{dia,png} to examples/sqlgen 2009-03-26 mtnyogi mtnyogi [124b5d] - Yet another attempt at making web_framework.t... 2009-10-25 mtnyogi mtnyogi [87e5be] Dropped all of the sub-testX scripts.
 testall.config 2009-10-28 mtnyogi mtnyogi [473574] Replaced testall script to use doctest-tools
 web.krb 2008-12-27 mtnyogi mtnyogi [fe1a23] - Looks like sqlite3 conversion is working now....
 web_framework.tst 2009-10-25 mtnyogi mtnyogi [87e5be] Dropped all of the sub-testX scripts. 2009-03-26 mtnyogi mtnyogi [4aaf2b] - Some web_framework cleanup, for Python3.0 and...

Read Me

This example automatically generates programs to render HTMLTemplates
(  You can use
easy_install to install the HTMLTemplate package.

It uses the sqlgen example on the back-end to generate and run SQL statements.
You'll need to first set up the sqlgen example database before using this
example.  Check there for the movie_db schema.  You'll also need the directory
containing the "examples" directory to be on your PYTHONPATH (e.g., if you
downloaded the pyke_examples separately).

This is also an example of using multiple rule bases (its own rule base, and
the sqlgen/database.krb rule base).

This example also caches the plans returned from pyke so it should be extremely
fast.  In fact, in siege tests compared to this same example running in
TurboGears 2.0, this web framework is a full 10 times faster than TurboGears!

To run this example:

    >>> from examples.web_framework import simple_server

Then point your browser at:


The "movie/1" says that you're starting with a unique row (id of 1) in the
"movie" table.  The "movie.html" is the name of the HTMLTemplate file you want
to use.  You may specify multiple unique starting tables by pairing the table
name with the id value: "/movie/1/genre/2/movie.html", though this doesn't
make much sense with the example templates...

    This uses backward-chaining to build a program to fill an HTMLTemplate.

    The top-level goal is:

        process($starting_tables, $template_name)
        taking (db_cursor, starting_keys)

    The plan returned from this goal returns a three tuple:

        http_status, header_list, html_document
    The WSGI front-end that drives pyke and executes the resulting plans.
    This parses the path from the WSGI environ and creates a plan for the
    combination of starting_tables and template_file, if one hasn't already
    been created by an earlier request, or if the template_file has been
    modified since the last plan for it was created.

    To create the plan, it establishes some of the interesting values in its
    environ as facts, then does the "process" goal above.
    The plan returned is run with the specific key to produce the WSGI output.

    To echo all sql statements to stderr, set the TRACE_SQL environment
    variable to something other than False prior to executing python.
    This is just a simple driver to run the wsgi_app as a local http server
    (default port 8080).  The 'run' function takes two optional arguments:
    port=8080 and logging=True.  Pass logging=False to disable logging
    requests to stderr (e.g., for performance measurement).
    This is a test driver to let you type goals in and run them to debug the

    Test functions:

            Creates a pyke engine and calls load_mysql_schema.load_schema.
            Loops on "goal: " prompt.  Type a goal, or trace/untrace rule_name.
            Empty string terminates the loop.  When the plan is returned,
            it enters a loop prompting for a python expression to run the plan
            (the plan itself is in a variable called "plan", and "Db_cursor"
            is a variable containing a database cursor).  For example:
            "plan(Db_cursor, {'movie': 1})".  An empty line terminates the plan

    Two very simple html templates that you can play with.

    A list of all combinations of movies 1-6 with movie.html and movie2.html
    for the siege program.  This measures the performance of the web server:

        $ siege -c 2 -f siege.urls
    Invokes the simple_server under cProfile.  Use siege to stimulate the
    server, then type ctl-C to interrupt it:

        Terminal 1                      Terminal 2
        --------------------------      --------------------------
        $ python                        
        >>> from examples.web_framework import profile_server       
                                        $ siege -c 1 -f siege.urls
        >>> profile_server.stats()      

    The 'run' function takes two optional arguments: port=8080 and
    logging=False.  Pass logging=True to enable logging requests to stderr.
    This creates the web server socket, then forks the process to get N long
    running processes all accepting connections from the same socket.  Each
    process will connect independently to the database server when they
    receive their first request.  Use ctl-C to kill all of the processes.
    This will fully utilize multiple processors to achieve higher throughputs:

        $ python
        >>> from examples.web_framework import preforked_server
        >>>     # 2 is the number of processes


    The 'run' function takes three optional arguments: num_processes=2,
    port=8080 and logging=False.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks