public
Description: bottle.py is a fast and simple micro-framework for small web-applications.
Homepage: http://bottle.paws.de/
Clone URL: git://github.com/defnull/bottle.git
bottle /
name age message
file .gitignore Fri Nov 27 01:34:56 -0800 2009 New static_file() function returns HTTPError in... [defnull]
file MANIFEST.in Sun Nov 22 23:53:24 -0800 2009 Added docs to release manifest [defnull]
file README Mon Oct 12 19:39:11 -0700 2009 Added README as a symlink [defnull]
file README.md Thu Sep 24 10:13:28 -0700 2009 Typo [defnull]
file bottle.py Tue Dec 15 08:27:08 -0800 2009 Merge branch 'master' of git@github.com:defnull... [defnull]
file bottledb.py Wed Dec 09 03:08:10 -0800 2009 Added the obsolete BottleDB classes to a separa... [defnull]
directory docs/ Tue Dec 15 08:12:23 -0800 2009 Some docs [defnull]
directory homepage/ Tue Dec 15 08:21:12 -0800 2009 Missing image for the homepage [defnull]
file setup.py Thu Jul 30 02:37:58 -0700 2009 Workaround for Python 3.0 SyntaxErrors when imp... [defnull]
directory test/ Tue Dec 15 08:11:31 -0800 2009 Made tests work better with 2to3 [defnull]
README.md

Bottle Web Framework

Bottle Logo

Bottle is a fast and simple WSGI-framework for the Python Programming Language. It offers request dispatching with url parameter support (routes), templates, key/value databases, a build-in HTTP server and adapters for many third party WSGI/HTTP-server and template engines - all in a single file and with no dependencies other than the Python Standard Library.

For news, bugs and documentation visit the bottle.py homepage.

Installation and Dependencies

You can install bottle with easy_install bottle or just download bottle.py and place it in your project directory. There are no (hard) dependencies other than the Python Standard Library.

Example

from bottle import route, run, request, response, send_file, abort, template

@route('/')
def hello_world():
    return 'Hello World!'

@route('/hello/:name')
def hello_name(name):
    return 'Hello %s!' % name

@route('/hello', method='POST')
def hello_post():
    name = request.POST['name']
    return 'Hello %s!' % name

@route('/static/:filename#.*#')
def static_file(filename):
    send_file(filename, root='/path/to/static/files/')

@route('/template/test')
def template_test():
    return template('template_name', title='Template Test', items=[1,2,3,'fly'])

run(host='localhost', port=8080)

Template example:

%message = 'Hello world!'
<html>
  <head>
    <title>{{title.title()}}</title>
  </head>
  <body>
    <h1>{{title.title()}}</h1>
    <p>{{message}}</p>
    <p>Items in list: {{len(items)}}</p>
    <ul>
    %for item in items:
      <li>
      %if isinstance(item, int):
        Zahl: {{item}}
      %else:
        %try:
          Other type: ({{type(item).__name__}}) {{repr(item)}}
        %except:
          Error: Item has no string representation.
        %end try-block (yes, you may add comments here)
      %end
      </li>
    %end
    </ul>
  </body>
</html>

Licence (MIT)

Copyright (c) 2009, Marcel Hellkamp.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.