pyQuery: Same API, but with a snake.

Written by on December 8th, 2008 in Uncategorized.

jQuery came first, but then we have seen others such as pQuery.

Now we have pyQuery which brings the same great taste API to Python. The author Olivier Lauzanne explains:

yquery allows you to make jquery queries on xml documents. The API is as much as possible the similar to jquery. pyquery uses lxml for fast xml and html manipulation.

This is not (or at least not yet) a library to produce or interact with javascript code. I just liked the jquery API and I missed it in python so I told myself “Hey let’s make jquery in python”. This is the result.

It can be used for many purposes, one idea that I might try in the future is to use it for templating with pure http templates that you modify using pyquery.

You can use the PyQuery class to load an xml document from a string, a lxml document, from a file or from an url:

PYTHON:

  1.  
  2. >>> from pyquery import PyQuery
  3. >>> from lxml import etree
  4. >>> d = PyQuery(“<html></html>”)
  5. >>> d = PyQuery(etree.fromstring(“<html></html>”))
  6. >>> d = PyQuery(url=‘http://google.com/’)
  7. >>> d = PyQuery(filename=path_to_html_file)
  8.  

We also saw new posts on pyjamas, the JS emitter (a la GWT for Java) that we covered awhile back.

Add to that the fantastic week that the pythonistas have had as they laud over us with Python 3000 having a final release (which will kick in updates to libraries that are needed to make this backwards not so compatible upgrade viable). It gives a kick in the backside to Perl, Ruby, Java, and even us JS folk :)

Source: Ajaxian » Front Page
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/478423618/pyquery

Comments are closed.



Site Navigation