Dash Framework

Dash Framework ”; Previous Next In this chapter, we will discuss about the Dash framework in detail. Dash is an open-source Python framework used for building analytical web applications. It is a powerful library that simplifies the development of data-driven applications. It’s especially useful for Python data scientists who aren’t very familiar with web development. Users can create amazing dashboards in their browser using dash. Built on top of Plotly.js, React, and Flask, Dash ties modern UI elements like dropdowns, sliders and graphs directly to your analytical python code. Dash apps consist of a Flask server that communicates with front-end React components using JSON packets over HTTP requests. Dash applications are written purely in python, so NO HTML or JavaScript is necessary. Dash Setup If Dash is not already installed in your terminal, then install the below mentioned Dash libraries. As these libraries are under active development, install and upgrade then frequently. Python 2 and 3 are also supported. pip install dash==0.23.1 # The core dash backend pip install dash-renderer==0.13.0 # The dash front-end pip install dash-html-components==0.11.0 # HTML components pip install dash-core-components==0.26.0 # Supercharged components pip install plotly==3.1.0 # Plotly graphing library In order to make sure everything is working properly, here, we created a simple dashApp.py file. Dash or App Layout Dash apps are composed of two parts. The first part is the “layout” of the app which basically describes how the application looks like. The second part describes the interactivity of the application. Core Components We can build the layout with the dash_html_components and the dash_core_components library. Dash provides python classes for all the visual components of the application. We can also customize our own components with JavaScript and React.js. import dash_core_components as dcc import dash_html_components as html The dash_html_components is for all HTML tags where the dash_core_components is for interactivity built with React.js. Using above two libraries, let us write a code as given below − app = dash.Dash() app.layout = html.Div(children=[ html.H1(children=”Hello Dash”), html.Div(children=”””Dash Framework: A web application framework for Python.”””) And the equivalent HTML code would look like this − <div> <h1> Hello Dash </h1> <div> Dash Framework: A web application framework for Python. </div> </div> Writing Simple Dash app We will learn how to write a simple example on dash using above mentioned library in a file dashApp.py. # -*- coding: utf-8 -*- import dash import dash_core_components as dcc import dash_html_components as html app = dash.Dash() app.layout = html.Div(children=[ html.H1(children=”Hello Dash”), html.Div(children=”””Dash Framework: A web application framework for Python.”””), dcc.Graph( id=”example-graph”, figure={ ”data”: [ {”x”: [1, 2, 3], ”y”: [4, 1, 2], ”type”: ”bar”, ”name”: ”Delhi”}, {”x”: [1, 2, 3], ”y”: [2, 4, 5], ”type”: ”bar”, ”name”: u”Mumbai”}, ], ”layout”: { ”title”: ”Dash Data Visualization” } } ) ]) if __name__ == ”__main__”: app.run_server(debug=True) Running the Dash app Note the following points while running the Dash app. (MyDjangoEnv) C:UsersrajeshDesktopMyDjangodash>python dashApp1.py Serving Flask app “dashApp1” (lazy loading) Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. Debug mode: on Restarting with stat Debugger is active! Debugger PIN: 130-303-947 Running on http://127.0.0.1:8050/ (Press CTRL+C to quit) 127.0.0.1 – – [12/Aug/2018 09:32:39] “GET / HTTP/1.1” 200 – 127.0.0.1 – – [12/Aug/2018 09:32:42] “GET /_dash-layout HTTP/1.1” 200 – 127.0.0.1 – – [12/Aug/2018 09:32:42] “GET /_dash-dependencies HTTP/1.1” 200 – 127.0.0.1 – – [12/Aug/2018 09:32:42] “GET /favicon.ico HTTP/1.1” 200 – 127.0.0.1 – – [12/Aug/2018 09:39:52] “GET /favicon.ico HTTP/1.1″ 200 – Visit http:127.0.0.1:8050/ in your web browser. You should see an app that looks like this. In above program, few important points to be noted are as follows − The app layout is composed of a tree of “components” like html.Div and dcc.Graph. The dash_html_components library has a component for every HTML tag. The html.H1 (children = ‘Hello Dash’) component generates a <h1> Hello Dash </h1> HTML element in your application. Not all components are pure HTML. The dash_core_components describe higher-level components that are interactive and are generated with JavaScript, HTML, and CSS through the React.js library. Each component is described entirely through keyword attributes. Dash is declarative: you will primarily describe your application through these attributes. The children property is special. By convention, it’s always the first attribute which means that you can omit it. Html.H1 (children=’Hello Dash’) is the same as html.H1 (‘Hello Dash’). The fonts in your application will look a little bit different than what is displayed here. This application is using a custom CSS stylesheet to modify the default styles of the elements. Custom font style is permissible, but as of now, we can add the below URL or any URL of your choice − app.css.append_css ({“external_url”:https://codepen.io/chriddyp/pen/bwLwgP.css}) to get your file to get the same look and feel of these examples. More about HTML The dash_html_components library contains a component class for every HTML tag as well as keyword arguments for all of the HTML arguments. Let us add the inline style of the components in our previous app text − # -*- coding: utf-8 -*- import dash import dash_core_components as dcc import dash_html_components as html app = dash.Dash() colors = { ”background”: ”#87D653”, ”text”: ”#ff0033” } app.layout = html.Div(style={”backgroundColor”: colors[”background”]}, children=[ html.H1( children=”Hello Dash”, style={ ”textAlign”: ”center”, ”color”: colors[”text”] } ), html.Div(children=”Dash: A web application framework for Python.”, style={ ”textAlign”: ”center”, ”color”: colors[”text”] }), dcc.Graph( id=”example-graph-2”, figure={ ”data”: [ {”x”: [1, 2, 3], ”y”: [4, 1, 2], ”type”: ”bar”, ”name”: ”Delhi”}, {”x”: [1, 2, 3], ”y”: [2, 4, 5], ”type”: ”bar”, ”name”: u”Mumbai”}, ], ”layout”: { ”plot_bgcolor”: colors[”background”], ”paper_bgcolor”: colors[”background”], ”font”: { ”color”: colors[”text”] } } } ) ]) if __name__ == ”__main__”: app.run_server(debug=True) In the above example, we modified the inline styles of the html.Div and html.H1 components with the style property. It is rendered in the Dash application as follows − There are couple of key distinctions between dash_html_components and HTML attributes − For style property in Dash, you can just supply a dictionary, whereas in HTML, it is semicolon-separated string. Style dictionary keys are camelCased, so text-align

Quick Guide

Python Web Development Libraries – Quick Guide ”; Previous Next Python Web Development Libraries – Introduction Whenever a user opens any web browser like Google Chrome or Mozilla and search for ‘Web development’, thousands of results appear in no time. What makes this possible? Web development! It broadly refers to the work associated with building, creating and maintaining websites for hosting via intranet or internet. The work associated in website design contain multiple areas: web programming, database management, web design, web publishing, etc. Web development includes all the codes that influence a website to run. We can separate the whole process of web development into two categories − Front-end Back-end Though frontend and backend web development are certainly distinct from each other, they are also like two sides of the same coin. A complete website relies on each side communicating and operating effectively with the other as a single unit. Both front-end and back-end are equally important in web development. The front-end or client-side of an application is the code responsible for everything the user directly experiences on screen from text colors to buttons, images and navigation menus. Some of the common skills and tools which are used by front-end developers are listed below − HTML/CSS/JavaScript CSS preprocessors Frameworks Libraries Git and Github Generally, the back-end/server-side of an application is responsible for managing information within the database and serving that information to the front-end. The back-end of a website consists of a server, application, and database. In general, it involves everything that happens before hitting your browser. The tools required in back-end web development are − Programming language − Ruby, PHP, Python, etc. Database − MySQL, PostgreSQL, MongoDB, Oracle, etc. Why Web Development? In today’s world, there are multiple choices to promote your business or skills and share your ideas. Some of them are promotion through websites, native applications in marketplaces, etc. The trend of creating new website as a tool of business development is rapidly gaining momentum around the world. But, some of us may be unaware of the importance a website holds in the growth of a business. Currently there are numerous start-ups struggling to establish their presence in the open market. However, it is also true that most of them fail to gain as much targeted audience as they want. One primary reason which is bringing them down is that they underestimate the potential of a full feature developed website to earn business for them. Website development for business or any other purpose can prove quite fruitful. Let us look at some of the important reasons why website development is important for business growth − Reaching out to your audiences Online websites can reach to broadest audience and are not restricted to a platform that constrain native applications. The viewers or customers can have easy access i.e. from a desktop/laptop to a mobile device, as websites have the capability to display the content through web browser. In comparison to native application, web browsing is much simpler because it does not require users to access the app store on their devices or download their app (which may include one or more processes in accessing to your contents). Distribution of your data is much more flexible and agile with web-based application than native ones as there are no stringent app store requirements and content restrictions to follow. Another tool which is very helpful for web development is the power of utilizing SEO techniques to target your audiences. 24/7 Accessible Instead of establishing a physical outlet for the company, if the business owner develops a website as an online forum or similar, there will be good chance of gaining larger audience online to link up. This is because, most of the people are wired up with the Internet all day. Generally, people prefer to go for the smartest way to check online first and then take a decision. So if the business owner fills all the basic details of the product and make a secure way to get the product to the customer in timely manner, then people will prefer buying online instead of visiting the outlet physically. This also allows people to access it even in the oddest hour of the day. Convenience A fully functional website provides greater advantage for users where they can always tune in and look for what they need. Generally, users avoid going to stores physically if they have an option to get it online. So, if you are a smart businessman, you would prefer to have all the details of your products or your stores on the website only to earn business, which you otherwise might not. Global Marketing With an online website, you can link up to social forums and market your product/service to a huge audience all around the globe. With this, you can regularly advertise and share your work on social forums to gain much higher footprints of targeted audience. Credible Source An online portal is the most trustworthy platform for any company/organization. Sometimes official websites can even function as their sole office. Consider a scenario, where it is not easy to get access to a company’s physical location. In such case, you can overcome this worry by focusing on their website. In short, by developing a website, you can promote your services by a few clicks and you can grab the attention of consumers from various parts of the world. The website of a company can prove remarkable to gain business not only in a shorter time but also with a much bigger audience. Python Frameworks Python is one of the most acceptable languages among web and application developers because of its strong emphasis on efficiency and readability. There are numerous outstanding Python web frameworks, each with their own specialities and features. Django Here, we will outline some necessary details and features of Django framework. Category − Django belongs to the full-stack Python framework. Release − Latest release – 2.1 version, commonly used release –

Discussion

Discuss Python Web Development Libraries ”; Previous Next Python provides multiple frameworks for the web development. This tutorial covers five most commonly used python libraries which are used for web development. All the mentioned libraries in this tutorial are the first choice in certain project-specific conditions/requirements. Also, while trying to select the libraries, the developers interest (based on their queries and community support) is considered. Print Page Previous Next Advertisements ”;

Python Frameworks

Python Frameworks ”; Previous Next Python is one of the most acceptable languages among web and application developers because of its strong emphasis on efficiency and readability. There are numerous outstanding Python web frameworks, each with their own specialities and features. Django Here, we will outline some necessary details and features of Django framework. Category − Django belongs to the full-stack Python framework. Release − Latest release – 2.1 version, commonly used release – 1.8, 1.6 version. About − Built by experienced developers, Django is a high level Python web framework which allows rapid, clean and pragmatic design development. Django handles much of the complexities of web development, so you can focus on writing your app without a need to reinvent the wheel. It’s free and open source. To map objects to database table, Django uses ORM and the same is used to transfer from one database to other. It works with mostly all important databases like Oracle, MySQL, PostgreSQL, SQLite, etc. There are numerous websites in the industry which uses Django as their primary framework for backend development. Features of Django Some of the exemplary features of this Python web framework are − URL routing Authentication Database schema migrations ORM (Object-relational mapper) Template engine The Official Website for Django framework is −https://www.djangoproject.com/ Flask Category − Flask belongs to Non Full-stack frameworks. Release − 1.0.2 released on 2018-05-02 About − It is classified as a micro-framework as we don’t require any particular libraries or tools. It has no form validation or database abstraction layer or any other components where pre-existing third party libraries provide common functions. However, flask support multiple extensions which extended the application features as if they were implemented in Flask itself. Extensions exist for object-relational mappers, form validation, upload handling, various open authentication technologies and several common frameworks related tools. Features of Flask Integrated support for unit testing Restful request dispatching Contains development server and debugger Uses Jinja2 templating Support for secure cookies Unicode-based 100% WSGI 1.0 compliant Extensive documentation Google App Engine compatibility Extensions available to enhance features desired Web2py Category − Web2py belongs to Full-stack framework family. Release − 2.17.1, released on 2018-08-06 About − Python 2.6, 2.7 to Python 3.x version. With no further dependencies, it’s a complete package in itself. Development, database administration, debugging, deployment, testing, and maintenance of applications all can be done through web interface, but generally not required. It is a scalable open source framework that comes with its own web-based IDE alongside a code editor, one-click deployment and debugger. Features of Web2py This framework comes with many developing tools and built-in features that eliminate the hassle of complexity to the developers. With no installation and configuration, it is easy to run. Supports almost all major operating system, like Windows, Unix/Linux, Mac, Google App Engine and almost all web hosting platform through Python 2.7/3.5/3.6/ version. Easy to communicate with MySQL, MSSQL, IBM DB2, Informix, Ingres, MongoDB, SQLite, PostgreSQL, Sybase, Oracle and Google App Engine. It prevents the most common types of vulnerabilities including Cross Site Scripting, Injection Flaws, and Malicious File Execution. Supports error tracking and internationalization. Multiple protocols readability. Employs successful software engineering practices that makes code easy to read and maintain. Ensure user-oriented advancements through backward compatibility. Pyramid Category − Pyramid is a non-Full Stack Frameworks Release − 1.9.2, released on 2018-04-23 About − Pyramid is a small, fast, down-to-earth Python web framework. It is developed as part of the Pylons Project. It is licensed under a BSD-like license. It makes real-world web application development and deployment more fun, more predictable and more productive. Features of Pyramid Python Pyramid is an open sourced framework with the following features − Simplicity − Anyone can start to work with it without any prior knowledge about it. Minimalism − Quite out of the box, Pyramid comes with only some important tools, which are needed for almost every web application, may it be security or serving static assets like JavaScript and CSS or attaching URLs to code. Documentation − Includes exclusive and up to date documentation. Speed − Very fast and accurate. Reliability − It is developed, keeping in mind that it is conservative and tested exhaustively. If not tested properly, it will be considered as broke. Openness − It’s sold with a permissive and open license. Dash Category − The Dash framework belongs to “other” Python web frameworks. Release − 0.24.1, core dash backend. About − Dash as an open source library for creating interactive web-based visualizations. The plotly team created Dash – an open source framework that leverages Flask, React.js and plotly.js to build custom data visualization apps. Key highlight of this library is that you can build highly interactive web application only through Python code. Data scientists love dash framework, specially all those who are less familiar with web development. With Dash, developers get access to all the configurable properties and underlying Flask instance. The applications developed using Dash framework can be deployed to servers and are eventually rendered in the web browser. Dash applications are inherently cross-platform (Linux/Win/Mac) and mobile friendly and the capabilities of applications can be extended by the rich set of Flask Plugins. Features of Dash Provides access to configurable properties and Flask instance Through Flash plugins, we can extend the capabilities of the Dash application Mobile-ready Print Page Previous Next Advertisements ”;

Useful Resources

Python Web Development Libraries – Resources ”; Previous Next The following resources contain additional information on Python Web Development Libraries. Please use them to get more in-depth knowledge on this. Useful Video Courses Python Flask and SQLAlchemy ORM 22 Lectures 1.5 hours Jack Chan More Detail Python and Elixir Programming Bundle Course 81 Lectures 9.5 hours Pranjal Srivastava More Detail TKinter Course – Build Python GUI Apps 49 Lectures 4 hours John Elder More Detail A Beginner”s Guide to Python and Data Science 81 Lectures 8.5 hours Datai Team Academy More Detail Deploy Face Recognition Project With Python, Django, And Machine Learning Best Seller 93 Lectures 6.5 hours Srikanth Guskra More Detail Professional Python Web Development with Flask 80 Lectures 12 hours Stone River ELearning More Detail Print Page Previous Next Advertisements ”;

Web2py Framework

Web2py Framework ”; Previous Next Web2py is an easy-to-use framework. With web2py, no installation and configuration is required as it is portable and can be run on a USD drive too. It is based on the MVC frameworks like many other python frameworks. Though most of them do not support older versions of Python, web2py still supports older versions: python 2.6 and 2.7. It also supports LDAP for authentication which is widely accepted these days. Web2py tries to lower the barrier of entry to web development by focusing on three main goals − Rapid development Ease of use Security Keeping in mind the user perspective, Web2py is built and constantly being optimized internally to make it a faster and leaner framework including support for backward compatibility. Installing and Configuring Web2py Framework Running a web2py is easy, you need to download the exe from the below link: http://www.web2py.com/init/default/download For windows, you can download the zip file, unzip it and run the exe file either directly or from the command line. You will be prompted with below screen asking for the admin password. You can choose an administrator password and start the server. You will see the following screen − Creating an app using Web2py Now we are ready to create a new app. Click on the admin tab located at the bottom. So after entering the admin password, we will get the below screen − Go to new simple application, enter some application name (like helloWeb2py) and click on create. This will display design interface page as given below − You can also go to your current live web,helloWeb2py, simply type http://127.0.0.1:8000/helloWeb2py on your local machine, you will get the below output − In the design page of helloWeb2py application, go to the controller and click on edit button next to default.py. If you change the return value of the index() function, the following output will be displayed − Save the changes, and now you can check the changes made in your helloWeb2py app. Just refresh the http://127.0.0.1:8000/helloWeb2py link and you will see the below output − Deploying the app on cloud platform Now if you want to deploy your app on cloud platform, come back to your home page and click on the site. You can choose any option for deployment. Here, we choose “pythonAnywhere”. Go to pythonAnywhere website and register yourself (if not already done). Click on “Add a new web app” and fill all the credentials (Choose web2py app). All done. Now go to https://username.pythonanywhere.com/welcome/default/index, click on admin tab (enter password). Next click on upload and install packed application. Fill the credentials as below and click install. Once everything is done, a pop-up message will appear as given below − Now to view your app, open the below link − https://username.pythonanywhere.com/welcome/default/index and you can see the following screen − Our first web2py application is successfully created and deployed. To summarize, Web2py is a free, fast, secure web development framework that is entirely written in python and encourages using python in every way possible (model, view, controller). It is a very good framework for small web applications or prototypes but fails to fulfil the enterprise class quality requirements. It is because, in an enterprise level application, the complexity of solving bugs will increase exponentially because of the lack of unit tests, good and accurate error reporting and scattered model. Print Page Previous Next Advertisements ”;

Choosing a Better Framework

Choosing a Better Framework ”; Previous Next The world of Python web frameworks provides lots of choices. Some of the prominent frameworks to consider are Django, Flask, Bottle, Diesel, Web2py, Pyramid, Falcon, Pecan, etc., that compete for the developer mindshare. Frameworks like Pyramid, Django, Web2py and Flask are ideal with their list of pros and cons; choosing just one for your project is a difficult choice to make. Dash is entirely designed for different set of needs. So, as a developer you want to cut the legions of options down to the one that will help you finish your project on time and with perfection. If we compare Flask, Pyramid and Django frameworks, Flask is a micro-framework primarily aimed at small applications with simpler requirements whereas Pyramid and Django are both aimed at larger applications. Pyramid is built with flexibility and freedom in mind, so the developer has right tools for the project. In case of pyramid, the developer is free to choose the database, URL structure, templating style and more. However, Django includes all the batteries a web application needs, so we just need to install Django and start working. Django comes with an ORM, whereas Pyramid and Flask leave it to the developer to choose how (or if) they want their data to be stored. Generally, the most common ORM for non-Django web applications is SQLAlchemy by far, however, other options can be DjangoDB, MongoDB, LevelDB and SQLite. Being a developer, if I have to choose between Django and Web2py for my project. I need to have some idea of both the frameworks’ benefits and limitations. So let us compare Django and Web2py − Django The community of Django is a big plus. This actually means to a developer is the wealth of resources will be greater. Specifically, this comes down to − Documentation Open source resources Third-party apps support Deployment support IRC channels with helpful developers Django has a very big community of development team and documentation. It is the right framework when we are dealing with writing a complex backend as it provides a lot of third party apps that lets you automate things like user’s logic (signup, authentication), asynchronous tasks, API creation, blogs, etc. Web2py Web2py is a good fit to fast development of simple web apps or http servers. Below are some of the benefits and limitations of web2py. Benefits of Web2py The following are some of the benefits of Web2py framework − Web2py is a potential framework when compared to Django and Flask in terms of speed and simplicity of the development. As Web2py uses python-based template language, this allows python developers to start writing code immediately after understanding the basics of writing template as views. Web2py can run python compiled code as an optimization to lower the running time and to allow you to distribute your code in a compiled fashion. Limitations of Web2py The following are some of the limitations of the framework: Web2py supports doctests, however it does not support unit testing. Now doctests are not the optimal choice because of their limited scope. There is no differentiation between production and development mode. In case an exception occurred, ticket is generated all the times and you will have to navigate to the ticket to check the error. This might be helpful in case of production server but will be difficult in development environment as developers really need to see the error instantly rather than checking the ticket number. Web2py has a good database abstraction layer (DAL) that allows you to abstract many types of database engines but it lacks powerful ORM. In case you are dealing with relatively large model, your code will get scattered by all nested definitions and attributes which makes things complicated. We cannot use standard python development tools without modifications as web2py has really poor IDE support. The Django and Web2py framework are full stack frameworks. This means they provide all the code needed − from form generators to templating layouts and forms validation, and leave you to write things according to your specific needs. However, with the non-stack frameworks like Flask and Pyramid, if you want to create a full-featured website, you will need to add a lot of code and extra bits yourself. This takes lot of skill and time. Dash Dash is entirely designed for specific task of building a reactive framework for dashboards. Dash by Plotly is a great way for the python developer to create interactive web apps without having to learn Javascript and front end web development. Dash is built on top of Flask, Plotly.js, React and React Js. There is no comparison between Dash and other frameworks (mentioned above) as they belong to different category of frameworks. Below are some of the reasons to prefer dash over other interactive dashboard frameworks (Jupiter Dashboards, matplotlib and other) − With just 50 lines of code, you can write a simple “hello world” Dash app, as Dash requires very little boilerplater. Entire Dash apps are written in python language, the most preferred language globally. In your own python code, you can bind dash interactive components like dropdown, text inputs, sliders, and graphs with reactive Dash “callbacks”. Complicated UIs in Dash apps can have multiple inputs, multiple outputs and inputs that depends on other inputs. Simultaneously, multiple users can work on Dash apps. For creating your own Dash components with React, dash uses React.js to render components and includes a plugin system. Developers or writers can write dash apps that respond to clicking, hovering or selecting points on the graph as Dash’s Graph components are interactive. Conclusion We can conclude that choosing the right framework out of many available python frameworks solely depends on the type of project, complexity, small or enterprise level project, kind of community support available or online resource available, scalability, security, etc. The above mentioned python frameworks are best in their class but have their own benefits and drawbacks (depending on the project requirement). So,

Pyramid Framework

Pyramid Framework ”; Previous Next Pyramid is a general, open source, web application development framework built in python. It allows python developer to create web applications with ease. Pyramid is backed by the enterprise knowledge Management System KARL (a George Soros project). Installing, starting up and configuring As described, “the start small, finish big, stay finished framework”, Pyramid is much like Flask which takes very little effort to install and run. In fact, you’ll recognize that some of the patterns are similar to Flask once you start building this application. Following are the steps to create pyramid framework environment − First, create a project directory. Here, we have created a directory named pyramidProject (you can choose any name you want). Next, create a virtual environment where you will install all the project specific dependencies. Here, we created a virtual environment folder named pyramidEnv where Pyramid is installed. Then, go to the directory, pyramidEnv and install the pyramid with pip install pyramid. Once everything is done as mentioned above, your directory structure will be as shown below − And the pyramid version installed in the system is given below − Core Concepts The Pyramid framework is based on below core concepts − Zope (extensibility, traversal, declarative security) − Pyramid is loosely based on Zope in terms of extensibility, the concept of traversal and the declarative security. Pylons (URL dispatch, non-opinionated view of persistence, templating, etc.) − Another area from where pyramid draws its concept is the pylons project. Pylons have that concept of routes, that calls the URL dispatch inside the pyramid framework and they also have the non-opinionated view of persistence layer or templating. Django (View, level of documentation) − Pyramid also gets hint from Django. The way we take our view, routed our URL and the level of documentation is very Django way. The following are the features of the Pyramid framework − It is the fastest known Python web framework. It supports small and large projects (why rewrite when you outgrow your small framework). It supports single file webapps like microframeworks. It has built-in sessions. It supports events similar to Plone/Zope. It provides Transaction Management (if already have noticed that we have used Zope before). Configuration Configuration is the settings that influence the operation of an application. There are two ways to configure a pyramid application: imperative configuration and declarative configuration. Pyramid configuration supports − Imperative configuration or even the overriding of the decorator-based configs Configuration conflict detection (including more local vs. less local determination) Configuration Extensibility (included from multiple apps) Flexible Authentication and Authorization Policies Programmatic Introspection of Configuration (view current state of routes to generate nav) URL generation In pyramid, we can generate URLs for routes, resources and static assets. It is easy and flexible to work with URL generation APIs. By generating URLs through pyramid’s various APIs, users can change the configuration arbitrarily without much worry of breaking a link with any of your web pages. So in short, URL in pyramid − supports URL generation to allow changes to app that won’t break links. generates URLs to static resources that live either inside or outside the application. supports Routes and Traversal. Views One of the primary jobs of pyramid is to find and invoke a view callable when a request reaches your application. View callables are bits of code which do something interesting in response to a request made in your application. When you map your views onto your URL dispatch or python code, there can be any kind of call. Views can be a function declaration or an instance, it can be used as a view in the pyramid. Some important points about Views are given below − Views are generated from any callable. Renderer based views can simply return dictionaries (not required to return a webby style object). Support multiple views per route (GET vs. POST vs. HTTP Header check, etc.). View response adapters (when you want to specify how view returns values should be handled vs. response objects). Extensibility Pyramid is designed with extensibility in mind. So if a pyramid developer is keeping in mind certain constraints while building an application, a third party should be able to change the application’s behaviour without needing to modify its source code. The behaviour of a pyramid application that obeys certain constraints can be overridden or extended without any modification. It is designed for flexible deployments to multiple environments (No Singletons). Pyramid has “Tweens” middleware support (WSGI middle ware, but runs in the context of Pyramid itself). Running a Hello, Pyramid Program The simplest program we can think after installing pyramid framework to check if everything is working fine, is to run a simple “Hello, World” or “Hello, Pyramid” program. Below is my pyramid “Hello, Pyramid” program on 8000 port number − Above simple example is easy to run. Save this as app.py (In this, we have given the name pyramid_helloW.py). Running the simplest program: − Next, open http://localhost:8000/ in a browser, and you will see the Hello, Pyramid! Message as follows − The following is the explanation for above code − Line no. 1-3 At the head of the file, we have import statements. The first line imports make_server function, which can create a simple web server when it is passed to an application. The second and third line import the configuration and Response function from pyramid. These functions are used to configure details and set parameters for the application and respond to requests, respectively. Line no. 5-6 Now we have a function definition called hello_world. Implement view code that generates the response. A function that fulfils the requirement of a view is responsible for rendering the text that will be passed back to the requesting entity. In the above case, the function, when called, uses the Response function we imported earlier. This passes back a value that should be given to the client. Line no. 8 if __name__ == ‘__main__’: Python is saying, “Start here when running from

Django Framework

Django Framework ”; Previous Next In this chapter, we will discuss about Django Framework in detail. Django is an MVT web framework that is used to build web applications. The huge Django web-framework comes with so many “batteries included” that developers often get amazed as to how everything manages to work together. The principle behind adding so many batteries is to have common web functionalities in the framework itself instead of adding latter as a separate library. One of the main reasons behind the popularity of Django framework is the huge Django community. The community is so huge that a separate website was devoted to it where developers from all corners developed third-party packages including authentication, authorization, full-fledged Django powered CMS systems, e-commerce add-ons and so on. There is a high probability that what you are trying to develop is already developed by somebody and you just need to pull that into your project. Why should you use Django? Django is designed in such a way that encourages developers to develop websites fast, clean and with practical design. Django’s practical approach to getting things done is where it stands out from the crowd. If you’re planning to build a highly customizable app, such as social media website, Django is one of the best frameworks to consider. Django strength lies in its interaction between users or its ability to share different types of media. One of the great advantage of django is its ability to utilize large community-based support which gives you highly customizable third-party ready to use plugins in your applications. Below are the top ten reasons to choose Django for web development − Python Python is arguably one of the easiest programming languages to learn because of its simple language constructs, flow structure and easy syntax. It is versatile and runs websites, desktop applications and mobile applications embedded in many devices and is used in other applications as a popular scripting language. Batteries Included Django comes with common libraries which are essential to build common functionalities like URL routing, authentication, an object-relational mapper (ORM), a templating system and db-schema migrations. Built-in admin Django has an in-built administration interface which lets you handle your models, user/ group permissions and to manage users. With model interface in place, there is no need for a separate database administration program for all but advanced database functions. Doesn’t get in your way Creating a Django application adds no boilerplate and no unnecessary functions. There’s no mandatory imports, third-party libraries and no XML configuration files. Scalable Django is based on MVC design pattern. It means that all the entities like db (database), back-end and front-end code are individual entity. Django allows us to separate code from the static media including pictures, files, CSS and JavaScript that make up your site. Django supports a full list of third-party libraries for web servers, caching, performance management, clustering and balancing. One of the advantages Django provides is the support for major email and messaging applications and services like ReST and OAuth. Battle tested Django was first open-sourced in 2005. After 12 years of growth, Django now not only runs news publishing websites but also runs all or part of major global enterprise like Pinterest, Instagram, Disqus, Bitbucket, EventBrite and Zapier. This makes it a robust and reliable web framework to work with. Huge package support Because of its large community support and huge developers network, there is a high possibility that whatever you intend to do might have been done before. Large international community of developers contribute to the community by releasing their projects as open-source packages. One such repository of these projects is Django Package site. Currently, Django packages list over 3400 plus reusable Django apps, sites and tools to use in our Django projects. Actively developed One of the biggest risks associated with open source project is its sustainability. We cannot be sure if it lasts long. There is no such risk with Django as it is 12 years old. Its consistent releases, newer/better versions and active community is growing every-day with a large core team of voluntary contributors who maintains and improve the code base every-day. Stable releases Open-source software projects like Django are, in many cases, actively developed and more secure than competing proprietary software as many developers are developing and testing it every day. However, the drawback of an open-source software project is the absence of a stable codebase to commercially viable development. In Django, we have Long Term Support (LTS) versions of the software and a defined release process as shown in the below image − First Class Documentation From the very first release, Django developers made sure that there must be proper comprehensive documents available and the tutorials are easily understand. Who’s Using Django? Because of the Django’s unique strength, there are multiple popular websites which are built with Python on top of the Django framework. Below are some of the major sites which are fully or partially built based on Django. Disqus It is one of the most preferred blog comment-hosting sites globally. It is easy to integrate with most popular CMS (content management systems) like WordPress and many others through Disqus. Handling a user-base of over 50 million, Django is able to satisfy the site owners to reach out to their communities. The Onion The Onion website which provide an online venue for their satirical newspaper, Django provides the framework for it. Bitbucket Bitbucket is like GitHub, a version control repository hosting service. The only difference between Bitbucket and GitHub is that Bitbucket hosts mercurial repositories whereas GitHub hosts git repositories. As millions of users are associated with Bitbucket, and all the services which bitbucket provides (like create a repo, push your code, add collaborators, commits, pull request, etc.) has to be stable. Django is responsible for running the bitbucket site. Instagram Instagram is a social networking app built especially for those who love to share photos and videos to all their friends. Currently there

Introduction

Python Web Development Libraries – Introduction ”; Previous Next Whenever a user opens any web browser like Google Chrome or Mozilla and search for ‘Web development’, thousands of results appear in no time. What makes this possible? Web development! It broadly refers to the work associated with building, creating and maintaining websites for hosting via intranet or internet. The work associated in website design contain multiple areas: web programming, database management, web design, web publishing, etc. Web development includes all the codes that influence a website to run. We can separate the whole process of web development into two categories − Front-end Back-end Though frontend and backend web development are certainly distinct from each other, they are also like two sides of the same coin. A complete website relies on each side communicating and operating effectively with the other as a single unit. Both front-end and back-end are equally important in web development. The front-end or client-side of an application is the code responsible for everything the user directly experiences on screen from text colors to buttons, images and navigation menus. Some of the common skills and tools which are used by front-end developers are listed below − HTML/CSS/JavaScript CSS preprocessors Frameworks Libraries Git and Github Generally, the back-end/server-side of an application is responsible for managing information within the database and serving that information to the front-end. The back-end of a website consists of a server, application, and database. In general, it involves everything that happens before hitting your browser. The tools required in back-end web development are − Programming language − Ruby, PHP, Python, etc. Database − MySQL, PostgreSQL, MongoDB, Oracle, etc. Why Web Development? In today’s world, there are multiple choices to promote your business or skills and share your ideas. Some of them are promotion through websites, native applications in marketplaces, etc. The trend of creating new website as a tool of business development is rapidly gaining momentum around the world. But, some of us may be unaware of the importance a website holds in the growth of a business. Currently there are numerous start-ups struggling to establish their presence in the open market. However, it is also true that most of them fail to gain as much targeted audience as they want. One primary reason which is bringing them down is that they underestimate the potential of a full feature developed website to earn business for them. Website development for business or any other purpose can prove quite fruitful. Let us look at some of the important reasons why website development is important for business growth − Reaching out to your audiences Online websites can reach to broadest audience and are not restricted to a platform that constrain native applications. The viewers or customers can have easy access i.e. from a desktop/laptop to a mobile device, as websites have the capability to display the content through web browser. In comparison to native application, web browsing is much simpler because it does not require users to access the app store on their devices or download their app (which may include one or more processes in accessing to your contents). Distribution of your data is much more flexible and agile with web-based application than native ones as there are no stringent app store requirements and content restrictions to follow. Another tool which is very helpful for web development is the power of utilizing SEO techniques to target your audiences. 24/7 Accessible Instead of establishing a physical outlet for the company, if the business owner develops a website as an online forum or similar, there will be good chance of gaining larger audience online to link up. This is because, most of the people are wired up with the Internet all day. Generally, people prefer to go for the smartest way to check online first and then take a decision. So if the business owner fills all the basic details of the product and make a secure way to get the product to the customer in timely manner, then people will prefer buying online instead of visiting the outlet physically. This also allows people to access it even in the oddest hour of the day. Convenience A fully functional website provides greater advantage for users where they can always tune in and look for what they need. Generally, users avoid going to stores physically if they have an option to get it online. So, if you are a smart businessman, you would prefer to have all the details of your products or your stores on the website only to earn business, which you otherwise might not. Global Marketing With an online website, you can link up to social forums and market your product/service to a huge audience all around the globe. With this, you can regularly advertise and share your work on social forums to gain much higher footprints of targeted audience. Credible Source An online portal is the most trustworthy platform for any company/organization. Sometimes official websites can even function as their sole office. Consider a scenario, where it is not easy to get access to a company’s physical location. In such case, you can overcome this worry by focusing on their website. In short, by developing a website, you can promote your services by a few clicks and you can grab the attention of consumers from various parts of the world. The website of a company can prove remarkable to gain business not only in a shorter time but also with a much bigger audience. Print Page Previous Next Advertisements ”;