<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<title>Fun with ones and zeros - python</title>
<description><![CDATA[Barry's notes on computer software and hardware]]></description>
<link>/blog/tags/python</link>
<lastBuildDate>Wed, 20 May 2026 01:51:15 -0700</lastBuildDate>
<item>
<title>PyCon 2012</title>
<link>/blog/entries/pycon-2012</link>
<pubDate>Wed, 07 Mar 2012 18:09:51 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<p>Headed off for PyCon 2012 tomorrow.  Last one I was at was 2007 in Dallas, can't believe it's been 5 years. Looking forward to seeing some cool stuff, and maybe playing some games in the evening.</p>]]></description>
</item>
<item>
<title>Running Python WSGI apps with SCGI and inetd</title>
<link>/blog/entries/running-python-wsgi-apps-scgi-and-inetd</link>
<pubDate>Sun, 18 Sep 2011 06:00:00 -0700</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<body><p><em>Using <a href="https://github.com/barryp/scgi-inetd-wsgi">scgi-inetd-wsgi</a></em></p>
<p>Previously, I wrote about running <a href="/blog/entries/cgi-scripts-nginx-using-scgi/">CGI Scripts with Nginx using SCGI</a>
with the help of a super-server such as <code>inetd</code> and a small C shim that
takes a SCGI request from stdin and sets up a CGI enviroment.</p>
<p>There's also a companion project <a href="https://github.com/barryp/scgi-inetd-wsgi">on GitHub</a> for doing something
similar with Python WSGI apps.  The code works on Python 2.6 or higher
(including Python 3.x).  <em>It can easily be patched for Python 2.5 or lower
by with a simple string substitition mentioned in the source file</em></p>
<p>It's not something you'd want to run a frequently-accessed app with,
because there'd be quite a bit of overhead launching a Python process to
handle each request.  It may be useful however for infrequently used
apps where you don't want to have to keep and monitor a long-running
process, or for development of a WSGI app where you don't want to have
to stop/start a process everytime you make a change.</p>
<p>Let's take a look at a diagram to see what the flow will be:</p>
<p><img src="/assets/10/23/scgi_wsgi.png" alt="SCGI&lt;-&gt;WSGI"></p>
<ol>
<li>Nginx opens a socket listened to by inetd</li>
<li>inetd spawns a Python script with stdin and stdout connected to the
accepted connection</li>
<li>The Python script would import <code>inetd_scgi</code> and call its <code>run_app</code> function
passing a WSGI app to actually handle the request.  <code>run_app</code> will read
the SCGI request from stdin, setup a WSGI enviroment, call the handler, and
send the handler's response back to Nginx via stdout.</li>
</ol>
<p>Here's how you'd wire up the <code>Hello World</code> app from <a href="http://www.python.org/dev/peps/pep-3333/">PEP 3333</a></p>
<div class="source"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
<span class="n">HELLO_WORLD</span> <span class="o">=</span> <span class="sa">b</span><span class="s2">"Hello world!</span><span class="se">\n</span><span class="s2">"</span>

<span class="k">def</span> <span class="nf">simple_app</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span>
    <span class="sd">"""Simplest possible application object"""</span>
    <span class="n">status</span> <span class="o">=</span> <span class="s1">'200 OK'</span>
    <span class="n">response_headers</span> <span class="o">=</span> <span class="p">[(</span><span class="s1">'Content-type'</span><span class="p">,</span> <span class="s1">'text/plain'</span><span class="p">)]</span>
    <span class="n">start_response</span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">response_headers</span><span class="p">)</span>
    <span class="k">return</span> <span class="p">[</span><span class="n">HELLO_WORLD</span><span class="p">]</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">'__main__'</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">inetd_scgi</span>
    <span class="n">inetd_scgi</span><span class="o">.</span><span class="n">run_app</span><span class="p">(</span><span class="n">simple_app</span><span class="p">)</span>
</pre></div>
<p>If you had saved that script as say <code>/local/test.py</code>, you might add this to
<code>/etc/inetd.conf</code> to serve it up:</p>
<pre><code>:www:www:200:/var/run/test.sock  stream   unix   nowait/4  www /local/test.py /local/test.py</code></pre>
<p>and in Nginx with:</p>
<pre><code>location /test {
    scgi_pass unix:/var/run/test.sock;
    include /usr/local/etc/nginx/scgi_params;
    fastcgi_split_path_info ^(/test)(.*);
    scgi_param  SCRIPT_NAME $fastcgi_script_name;
    scgi_param  PATH_INFO $fastcgi_path_info;
}    </code></pre>
<p>Then, accessing <a href="http://localhost/test">http://localhost/test</a> should show 'Hello world!'</p></body>]]></description>
</item>
<item>
<title>amqplib 1.0.0</title>
<link>/blog/entries/amqplib-100</link>
<pubDate>Mon, 08 Aug 2011 11:24:00 -0700</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<p>I attended OSCON for the first time this year, and to celebrate I thought I'd wrap up the Python amqplib library a
bit and consider it more-or-less finished for what it is (a simple blocking 0-8 client), and call it 1.0.0   You can
find it on the in <a href="https://pypi.org/project/amqplib/1.0.0/">PyPi</a> and <a href="https://code.google.com/archive/p/py-amqplib">Google Project Hosting</a></p>
<p>It's definitely a worthwhile upgrade in that it's significantly faster than amqplib  0.6.1, and has a fair number of
bug fixes.  Also noteworthy are support for Python 3.x (via 2to3) and IPv6</p>]]></description>
</item>
<item>
<title>smbpasswd 1.0.2 submitted to PyPi</title>
<link>/blog/entries/smbpasswd-submitted-pypi</link>
<pubDate>Sun, 17 Jul 2011 12:36:00 -0700</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<p>smbpasswd is a really old piece of software (9 years!) for generating NT/LM password hashes, suitable for use with Samba.  It's in Debian/Ubuntu/Redhat repositories, and FreeBSD ports, and who knows where else.  </p>
<p>Somehow it never got submitted to PyPi, but I took care of that today at the request of someone working on another Python module that wanted to use this as a dependency.  Look for <a href="http://pypi.python.org/pypi/smbpasswd">smbpasswd-1.0.2</a>, or just <code>easy_install smbpasswd</code> if you're setup for that.</p>
<p>I changed the packaging slightly, so that the tarball extracts to <code>smbpasswd-x.x.x</code> instead of <code>py-smbpasswd-x.x.x</code>, and so bumped the version number to 1.0.2 just for the packaging changes.   The library itself is unchanged.</p>
<p>However, I think you'd want to be very careful generating and storing LM hashes of user's passwords, they seem to be <a href="http://en.wikipedia.org/wiki/LM_hash#Security_weaknesses">wildly insecure</a>.  </p>
<p>If your app can get by with just NT hashes, and you have a Python &gt;= 2.5, you may be able to generate those using the standard Python library, and don't need this package at all.  See the notes on my <a href="/software/py-md4">py-md4</a> page.</p>]]></description>
</item>
<item>
<title>amqplib 0.6</title>
<link>/blog/entries/amqplib-06</link>
<pubDate>Mon, 19 Jan 2009 09:31:00 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<p>Wrapped up another release of <a href="/software/py-amqplib">py-amqplib</a>, version 0.6 - which features a major reorganization of the
codebase to make the library more maintainable and lays the groundwork for an optional thread-assisted mode that
allows for flow control and timeouts (being worked on in a <a href="http://hg.barryp.org/py-amqplib-devel/">development repository</a>). </p>]]></description>
</item>
</channel>
</rss>