You can edit almost every page by Creating an account. Otherwise, see the FAQ.

Web.py

From EverybodyWiki Bios & Wiki






Web.py Web Framework
Original author(s)Aaron Swartz
Developer(s)Web.py GitHub project contributors
Initial releaseDecember 10, 2008; 15 years ago (2008-12-10)
Stable release
0.40 / September 27, 2019; 4 years ago (2019-09-27)
RepositoryWeb.py Repository
Written inPython
Engine
    TypeWeb application framework
    LicenseCreative Commons public domain software
    Websitewebpy.org

    Search Web.py on Amazon.

    Aaron Swartz - Creator of Web.py

    Web.py is an open-source python-based web application framework created by Aaron Swartz. It is designed to build a simple yet powerful web application. It allows the developers to create a web application from scratch giving them full control of all aspects of web development. The main idea behind this was “Think of the ideal way to write a web app. Write the code to make it happen.”.[1]

    Web.py helped Reddit.com to become a top website while Aaron developed it using Web.py. It can be used by anyone, for any purpose as the framework is available in the public domain.[1]

    History[edit]

    Aaron Swartz started working on Web.py in 2005. Aaron wanted a faster and simpler framework for python web applications. In 2005, while Aaron was working at Reddit.com, he used Web.py to build Reddit.com which helped Reddit become a top website with millions of daily views[1]. Later Reddit was rewritten using other modern-day web application frameworks. In 2013, at the age of 26, Swartz committed suicide in his Brooklyn apartment after which Anand Chitipothu[2] has been maintaining and developing web.py.

    Development Releases[edit]

    Web.py’s first official release on GitHub was on 10th December 2008 known as “webpy-0.31”[3]. Web.py has released 11 more versions of the framework over time. Web.py has seen continuous development before Swartz’s death. Web.py released its next major update in 2016, 3 years later Swartz’s death. After which, Web.py has released two more updates in 2018 and 2019 (latest release)[3]. Web.py is now being maintained and improved by the contributors of the GitHub Project.

    Latest Releases[edit]

    Web.py’s latest version, 0.40 released on 27th September 2019.[3]. The new version supports Python 2, but the maintainers will drop support for the Python version in their next release. The latest version adds functionality to connect to SQLite Databases through URLs and now supports SameSite cookies which helps in preventing CSRF attacks and making secure applications using the framework. The latest version also fixes major bugs including connecting to PostgresDB, IP Address Validation, DiskStore concurrency and many Python-3 compatibility issues[3]

    Features[edit]

    Web.py is lightweight and a fast web framework for python-based web apps. It was built around the idea of a minimalist framework[4]. Web.py’s slogan says, “Think about the ideal way to write a web app. Write the code to make it happen.”[1]

    Web.py has a built-in webserver accompanied by a debug feature which is automatically enabled when the application is in development mode. Developers use Web.py’s webserver and debugger together as it automatically refreshes the page after a change takes place in the code which helps them in quick and efficient debugging[4]. A debugging page is displayed if an error occurs with details on the error.[5]

    A Web.py web application can be deployed to any server supporting WSGI (Web Server Gateway Interface). WSGI connects the server-side applications such as Apache / Nginx to the web application side built using Python. WSGI helps the server to communicate to the application and return responses in HTML which is then shown to the client (user).[6]

    In the latest release, Web.py has added SameSite cookies which prevent CSRF attacks making the web application build using this framework secure for its users. It also has the functionality to allow concurrent data storage allowing the applications built on it to store data without any data corruptions or data losses.[3]

    A web.py application can be written according to the MVC (model-view-controller) design pattern[7]. But everything needs to be done from scratch like creating a config file, write a model file which will interact with the application’s database. The view file is rendered and shown to the end-user and the controller takes care of the computational logic which may determine what to do with a GET request or a POST request or any other type of request.

    Installation[edit]

    Web.py has a simple installation process. To install Web.py on a system with Python installed, you need to download the latest .zip from its GitHub project page, extract and a run an install script to install the framework[8].

    # download link -- latest version
    https://github.com/webpy/webpy/archive/0.40.tar.gz
    
    # install script
    python setup.py install
    

    Another way to install web.py is to use pip (python package manager) or easy_install[8].

    # using PIP
    pip install web.py==0.40
    
    # or using easy_install
    easy_install web.py
    

    This will install the web framework in the application folder with all its features including the inbuilt webserver and the debugger.

    To start writing a web application using web.py the first line should be import web. This imports web.py’s functions and packages like database and forms.

    A Simple Hello World program can be written using the code sample below[9].

    import web
    
    urls = ("/.*", "hello")
    app = web.application(urls, globals())
    
    class hello:
        def GET(self):
            return 'Hello, world!'
    
    if __name__ == "__main__":
        app.run()
    

    Code Structure[10][edit]

    According to web.py’s creator and supporters, Web.py should be used as an install and code framework, rather than setting up things. But it does have a structure as to how an application should be written.

    To write an app the first line of the app should be import web. This should be followed by any other packages a developer requires to build the application. A web application requires a list of URLs it has and information on which functions to run when that specific URL is used. This is declared by the line below.

    urls = (
      '/', 'index'
    )
    

    If a URL used is not specified in the URLs variable, then a 404 error should be thrown. The framework needs to have the function which should be used when a user uses a GET or a POST request in the application. An ideal way to do this is to create a class/object in python and then define the GET method or a POST method.

    class index:
        def GET(self):
            return "Hello, world!"
    

    This would simply print the string “Hello, world!” on a blank screen. At last, the program should know which function to run when the program is initialized/started. This is done through a default way of initializing python applications. But a developer needs to tell python about the things required for the application to be built and served on the server.

    if __name__ == "__main__":
        app = web.application(urls, globals())
        app.run()
    

    Templates[10][edit]

    A web application consists of multiple HTML webpages. In web.py all webpages are stored in a folder called templates. A web.py application webpage can be written in simple HTML or in templating language provided in the framework. The templating language could be used to write dynamic pages.

    Using the templating language each line of code must start with a $ sign.

    $def with (name)
    
    $if name:
        I just wanted to say <em>hello</em> to $name.
    $else:
        <em>Hello</em>, world!
    

    All HTML template files should be rendered and this should be done in the main file which has URLs and other functions. The following code is used to render all the templates inside the templates folder and return a page in the function call.

    # render all templates inside the templates directory
    render = web.template.render('templates/')
    
    # will return index.html
    return render.index()
    

    Developers can also write javascript code for the HTML pages using the jsdef templetor. This needs to be imported separately as it is an extension of the main Templetor of web.py. The code written in jsdef needs to be rendered which will then turn the code into a proper javascript code[11].

    import web
    import jsdef
    
    render = web.template.render("templates", extensions=[jsdef.extension])
    

    Additional Packages[edit]

    Web.py is a minimalist framework which means everything needs to be built from scratch. A web application needs to communicate with its database and store information collected from forms in the application. This requires developers to build the database and forms from scratch. Web.py has some additional packages which can be used to create databases and forms with validation in Web.py.

    Database Package[12][edit]

    A Database Package comes with Web.py which is same as sqlite3 python package which is used to create and connect to databases in python. To use the database package in the application you don’t have to import any other package. This package can be directly used from the same import web statement. A code example below shows a database connection in web.py.[4]

    import web
    
    db1 = web.database(dbn='mysql', db='dbname1', user='foo')
    db2 = web.database(dbn='mysql', db='dbname2', user='foo')
    
    print db1.select('foo', where='id=1')
    print db2.select('bar', where='id=5')
    
    db1.ctx.db.close()
    db2.ctx.db.close()
    

    Forms Package[13][edit]

    The forms package of the framework allows the developer to create forms with validation and securely send the data to the backend side of the application. Using the package, the developers can refrain from creating forms in HTML with poor security and ask the package to create the form. Developers need to tell the package what type of fields they require, and the validation required for that field. A code example below shows how a form is created in web.py.

    import web
    from web import form
    
    render = web.template.render('templates') # your templates
    
    vpass = form.regexp(r".{3,20}$", 'must be between 3 and 20 characters')
    vemail = form.regexp(r".*@.*", "must be a valid email address")
    
    register_form = form.Form(
        form.Textbox("username", description="Username"),
        form.Textbox("email", vemail, description="E-Mail"),
        form.Password("password", vpass, description="Password"),
        form.Password("password2", description="Repeat password"),
        form.Button("submit", type="submit", description="Register"),
        validators = [
            form.Validator("Passwords did't match", lambda i: i.password == i.password2)]
    
    )
    
    class register:
        def GET(self):
            # do $:f.render() in the template
            f = register_form()
            return render.register(f)
    
        def POST(self):
            f = register_form()
            if not f.validates():
                return render.register(f)
            else:
                # do whatever is required for registration
    

    Deploying[edit]

    A web.py application can be deployed to the servers using Fastcgi, mod_wsgi, uWSGI, PyISAPIe and using the Google App Engine Application. Information on how to deploy the application built using web.py framework is available online on webpy.org. The most common web services like AWS and DigitalOcean allow users to host web applications on Linux instances. A web.py can easily be installed on theses Linux instances and with the help of Nginx and mod_wsgi, the application can be made available for the end-user to use.

    A most effective way to deploy web applications, use more than one websites which can be used by the developers/testers or product owners to test functionality and page responsiveness. Applications built using web.py on a local machine has its debugging feature enabled by default but not on live servers. This can be done by adding the following lines in the main functions before everything else[10].

    web.config.debug = True
    

    This can be dangerous as it may expose the codebase to the end-user and increase the chances of attacks through SQL Injections, resulting in loss/leak of information from the database.

    Developers[14][edit]

    Web.py is maintained by GitHub contributors of the project who create new features and fix issues, keeping the framework up to date with today’s technology. The recent version has added some security which can be found in most websites build in recent times.

    Since 2008, a developer known as Anand Chitipothu has been the most active and contributing developers to web.py. Anand has 363 commits adding over 13,500 lines of code to the web.py repository.

    Another developer iRedMail has started contributing to web.py recently and was the one who released the latest version 0.40 of web.py. iRedMail has been constantly contributing to web.py by fixing and improving the codebase of the framework.

    Documentation[edit]

    Webpy.org, the official website for web.py has documentation for web.py (version unknown). Apart from this web.py has many tutorials on YouTube and other blogs created by other developers using or maintaining web.py.

    Read the Docs is a free documentation hosting website developed and supported by the developer’s community, which has documentation for web.py 0.37 (previous version)[15]

    Licenses[edit]

    The latest version of Web.py (0.40) is released with a public domain license. It is an open-source web framework, and anyone can contribute to this framework. Being available in the public domain[1] allows Web.py to be used by anyone and for any purpose without any restrictions. Although because web.py uses CherryPy’s web server since version 0.35, the webserver part is governed by the BSD License.[5]

    Use of Web.py[edit]

    Reddit.com was one of the first companies to use Web.py as its framework in 2005. Using Web.py, Reddit.com got access to a wider range of code libraries and it significantly increased their development flexibility. A year later in 2006, Conde Nast Publications acquired Reddit.com and the web application was rewritten using other tools.[1]

    Web.py is still used by many companies[4] around the globe

    • Yandex
    • Oyester.com
    • local.ch
    • Make History
    • Chiefmail
    • archvid.com

    Other Python Web Frameworks[edit]

    Like Web.py, there are many other web framework applications like Django, Web2py, CherryPy and many more.[16]

    References[edit]

    1. 1.0 1.1 1.2 1.3 1.4 1.5 "Philosophy (web.py)". webpy.org. Retrieved 2020-02-21.
    2. Guardia, Carlos De La (2016-12-07). "Python Web Frameworks". O’Reilly Media. Retrieved 2020-02-21.
    3. 3.0 3.1 3.2 3.3 3.4 "webpy/webpy". GitHub. Retrieved 2020-02-21.
    4. 4.0 4.1 4.2 4.3 zoriana. "web.py quickly implements simple Python web apps". Quintagroup. Retrieved 2020-02-21.
    5. 5.0 5.1 Grehan, Rick (2011-08-10). "Pillars of Python: Six Python Web frameworks compared". InfoWorld. Retrieved 2020-02-21.
    6. "Web.py Cookbook (web.py)". webpy.org. Retrieved 2020-02-21.
    7. admin. "webpy Example – Riaan's SysAdmin Blog". Retrieved 2020-02-21.
    8. 8.0 8.1 "Install guide (web.py)". webpy.org. Retrieved 2020-02-21.
    9. "Hello World! (web.py)". webpy.org. Retrieved 2020-02-21.
    10. 10.0 10.1 10.2 "Tutorial (web.py)". webpy.org. Retrieved 2020-02-21.
    11. "JavaScript templating with web.py". anandology.com. Retrieved 2020-02-21.
    12. "Multiple Databases (web.py)". webpy.org. Retrieved 2020-02-21.
    13. "How to use forms (web.py)". webpy.org. Retrieved 2020-02-21.
    14. "Contributors to webpy/webpy". GitHub. Retrieved 2020-02-21. Unknown parameter |url-status= ignored (help)
    15. "Welcome to web.py's documentation! — web.py 0.37 documentation". webpy.readthedocs.io. Retrieved 2020-02-21.
    16. "Python Frameworks: Full-Stack vs. Micro Framework - DZone Web Dev". dzone.com. Retrieved 2020-02-21.

    External links[edit]


    This article "Web.py" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Web.py. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.