shabda
Comments
Reactions

Django Request Response processing

By : Shabda Raaj

Have you wondered the steps a users request goes through before being responded to by Django? The answer lies in reading django.core.handlers.base and django.core.handlers.wsgi. Here is a diagram explaining what happens. (Click to enlarge.)

The steps are. (With Apache/Mod_wsgi, similar steps for other setup.)

  1. User's request comes to Apache etc.
  2. Apache sends request to django.core.handlers.wsgi via mod_wsgi.
  3. A list of request and response middleware callables is created.
  4. Request middleware is applied. If it sends a response, it is returned to the user.
  5. urlresolvers.resolve finds the view funcion to ...

more info..
Topics : django tips
lakshman
Comments
Reactions

Better Python package management using source and version control systems

By : lakshman

Thanks to awesome django community, there is plenty of open source django code around.

These packages get updated quite often and if you use it often like we do, you'd have possibly realized the need to manage these packages better.

Thankfully, all python ever needs is the source, and all you need to do is to place the source in the python path.

Most projects use Distributed Version Control Systems like Mercurial and Git, and they come locally with the entire history of the source which provides a lot of control to use any version of the code. For ...

more info..
shabda
Comments
Reactions

Understanding decorators

By : Shabda Raaj

If you used Django for any length of time, you would have come across the login_required decorator. You write @login_required before a view, and it magically becomes accessible only to authenticated users.

Decorators were introduced in python 2.4. PEP 318 is the PEP describing it. At the simplest decorators are nothing but callables returning other callables, and the decorator syntax @decorator is nothing but foo = bar(foo), where both bar and foo are callables.

Let us see some decorators in action.

In [1]: def good_function():
   ...:     print 'I am a good function'
   ...:     
   ...:

In [2]: def decorator(orig_func):
   ...:     def bad_func():
   ...:         print ...

more info..
Topics : python tips
shabda
Comments
Reactions

Generating pseudo random text with Markov chains using Python

By : Shabda Raaj

First the definition from Wolfram

A Markov chain is collection of random variables {X_t} (where the index t runs through 0, 1, ...) having the property that, given the present, the future is conditionally independent of the past.

Wikipedia is a little clearer

...Markov chain is a stochastic process with markov property ... [Which means] state changes are probabilistic, and future state depend on current state only.

Markov chains have various uses, but now let's see how it can be used to generate gibberish, which might look legit.

The algorithm is,

  1. Have a text which will serve as the corpus from ...

more info..
Topics : seo algorithms

Yahoo BOSS python api

By : lakshman

Yahoo has a search api with generous limits, BOSS. There are a few python apis around it. But we wanted a lighter api, and one which has the same interface as out Bing Python api. So here is the updated bingapi.(Now with bossapi.py as well). Or svn it from here


Usage

Usage is mostly compatible with bingapi

In [2]: from bingapi import bossapi

In [3]: api = bossapi.Boss('<appid>')

In [4]: api.do_web_search('Uswaretech')
Out[4]: ....

In [5]: api.do_news_search('salsa')
Out[5]: ...

In [6]: api.do_siteexplorer_search('http://uswaretech.com')
Out[6]: .....

more info..
Topics : API search yahoo
lakshman
Comments
Reactions

Python Wrapper on Bing API

By : lakshman

The newly launched search engine Bing has a simple restful API. We have created a thin Python wrapper over this API, which allows to query the Bing servers in a very pythonic way.

Installing this is as easy as easy_install bingapi.

[Or get it here or here ]

Using

from bingapi import bingapi
bing = bingapi.Bing(<appid>)
bing.do_web_search('Usware Technologies')

The README from the project is posted below, which provides more details on using this.

bingapi.py is a very thin python wrapper over the Bing API. Bing provides a very simple Restful interface to their search engine and provides ...

more info..
© Agiliq, 2009-2012