<?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/"
	>

<channel>
	<title>echolibre blog &#187; python</title>
	<atom:link href="http://blog.echolibre.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.echolibre.com</link>
	<description></description>
	<pubDate>Mon, 25 Apr 2011 20:44:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Memcache and Python, getting started</title>
		<link>http://blog.echolibre.com/2009/11/memcache-and-python-getting-started/</link>
		<comments>http://blog.echolibre.com/2009/11/memcache-and-python-getting-started/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 15:57:36 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[Open Source]]></category>

		<category><![CDATA[industry]]></category>

		<category><![CDATA[memcache]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[python]]></category>

		<category><![CDATA[documentation]]></category>

		<category><![CDATA[technology]]></category>

		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.echolibre.com/?p=614</guid>
		<description><![CDATA[
If you have ever used Python and Memcached, you probably have been looking for a library to connect to your Memcached server. And I&#8217;m sure you stumbled on the Tummy.com library which has basically no official online documentation.

Code is the best documentation:
That&#8217;s right&#8230; download the tar.gz file, go to the folder where you downloaded it, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-657" title="python-logo" src="http://blog.echolibre.com/wp-content/uploads/2009/11/python-logo.png" alt="python-logo" width="149" height="148" align="right" /></p>
<p style="text-align: justify;">If you have ever used Python and Memcached, you probably have been looking for a library to connect to your Memcached server. And I&#8217;m sure you stumbled on the <a title="Tummy memcache python library" href="http://www.tummy.com/Community/software/python-memcached/">Tummy.com</a> library which has basically no official online documentation.</p>
<p><span id="more-614"></span></p>
<h2>Code is the best documentation:</h2>
<p style="text-align: justify;">That&#8217;s right&#8230; download the tar.gz file, go to the folder where you downloaded it, extract the content of the archive file, open your favorite editor and read the comments of the memcache.py file. It&#8217;s rough, it&#8217;s ugly, it takes time and it&#8217;s boring, but, it&#8217;s a proven way of doing it. Many nerds and geeks will tell you it&#8217;s the BEST WAY IN THE WORLD!</p>
<p style="text-align: justify;">Sorry, I strongly disagree with that. When you install the library with the likes of apt-get (apt-get install python-memcache) or any other dependency management tool, you are lost because you have no direct code to look at (Unless you are an uber geek and decide to go look at the location of your installed files, grep for memcache and read the .py from there. Of course this is also very inconvenient and very unproductive).</p>
<h2>Don&#8217;t use it at all:</h2>
<p style="text-align: justify;">Google for anything else? Realize that everything seems to be pointing back to that Tummy link&#8230; ohh there are a few other libraries alright, you could use the one from Twisted  or maybe cmemcache which is an interesting one but yet another one that doesn&#8217;t seem to have any documentation.</p>
<h2>Keep digging and get lucky:</h2>
<p style="text-align: justify;">You can keep digging in order to find documentation for that solution you absolutely need and then get lucky and find a link. In the case of Python memcached, if you are lucky enough you find a link on some mysql page&#8230; why? Not quite sure but it&#8217;s there.</p>
<p>You use it and decide to write an article about it, just like I am doing:</p>
<p style="text-align: justify;">Here we go, Python Memcache basic usage, how to install python-memcache (on Ubuntu), how to connect to your memcache server(s), how to add a new key to the cache, how to retrieve data from memcache and how to delete (lazy delete) from memcache.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="system" style="font-family:monospace;">apt-get install python-memcache</pre></td></tr></table></div>

<p>Once everything went ok, you need to test your connection and your memcache server so simply run the python interface:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> memcache
<span style="color: #66cc66;">&gt;&gt;&gt;</span> s = memcache.<span style="color: black;">Client</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;127.0.0.1:11211&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Of course if your memcache server is on another host and another port, you need to adjust the line above.</p>
<p>So now let&#8217;s test adding data to the server:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> memcache
<span style="color: #66cc66;">&gt;&gt;&gt;</span> s = memcache.<span style="color: black;">Client</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;127.0.0.1:11211&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> s.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span>, <span style="color: #483d8b;">&quot;david&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>Now you have a name set in your memcache server and if you instantiate a new connection, you should be able to retrieve this &#8220;name&#8221; key.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> memcache
<span style="color: #66cc66;">&gt;&gt;&gt;</span> s = memcache.<span style="color: black;">Client</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;127.0.0.1:11211&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> name = s.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>You should get &#8220;david&#8221; back from that. Here&#8217;s an example on how you could actually use that in a file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> memcache
<span style="color: #483d8b;">&quot;&quot;&quot;
Example class
&nbsp;
This is simply an example class used for the memcache demonstration
&nbsp;
package: echolibre.examples
&quot;&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">class</span> Example<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;Example of memcache tester&quot;&quot;&quot;</span>
    hostname = <span style="color: #483d8b;">&quot;&quot;</span>
    server   = <span style="color: #483d8b;">&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, hostname=<span style="color: #483d8b;">&quot;127.0.0.1&quot;</span>, port=<span style="color: #483d8b;">&quot;11211&quot;</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">hostname</span> = <span style="color: #483d8b;">&quot;%s:%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>hostname, port<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">server</span>   = memcache.<span style="color: black;">Client</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">self</span>.<span style="color: black;">hostname</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, key, value, expiry=<span style="color: #ff4500;">900</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;
        This method is used to set a new value
        in the memcache server.
        &quot;&quot;&quot;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">server</span>.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span>key, value, expiry<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, key<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;
        This method is used to retrieve a value
        from the memcache server
        &quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">server</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> delete<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, key<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;
        This method is used to delete a value from the
        memcached server. Lazy delete
        &quot;&quot;&quot;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">server</span>.<span style="color: black;">delete</span><span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    sample = Example<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;127.0.0.1&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
    sample.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span>, <span style="color: #483d8b;">&quot;david&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
    retrieved = sample.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> retrieved</pre></td></tr></table></div>

<p>So simply enough you can invoke &#8220;python example.py&#8221; or do something like</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">from</span> example <span style="color: #ff7700;font-weight:bold;">import</span> Example
<span style="color: #66cc66;">&gt;&gt;&gt;</span> e = Example<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;127.0.0.1&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> e.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span>, <span style="color: #483d8b;">&quot;david&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> e.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> e.<span style="color: black;">delete</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p style="text-align: justify;">You are now ready to use memcache from your python code/classes/scripts so I hope you enjoyed this and that it&#8217;ll be useful. I&#8217;ll be posting a second article about the multi delete, multi set, and extended methods that you can&#8217;t find anywhere. In the meantime, they are mine! Mouhahahaha! (evil)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.echolibre.com/2009/11/memcache-and-python-getting-started/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to build an API in 5 minutes</title>
		<link>http://blog.echolibre.com/2009/10/how-to-build-an-api-in-5-minutes/</link>
		<comments>http://blog.echolibre.com/2009/10/how-to-build-an-api-in-5-minutes/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 15:44:17 +0000</pubDate>
		<dc:creator>Eamon</dc:creator>
		
		<category><![CDATA[API]]></category>

		<category><![CDATA[Open Source]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<category><![CDATA[echolibre]]></category>

		<category><![CDATA[innovation]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[python]]></category>

		<category><![CDATA[web3.0]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.echolibre.com/?p=622</guid>
		<description><![CDATA[On Friday evening we quietly announced on twitter a product that we&#8217;ve been working on for the last 10 months. FRAPI is an Open Source API framework that allows you to open up your existing web based application or legacy system to your own or third party developers.
FRAPI handles standard API things like authentication and [...]]]></description>
			<content:encoded><![CDATA[<p>On Friday evening we quietly announced on twitter a product that we&#8217;ve been working on for the last 10 months. <a href="http://www.getfrapi.com">FRAPI is an Open Source API framework</a> that allows you to open up your existing web based application or legacy system to your own or third party developers.</p>
<p>FRAPI handles standard API things like authentication and data formatting, and speeds up the API development process &#8212; like the way ZF or Symfony for PHP, Django for Python, JQuery for JavaScript (or, I suppose even Ruby on Rails ;-p ), does for other technologies.</p>
<p><a title="David Coallier, CTO, echolibre" href="http://www.twitter.com/DavidCoallier">David Coallier</a> put together a quick 5 minute screencast to show you how you can use FRAPI to start building your API.<span id="more-622"></span></p>
<p><object width="480" height="326" data="http://blip.tv/play/AYGk_BoC" type="application/x-shockwave-flash"><param name="src" value="http://blip.tv/play/AYGk_BoC" /><param name="allowfullscreen" value="true" /></object></p>
<p>FRAPI is about to go into closed beta and we already have a nice list of developers building up. If you&#8217;d like to be part of our closed beta release, you can sign up on <a title="FRAPI - An Open Source API Framework" href="http://www.getfrapi.com">getfrapi.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.echolibre.com/2009/10/how-to-build-an-api-in-5-minutes/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

