<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andrea Grandi &#187; Python</title>
	<atom:link href="http://www.andreagrandi.it/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andreagrandi.it</link>
	<description>Pensieri, progetti e qualche informazione su di me</description>
	<lastBuildDate>Fri, 03 Feb 2012 20:03:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Backing up all your Flickr photos using Linux</title>
		<link>http://www.andreagrandi.it/2012/01/05/backing-up-all-your-flickr-photos-using-linux/</link>
		<comments>http://www.andreagrandi.it/2012/01/05/backing-up-all-your-flickr-photos-using-linux/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 10:31:07 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ubuntu (EN)]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=599</guid>
		<description><![CDATA[I've been a Flickr pro user for 4 years, but the pro account costs 24,95$/year and I was looking for something cheaper. Anyway I was thinking that after all, even if I don't renew my account, I can always access to all my pictures.... wrong! If you don't renew your pro Flickr account you can [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2012%2F01%2F05%2Fbacking-up-all-your-flickr-photos-using-linux%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2012%2F01%2F05%2Fbacking-up-all-your-flickr-photos-using-linux%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I've been a Flickr pro user for 4 years, but the pro account costs <strong>24,95$/year</strong> and I was looking for something cheaper. Anyway I was thinking that after all, even if I don't renew my account, I can always access to all my pictures.... wrong! <strong>If you don't renew your pro Flickr account you can only access to the low resolution version of your own pictures.</strong> That's not acceptable for me, so I decided to download all my pictures and upload them somewhere else. Here comes the second disappointment: <strong>there is no automatic way to download all your pictures</strong>.</p>
<p>I simply had no time to write an application by myself, so I started searching on Google to see if there was something available to do this simple task. At the beginning I only found abandoned tools (closed source, the API was expired ecc...), paid tools, Windows only tools ecc... but finally I found this post <a href="http://hivelogic.com/articles/backing-up-flickr/">http://hivelogic.com/articles/backing-up-flickr/</a></p>
<p>There is a Python script that automatically downloads all your Flickr pictures getting the highest resolution available, you can download the script from here <a href="https://github.com/dan/hivelogic-flickrtouchr">https://github.com/dan/hivelogic-flickrtouchr</a></p>
<p>The usage is very simple</p>
<pre class="brush: plain; title: ; notranslate">
mkdir FlickrBackupFolder
python flickrtouchr.py FlickrBackupFolder
</pre>
<p>A browser's window will be opened and you'll be prompted for authorization. After that, all you pictures will be downloaded.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2012/01/05/backing-up-all-your-flickr-photos-using-linux/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Twitter client for Maemo in Qt + Python: call for developers and UI designers</title>
		<link>http://www.andreagrandi.it/2010/02/22/twitter-client-for-maemo-in-qt-python-call-for-developers-and-ui-designers/</link>
		<comments>http://www.andreagrandi.it/2010/02/22/twitter-client-for-maemo-in-qt-python-call-for-developers-and-ui-designers/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 16:16:07 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[MeeGo]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[N900]]></category>
		<category><![CDATA[nokia]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=369</guid>
		<description><![CDATA[Introduction My name's Andrea Grandi, I'm italian and I'm a Maemo user/lover/contributor since the Nokia 770. I love Python as development language and few months ago I also gave some contributions to the PyMaemo project. In these days I had the idea to start writing a Twitter client for Maemo with a precise direction in [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2010%2F02%2F22%2Ftwitter-client-for-maemo-in-qt-python-call-for-developers-and-ui-designers%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2010%2F02%2F22%2Ftwitter-client-for-maemo-in-qt-python-call-for-developers-and-ui-designers%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h2>Introduction</h2>
<p>My name's <strong>Andrea Grandi</strong>, I'm italian and I'm a Maemo user/lover/contributor since the <strong>Nokia 770</strong>. I love <strong>Python</strong> as development language and few months ago I also gave some contributions to the <a href="http://pymaemo.garage.maemo.org/"><strong>PyMaemo</strong></a> project.</p>
<p>In these days I had the idea to start writing a <strong>Twitter</strong> client for <strong>Maemo</strong> with a precise direction in my mind. I'll try to explain all my reasons here. First of all I've to thank the author of <a href="http://mauku.henrikhedberg.com/"><strong>Mauku</strong></a> client. I use it since its first version and I'm quite happy with it. Then, why do I want to write another one?</p>
<ol>
<li><strong>Maemo</strong> (MeeGo) is moving to <strong>Qt</strong> and for this reason I'm going to use Qt, while Mauku uses Gtk.</li>
<li> I'm learning Qt and what is better than writing a complete (but not too complex) application to learn better?</li>
<li>Mauku is not free as lot of people could think. Reading the source codeyou find this "You are NOT allowed to modify or redistribute the source code.", while I want to write a client and release it under <strong>GPL2</strong> or <strong>GPL3</strong> license.</li>
<li>Mauku is not updated since some months and we have no news about it.</li>
<li> I love Python and I like to write free software in this language.</li>
<li>I want to give to Maemo a stronger contribute.</li>
</ol>
<h2>My request for help</h2>
<p>Before lot of people start writing their own client resulting in 4-5 twitter clients for Maemo, why don't we join our strength and work to a common project? I'm not a Python expert nor a Qt one, but I've some experience as project/team leader and since this is not a complex project, I would be glad to lead it. So, I'm looking for Python developers, Qt developers, UI designers and whoever want to contribute to this project. I still have to find a good name and logo for this application.</p>
<p>Who want to help me?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2010/02/22/twitter-client-for-maemo-in-qt-python-call-for-developers-and-ui-designers/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Writing Python bindings of existing C libraries – (3) – Building and Installing with distutils</title>
		<link>http://www.andreagrandi.it/2009/08/13/writing-python-bindings-of-existing-c-libraries-%e2%80%93-3-%e2%80%93-building-and-installing-with-distutils/</link>
		<comments>http://www.andreagrandi.it/2009/08/13/writing-python-bindings-of-existing-c-libraries-%e2%80%93-3-%e2%80%93-building-and-installing-with-distutils/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 09:39:50 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[distutils]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[setup]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=315</guid>
		<description><![CDATA[In the last post of this series, we saw how to write a simple binding and we finished to build and install it manually. This is of course not a good way to manage the building/installation procedure. In Python we can use a library called distutils that let us to automatize the building and installing [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F13%2Fwriting-python-bindings-of-existing-c-libraries-%25e2%2580%2593-3-%25e2%2580%2593-building-and-installing-with-distutils%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F13%2Fwriting-python-bindings-of-existing-c-libraries-%25e2%2580%2593-3-%25e2%2580%2593-building-and-installing-with-distutils%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In the last post of this series, we saw how to write a simple binding and we finished to build and install it manually. This is of course not a good way to manage the building/installation procedure.</p>
<p>In Python we can use a library called <strong>distutils</strong> that let us to automatize the building and installing process. I'll use the <strong>foo</strong> source code to create the package, so it will be easier to understand.</p>
<h2>Using distutils</h2>
<p>All we have to do is to write a <strong>setup.py</strong> file similar to this one:</p>
<pre class="brush: python; title: ; notranslate">
from distutils.core import setup, Extension

foomodule = Extension('foo', sources = ['foo.c'])

setup (name = 'Foo',
       version = '1.0',
       description = 'This is a package for Foo',
       ext_modules = [foomodule])
</pre>
<p>As you can see, we have to first import needed modules with: <strong>from distutils.core import setup, Extension</strong><br />
then we create an entry for each module we have (in this case just one, "foomodule"). We then call the <strong>setup()</strong> method passing it all the parameters and our <strong>setup.py</strong> is complete.</p>
<h2>Building and installing</h2>
<p>To test it we can try to build the package in this way:</p>
<p><code>python2.5 setup.py build</code></p>
<p>if we want to install the module in our system:</p>
<p><code>python2.5 setup.py install</code></p>
<h2>References</h2>
<ul>
<li>Official Python documentation: <a href="http://docs.python.org/extending/building.html">http://docs.python.org/extending/building.html</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/08/13/writing-python-bindings-of-existing-c-libraries-%e2%80%93-3-%e2%80%93-building-and-installing-with-distutils/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PyMaemo (Python for Maemo) second beta release for Fremantle</title>
		<link>http://www.andreagrandi.it/2009/08/10/pymaemo-python-for-maemo-second-beta-release-for-fremantle/</link>
		<comments>http://www.andreagrandi.it/2009/08/10/pymaemo-python-for-maemo-second-beta-release-for-fremantle/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 08:20:09 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[fremantle]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[nokia]]></category>
		<category><![CDATA[pymaemo]]></category>
		<category><![CDATA[tablet]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=312</guid>
		<description><![CDATA[The PyMaemo team is pleased to announce the second beta release of PyMaemo for Fremantle! This new release is available through the extras-devel repository, see installation instructions in http://pymaemo.garage.maemo.org/sdk_installation.html#fremantle What is it? Python for Maemo (PyMaemo for short) main objective is to make possible to use Python programming language as the scripting and development language [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F10%2Fpymaemo-python-for-maemo-second-beta-release-for-fremantle%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F10%2Fpymaemo-python-for-maemo-second-beta-release-for-fremantle%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>The <strong>PyMaemo</strong> team is pleased to announce the second beta release of  PyMaemo for <strong>Fremantle</strong>!</p>
<p>This new release is available through the <strong>extras-devel</strong> repository, see  installation instructions in<br />
<a href="http://pymaemo.garage.maemo.org/sdk_installation.html#fremantle" target="_blank">http://pymaemo.garage.maemo.org/sdk_installation.html#fremantle</a></p>
<h2>What is it?</h2>
<p>Python for Maemo (PyMaemo for short) main objective is to make  possible to use <strong>Python</strong> programming language as the scripting and  development language for Maemo Platform, providing a better  alternative for fast prototyping and programming in Maemo environment  besides the C programming language.</p>
<p>Python is for serious programming and to have fun. Python has a nice  syntax, it is easy to learn and powerful enough for a vast range of  applications, this is why we choose Python for Maemo.</p>
<h2>What has changed?</h2>
<p><strong>New packages:</strong></p>
<ul>
<li> <strong>python-mafw</strong> (0.1-1maemo1)
<ul>
<li>Python bindings for the Media Application Framework [1]</li>
<li>Supported API is very basic at the moment, and there are some bugs. Feedback is welcome!</li>
</ul>
</li>
<li><strong>python-hildondesktop</strong> (0.0.3-1maemo1)
<ul>
<li>Python bindings for the home/status widgets API</li>
</ul>
</li>
<li><strong>python-notify</strong> (0.1.1-2maemo1)
<ul>
<li>Python bindings for libnotify</li>
</ul>
</li>
<li><strong>pyclutter</strong> (0.8.0-1maemo2)
<ul>
<li>Python bindings for the Clutter API [2]</li>
<li>Experimental package, waiting for developer feedback</li>
</ul>
</li>
</ul>
<p><strong> Updated packages:</strong></p>
<ul>
<li> <strong>gnome-python</strong> (2.26.1-1maemo1)
<ul>
<li>major upgrade, matching current Debian testing release;</li>
<li>feedback on this is welcome, as it replaces a fairly old version (2.18).</li>
</ul>
</li>
<li><strong>pygtk</strong> (2.12.1-6maemo7)
<ul>
<li>Enable glade support.</li>
</ul>
</li>
<li><strong>python2.5</strong> (2.5.4-1maemo1)
<ul>
<li>Updated to latest upstream 2.5.x release.</li>
<li>add support to --install-layout=deb flag.</li>
</ul>
</li>
<li><strong>python-central</strong> (0.6.11.1maemo1)
<ul>
<li>dependency needed by the new python-setuptools version.</li>
</ul>
</li>
<li><strong>python-defaults</strong> (2.5.2-3maemo3)
<ul>
<li>Change PREVVER in debian/rules, avoiding old python2.5-minimal versions that had "/usr/bin/python" and thus conflicts with python-minimal.</li>
</ul>
</li>
<li><strong>python-hildo</strong>n (0.9.0-1maemo10)
<ul>
<li>lots of bug fixes</li>
</ul>
</li>
<li><strong>python-setuptools</strong> (0.6c9-1maemo1)
<ul>
<li>add support to --install-layout=deb flag.</li>
</ul>
</li>
</ul>
<p><strong> Bugs fixed:</strong> MB#4530 [3], MB#4450 [4], MB#4629 [5], MB#4628 [6],<br />
MB#4647 [7], MB#4632 [8],  MB#4646 [9],  MB#4750 [10],  MB#4749 [11],<br />
MB#4791 [12]</p>
<h2>Known issues</h2>
<p>MB#4782 [13]: osso.Context causes segmentation fault<br />
MB#4821 [14]: Cannot create HildonTouchSelector with single text column<br />
MB#4824 [15]: python-mafw: source_browsing.py example does not work<br />
MB#4839 [16]: python-mafw: mafw.Registry lacks list_plugins() method<br />
MB#4849 [17]: python-mafw: MafwPluginDescriptorPublic structure is missing</p>
<p>We will not migrate to python2.6 in fremantle due to a (unresolved)  bug (MB#4734 [18]), where a core SDK package explicitly conflicts with  python &gt;= 2.6, preventing any further upgrades from the 2.5.x series.</p>
<p>This release is supposed to be compatible with previous releases. If  you have any issues regarding building your Python application on  Fremantle, feel free to report it on the pymaemo-developers mailing list [19].</p>
<h2>Acknowledgments</h2>
<p>Thanks to everybody who helped making this release possible.</p>
<p>Bug reports, as always, should go to our Bugzilla [20]. Use the  <strong>pymaemo-developers</strong> mailing list for help, feedback or suggestions.</p>
<h2>References</h2>
<p>[1] <a href="https://garage.maemo.org/projects/mafw/" target="_blank">https://garage.maemo.org/projects/mafw/</a><br />
[2] <a href="http://www.clutter-project.org/" target="_blank">http://www.clutter-project.org/</a><br />
[3] <a href="https://bugs.maemo.org/show_bug.cgi?id=4530" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4530</a><br />
[4] <a href="https://bugs.maemo.org/show_bug.cgi?id=4450" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4450</a><br />
[5] <a href="https://bugs.maemo.org/show_bug.cgi?id=4629" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4629</a><br />
[6] <a href="https://bugs.maemo.org/show_bug.cgi?id=4628" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4628</a><br />
[7] <a href="https://bugs.maemo.org/show_bug.cgi?id=4647" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4647</a><br />
[8] <a href="https://bugs.maemo.org/show_bug.cgi?id=4632" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4632</a><br />
[9] <a href="https://bugs.maemo.org/show_bug.cgi?id=4646" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4646</a><br />
[10] <a href="https://bugs.maemo.org/show_bug.cgi?id=4750" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4750</a><br />
[11] <a href="https://bugs.maemo.org/show_bug.cgi?id=4749" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4749</a><br />
[12] <a href="https://bugs.maemo.org/show_bug.cgi?id=4791" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4791</a><br />
[13] <a href="https://bugs.maemo.org/show_bug.cgi?id=4782" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4782</a><br />
[14] <a href="https://bugs.maemo.org/show_bug.cgi?id=4821" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4821</a><br />
[15] <a href="https://bugs.maemo.org/show_bug.cgi?id=4824" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4824</a><br />
[16] <a href="https://bugs.maemo.org/show_bug.cgi?id=4839" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4839</a><br />
[17] <a href="https://bugs.maemo.org/show_bug.cgi?id=4849" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4849</a><br />
[18] <a href="https://bugs.maemo.org/show_bug.cgi?id=4734" target="_blank">https://bugs.maemo.org/show_bug.cgi?id=4734</a><br />
[19] <a href="https://garage.maemo.org/mailman/listinfo/pymaemo-developers" target="_blank">https://garage.maemo.org/mailman/listinfo/pymaemo-developers</a><br />
[20] <a href="https://bugs.maemo.org/enter_bug.cgi?product=PyMaemo" target="_blank">https://bugs.maemo.org/enter_bug.cgi?product=PyMaemo</a></p>
<h2>Credits</h2>
<p>This post was possible thanks to <strong>Anderson Lizardo</strong>, from PyMaemo team, who posted these informations on pymaemo-developers mailing list.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/08/10/pymaemo-python-for-maemo-second-beta-release-for-fremantle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Writing Python bindings of existing C libraries – (2) – A simple example of binding</title>
		<link>http://www.andreagrandi.it/2009/08/06/writing-python-bindings-of-existing-c-libraries-%e2%80%93-2-%e2%80%93-a-simple-example-of-binding/</link>
		<comments>http://www.andreagrandi.it/2009/08/06/writing-python-bindings-of-existing-c-libraries-%e2%80%93-2-%e2%80%93-a-simple-example-of-binding/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 14:44:21 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[maemo]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=301</guid>
		<description><![CDATA[Introduction As I promised in the preceding post, I'll provide a very easy example of a python binding. Let's suppose we don't want to use the methods included in Python to sum two integer values and we want to do it in C and then call the add method from a python script. I'll write [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F06%2Fwriting-python-bindings-of-existing-c-libraries-%25e2%2580%2593-2-%25e2%2580%2593-a-simple-example-of-binding%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F06%2Fwriting-python-bindings-of-existing-c-libraries-%25e2%2580%2593-2-%25e2%2580%2593-a-simple-example-of-binding%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h2>Introduction</h2>
<p>As I promised in the preceding post, I'll provide a very easy example of a python binding. Let's suppose we don't want to use the methods included in Python to sum two integer values and we want to do it in C and then call the add method from a python script. I'll write the complete source code first and then I'll explain all the parts of it.</p>
<h2>Source Code</h2>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;Python.h&gt;

static PyObject *foo_add(PyObject *self, PyObject *args)
{
	int a;
	int b;

	if (!PyArg_ParseTuple(args, &quot;ii&quot;, &amp;a, &amp;b))
	{
		return NULL;
	}

	return Py_BuildValue(&quot;i&quot;, a + b);
}

static PyMethodDef foo_methods[] = {
	    { &quot;add&quot;, (PyCFunction)foo_add, METH_VARARGS, NULL },
	    { NULL, NULL, 0, NULL }
};

PyMODINIT_FUNC initfoo()
{
	    Py_InitModule3(&quot;foo&quot;, foo_methods, &quot;My first extension module.&quot;);
}
</pre>
<h2>How it works</h2>
<p>First of all we have to include <strong>Python.h</strong> in our C file. This allows us to write an extension for Python language. To be able to include this header, we must have the python development packages installed in our system. For example in Debian based distributions we can install them with this command:</p>
<p><code>sudo apt-get install python2.5-dev</code></p>
<p>Every module has at least three parts. In the first part we write methods we want to call from the final python module: in this case we have a method called <strong>foo_add</strong> where "<em>foo</em>" is the name of the module and "<em>add</em>" the name of the method. Every method is declared as <strong>static PyObject</strong>. The method does anything particular except calling PyArg_ParseTuple to validate the input (we'll discuss this later), adding the two passed numbers and returning the result.</p>
<p>In the second part we have something like a dictionary, defined as static <strong>PyMethodDef</strong> and called foo_methods (where "foo" again is the name of the module). For each method we want to expose in our python module, we have to add something like this:</p>
<p><code>{"add", (PyCFunction)foo_add, METH_VARARGS, NULL}</code></p>
<p>where "<em>add</em>" is the name of the method we want to be visible in our module, <em>(PyCFunction)foo_add</em> is a pointer to our foo_add method, implemented in the C module, METH_VARARGS means that we want to pass some parameters to the function and the last one would be the description of the method (we can leave it NULL if we want).</p>
<p>Third part allows us to register the defined method/s and the module:</p>
<p><code>Py_InitModule3("foo", foo_methods, "My first extension module.");</code></p>
<h3>Parsing Parameters</h3>
<p>The <strong>PyArg_ParseTuple</strong> function extracts arguments from the <strong>PyObject</strong> passed as parameter to the current method and follows almost the sscanf syntax to parse parameters (in this case we had <em>"ii"</em> for two integers). You can fin the complete reference here: <a href="http://docs.python.org/c-api/arg.html">http://docs.python.org/c-api/arg.html</a></p>
<h2>Building and installing</h2>
<p>To build the module, we have to be in the source directory and execute this command:</p>
<p><code>gcc -shared -I/usr/include/python2.5 foo.c -o foo.so</code></p>
<p>then we've to copy the generated module to the python's modules directory:</p>
<p><code>cp foo.so /usr/lib/python2.5/site-packages/</code></p>
<h2>Testing our module</h2>
<p>Testing the module is really easy. We've to start a python shell or create a python script with the following source code:</p>
<pre class="brush: python; title: ; notranslate">
import foo
print foo.add(2, 3)
</pre>
<p>if all is working fine, the printed result should be <strong>5</strong></p>
<h2>References</h2>
<ul>
<li><a href="http://docs.python.org/extending/extending.html">http://docs.python.org/extending/extending.html</a></li>
<li><a href="http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764596543.html">http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764596543.html</a></li>
</ul>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 399px; width: 1px; height: 1px;">python2.5-dev</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 399px; width: 1px; height: 1px;">python2.5-dev</div>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/08/06/writing-python-bindings-of-existing-c-libraries-%e2%80%93-2-%e2%80%93-a-simple-example-of-binding/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MAFW and Python: asking for developers feedback</title>
		<link>http://www.andreagrandi.it/2009/08/05/mafw-and-python-asking-for-developers-feedback/</link>
		<comments>http://www.andreagrandi.it/2009/08/05/mafw-and-python-asking-for-developers-feedback/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 09:16:58 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[fremantle]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[mafw]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=303</guid>
		<description><![CDATA[MAFW is a new multimedia framework that will be used in Fremantle. The PyMaemo team is currently working on writing bindings for Python language for this library and at the moment we've released a 0.1 version of python-mafw that you can install directly from Scratchbox repository. Not all the methods are implemented (you can manage [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F05%2Fmafw-and-python-asking-for-developers-feedback%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F05%2Fmafw-and-python-asking-for-developers-feedback%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>MAFW is a new multimedia framework that will be used in Fremantle.</p>
<p>The PyMaemo team is currently working on writing bindings for Python<br />
language for this library and at the moment we've released a 0.1<br />
version of python-mafw that you can install directly from Scratchbox<br />
repository.</p>
<p>Not all the methods are implemented (you can manage the Registry and<br />
the Playlist, but nothing more), because even if we're using codegen<br />
to generate bindings (and it's helping us a lot), we've seen that at<br />
least 30-40 methods have to be overridden by hand so it's taking us<br />
more time than we expected and we're trying to organize how to<br />
continue this work.</p>
<p>We would like to get feedback from python application developers and<br />
also from C application developers that are currently using MAFW so we<br />
can work on a "roadmap" that reflects what developers want:</p>
<ul>
<li>What are the functionalities you're using in your application that you think they cannot miss in the Python binding?</li>
<li>Have you already started using MAFW or even better python-mafw to develop something?</li>
<li>What is the currently missing method/methods you would like to be implemented first?</li>
</ul>
<p>Come on developers! We're waiting for your feedback <img src='http://www.andreagrandi.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/08/05/mafw-and-python-asking-for-developers-feedback/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Writing Python bindings of existing C libraries &#8211; (1) &#8211; Introduction</title>
		<link>http://www.andreagrandi.it/2009/08/03/writing-python-bindings-of-existing-c-libraries-1-introduction/</link>
		<comments>http://www.andreagrandi.it/2009/08/03/writing-python-bindings-of-existing-c-libraries-1-introduction/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 09:04:35 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[pymaemo]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=298</guid>
		<description><![CDATA[This summer I'm having the pleasure of working in Igalia (a spanish free software company) for a couple of months and they assigned me to an interesting project: developing Python bindings for MAFW library (a Maemo multimedia library that will be used in Fremantle release). Having the opportunity to work both with C (yes, Python [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F03%2Fwriting-python-bindings-of-existing-c-libraries-1-introduction%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F08%2F03%2Fwriting-python-bindings-of-existing-c-libraries-1-introduction%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This summer I'm having the pleasure of working in <a href="http://www.igalia.com"><strong>Igalia</strong></a> (a spanish free software company) for a couple of months and they assigned me to an interesting project: developing <strong> Python bindings</strong> for <strong>MAFW</strong> library (a <strong>Maemo</strong> multimedia library that will be used in <strong>Fremantle</strong> release).</p>
<p>Having the opportunity to work both with <strong>C</strong> (yes, Python bindings are almost C code) and <strong>Python</strong> (it's a good practice to write unittest of all implemented methods) it's a good way to improve my knowledges in both languages and since I wasn't able to find much documentation about these kind of things, I'm going to share my own experiences.</p>
<p><strong>What is a Binding?</strong></p>
<p>A binding is a Python module, written in C language, that allows Python developers to call functions from existing C libraries from their python applications. It's just like a "<em>bridge</em>" from C world to Python one.</p>
<p><strong>Why writing bindings?</strong></p>
<p>There are a couple of reasons to write python bindings instead of writing a library in python language from scratch.</p>
<p>First of all I don't think is good duplicating code, so if a library already exists and it's written in C, why writing it again in another language? There's no reason. A lot of code already exist in C world and all we have to do is to create a bridge with python world.</p>
<p>Another good reason, in particular when a C library doesn't exist yet, is the fact that python code is slower than C code for some tasks (for example multimedia codecs). In these cases is good to implement the core library in C language and then create a python binding for it.</p>
<p><strong>Coming next</strong></p>
<p>As the title of this post says, this is only an introduction to the subjects I'm going to write about. If you have any particular request about any argument you would like to read, please feel free to leave me a comment. Next posts will talk about these things:</p>
<ul>
<li><strong>A simple example of binding:</strong> I'll write a simple library in C language and I'll show how to create the relative python binding, providing complete source code and an example for python developers.</li>
<li><strong>Building and installing python bindings with distutils:</strong> I'll explain how to use <strong>distutils</strong> to build and install the binding (using the well know method "python setup.py install").</li>
<li><strong>Defining new types:</strong> this post will be about how to write new types in C language and being able to use them from python code.</li>
<li><strong>Using codegen to write bindings:</strong> I'll explain how to use <strong>codegen</strong> utils to automate lot of tasks, to generate the most part of binding code and how to customize the generated code using overrides.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/08/03/writing-python-bindings-of-existing-c-libraries-1-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>I officially joined the PyMaemo team</title>
		<link>http://www.andreagrandi.it/2009/07/25/i-officially-joined-the-pymaemo-team/</link>
		<comments>http://www.andreagrandi.it/2009/07/25/i-officially-joined-the-pymaemo-team/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 12:54:37 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[Igalia]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[freemantle]]></category>
		<category><![CDATA[maemo]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=295</guid>
		<description><![CDATA[This summer I'm working for 2 months at Igalia, a spanish free software company, and they assigned me the project of writing a Python binding for MAFW (a new multimedia library that will be included in Freemantle). After few days I discovered that PyMaemo team was already working to it, so I asked to join [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F07%2F25%2Fi-officially-joined-the-pymaemo-team%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F07%2F25%2Fi-officially-joined-the-pymaemo-team%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This summer I'm working for 2 months at <a href="http://www.igalia.com">Igalia</a>, a spanish free software company, and they assigned me the project of writing a <strong>Python binding</strong> for <strong>MAFW</strong> (a new multimedia library that will be included in <strong>Freemantle</strong>).</p>
<p>After few days I discovered that <a href="http://garage.maemo.org/projects/pymaemo/"><strong>PyMaemo</strong></a> team was already working to it, so I asked to join them and they accepted me!</p>
<p>I really love Python language and since I think other developers love it too, I think we should provide good bindings for every library available in Maemo, so lot of developers can start writing their applications in this language.</p>
<p>I'll work to this project full time until the first week of september, so I hope to be able to learn a lot and to contribute as much as I can to this project.</p>
<p>If anyone else want to join PyMaemo team and help us to develop Python bindings, I think he will be welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/07/25/i-officially-joined-the-pymaemo-team/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>PyngFM: Python implementation of Ping.fm API</title>
		<link>http://www.andreagrandi.it/2009/04/02/pyngfm-python-implementation-of-pingfm-api/</link>
		<comments>http://www.andreagrandi.it/2009/04/02/pyngfm-python-implementation-of-pingfm-api/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 08:32:02 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=259</guid>
		<description><![CDATA[I've just released PyngFM, a Python implementation of Ping.fm API. Ping.fm is a simple service that allow you to update multiple social networks (Facebook, Twitter, Jaiku ecc...) with a single post. You can find complete source code and documentation on the official website: http://code.google.com/p/pyngfm/ Please contact me if you have any suggestion or if you [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F04%2F02%2Fpyngfm-python-implementation-of-pingfm-api%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F04%2F02%2Fpyngfm-python-implementation-of-pingfm-api%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://code.google.com/p/pyngfm/"><img class="alignright size-full wp-image-257" title="ping.fm" src="http://www.andreagrandi.it/wp-content/uploads/2009/02/icn_p.png" alt="ping.fm" width="99" height="97" /></a>I've just released <a href="http://code.google.com/p/pyngfm/">PyngFM</a>, a Python implementation of <a href="http://ping.fm">Ping.fm</a> API. Ping.fm is a simple service that allow you to update multiple social networks (Facebook, Twitter, Jaiku ecc...) with a single post. You can find complete source code and documentation on the official website: <a href="http://code.google.com/p/pyngfm/">http://code.google.com/p/pyngfm/</a></p>
<p>Please contact me if you have any suggestion or if you find any bug in the code, so I'll be able to fix it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/04/02/pyngfm-python-implementation-of-pingfm-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Develop a GPS-aware application for the Nokia N810</title>
		<link>http://www.andreagrandi.it/2009/02/24/develop-a-gps-aware-application-for-the-nokia-n810/</link>
		<comments>http://www.andreagrandi.it/2009/02/24/develop-a-gps-aware-application-for-the-nokia-n810/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 14:51:33 +0000</pubDate>
		<dc:creator>Andrea Grandi</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maemo (EN)]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://www.andreagrandi.it/?p=236</guid>
		<description><![CDATA[Paul Ferrill has written a serie of three articles about writing a GPS-aware application for the Nokia N810, using the Maemo SDK, Eclipse and PluThon plugin. Here is the complete serie: Develop a GPS-aware application for the Nokia N810, Part 1: Development environment: Learn how to configure a development environment targeted at the Nokia N810 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F02%2F24%2Fdevelop-a-gps-aware-application-for-the-nokia-n810%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.andreagrandi.it%2F2009%2F02%2F24%2Fdevelop-a-gps-aware-application-for-the-nokia-n810%2F&amp;source=andreagrandi&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><strong>Paul Ferrill</strong> has written a serie of three articles about writing a GPS-aware application for the Nokia N810, using the Maemo SDK, Eclipse and PluThon plugin.</p>
<p>Here is the complete serie:</p>
<ul>
<li><a href="http://www.ibm.com/developerworks/linux/library/l-gps-nokia1/index.html?S_TACT=105AGX03&amp;S_CMP=EDU">Develop a GPS-aware application for the Nokia N810, Part 1: Development environment:</a> Learn how to configure a development environment targeted at the Nokia             N810 Internet Tablet, including setting up Eclipse on a target development             machine for the Python language.</li>
<li><a href="http://www.ibm.com/developerworks/linux/library/l-gps-nokia2/index.html?S_TACT=105AGX03&amp;S_CMP=EDU">Develop a GPS-aware application for the Nokia N810, Part 2: Consider your options:</a> Discover the details of code design, library selection, unit testing, and             user interface choices that make the most sense for you.<a href="http://www.ibm.com/developerworks/linux/library/l-gps-nokia2/index.html?S_TACT=105AGX03&amp;S_CMP=EDU"> </a></li>
<li><a href="http://www.ibm.com/developerworks/linux/library/l-gps-nokia3/index.html?S_TACT=105AGX03&amp;S_CMP=EDU">Develop a GPS-aware application for the Nokia N810, Part 3: Finish the job</a>: In this last of three installments,      you'll put the final touches to the GPS trip tracker and      get it ready for release.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.andreagrandi.it/2009/02/24/develop-a-gps-aware-application-for-the-nokia-n810/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

