Grape release of Pynq is out there!!!
Grape release of Pynq is out! You can grab it in the usual places (Installing Pynq)
.
I’ll go over all the details of this new release, but first I’d like to introduce the HOTTEST feature of this new release: DOCUMENTATION!
Pynq now has comprehensive (as much as I can think of anyway) documentation of all it’s features at this url: http://wiki.github.com/heynemann/pynq
This is really cool for people starting with Pynq.
Now let’s talk code!
Introduction
For those of you that are not familiar with Pynq yet I seriously advise you to check the wiki, but I’ll try to explain in as few words as possible.
Pynq is a Python implementation of Microsoft’s Linq (Language Integrated Query). We want it to be more than just a mere implementation of Linq for Collections in Python. We are going for a full featured expression-tree parser and provider infrastructure implementation. As such Pynq now features only the Collection Provider, but in release Mango (0.5.0) we’ll be doing a Twitter Provider as a means to demonstrate how to create a provider (I’ll blog about it later when we do it).
Querying
Since Pynq parses all your commands to expression trees it gives a LOT of freedom to the given Provider to do whatever it wants with it. This is where the real power behind Linq lies. You can’t forget, of course, the nice syntax it adds to your code. Where once you read:
http://gist.github.com/112032
Or something like that, now you'll read:
http://gist.github.com/112035
As you can see this is a much clearer code. The code gets a lot clearer once you start adding more to the query, like getting only a couple fields for instance:
http://gist.github.com/112040
The code is still clear, even though we have increased the complexity of our query A LOT!
New Release Features
This new release allows users to retrieve expressions as columns, instead of only being able to select columns. Here’s an example:
http://gist.github.com/112042
This makes it really easy to retrieve calculated columns on the fly, which can make the code a lot clearer (instead of looping through the collection to retrieve it).
To retrieve the calculated columns you use “dynamic_” and the index of the column in the select() method, like dynamic_4. This is not as cool as having an “as label” way of defining the name of the attribute. We might work it differently in the future. Suggestions are VERY WELCOME!
Another cool feature is sorting with expressions. Let’s say you did retrieve salary + bonus and now you want to order by greatest salary + bonus to lowest salary + bonus:
http://gist.github.com/112043
Even though the syntax is a little weird (the negative sign), think of it this way: order_by *ALWAYS* does ascendant order. By placing a negative sign before the order by expression you want, you are negating the order, thus inverting it. The parenthesis are REALLY important, because otherwise you would be doing negative salary + bonus ascending. Do not forget the parenthesis if what you want is a descending order.
Where to get it
You can get Pynq from:
- PyPI page at http://pypi.python.org/pypi/Pynq/
- Github Downloads at http://github.com/heynemann/pynq/downloads
- Through a debian repository. For more info on this check the installing page at http://wiki.github.com/heynemann/pynq/installing
Conclusion
Pynq is evolving pretty fast and we’ll keep adding more features in the upcoming releases.
Stay tuned and CONTRIBUTE!!!
Cheers!
Ps: sorry for the links to gists, but I couldn't make the god damn 'embed' feature of github to work with my blog!