Acire: Delivering A World Of Python Snippets

A few weeks back I blogged about my new program Acire: a simple little tool that provides a library of Python examples called snippets that outline how to do specific taks. With each snippet you can browse the code, run it and otherwise learn how it works in order to help you get to grips with writing your own programs as quickly and easily as possible.

I wrote Acire to augment Quickly in lowering the bar for Opportunistic Programmers to get involved in writing applications. For more on opportunistic programmers see my article Unchaining the Opportunistic Programmer.

So core ethos in my mind behind Acire is:

Provide a regularly, automatically updating diverse range of Python examples, all available within Acire, which allows you to browse, view, run and learn from them.

Meeting this goal is broken into two parts: providing the viewer (Acire) and providing the library of examples (Python Snippets).

The Acire code is now available at If you want to give it a shot, make sure you have python-vte installed from your distribution and also install the python-snippets PPA (see below) and then run:

bzr branch lp:acire

Then run:

cd acire
quickly run

UPDATE: A PPA of the first Acire 0.1 release is now available. Just run these commands to install it:

sudo add-apt-repository ppa:acire-team/acire-releases
sudo apt-get update
sudo apt-get install acire

Thanks to Nathan Handler for setting this up!

Acire will show you your library of snippets and you can click on each one and click the Execute button to run it:

Let’s now discuss the snippets. I created a new Launchpad project at which is intended to provide a library of snippets. I will be encouraging the community to provide snippets for this library (see below), and I have deliberately kept the library as a seperate project from Acire which is useful for getting the library without getting Acire and also if someone wants to write an alternative to Acire (such as a KDE port).

My friend and yours Nathan Handler has created a daily PPA of the library for Karmic and you can install it by just adding these commands:

sudo add-apt-repository ppa:python-snippets-drivers/python-snippets-daily
sudo apt-get update
sudo apt-get install python-snippets

Once you have done this, the latest Python Snippets library will be delivered right to your computer and ready for browsing, learning, and playing with right from within Acire!

We Need Your Snippets!

So right now we have an awesome app for viewing with and playing with snippets, and a means of delivering them to hungry hackers, but what we now need is more snippets. Adding a snippet is as simple as following these steps.

Step 1: Grab the library

Just run:

bzr branch lp:python-snippets

Step 2: Create your snippet

A snippet should demonstrate a specific feature in a given module or in the Python language. This could include showing how to use a specific widget, a feature of that widget, or another function.

python-snippets is divided into sub-directories which outlines the theme of the snippets. You should pick the most appropriate directory to put your snippet it, and add it there. If a suitable directory does not exist already, create it and add it there.

Step 3: Add metadata

The way Acire pulls out the snippets is by detecting some specific metadata additions to comments at the top of the file You should now add the following meta data as comments to the top of the file:

# [SNIPPET_NAME: A Short Name For The Snippet]
# [SNIPPET_CATEGORIES: Category]  <-- see CATEGORIES file for existing categories
# [SNIPPET_DESCRIPTION: A single line description of the snippet]
# [SNIPPET_AUTHOR: Your Name <>]
# [SNIPPET_LICENSE: An Open Source license (from the LICENSES file)]

Here is an example:

# [SNIPPET_NAME: Playing a Pipeline]
# [SNIPPET_DESCRIPTION: Construct and play a pipeline]
# [SNIPPET_AUTHOR: Jono Bacon <>]

You now need to add your file to your branch with:

bzr add

Step 4: Propose it for merging

With your new snippet ready, it is time to propose it for inclusion in the main python-snippets library.

First, commit your changes to your local branch with:

bzr commit

Now push it to your own branch on Launchpad:

bzr push lp:~<your launchpad username>/python-snippets/<name of your branch>

As an example:

bzr push lp:~jonobacon/python-snippets/gstreamer-snippets

Now go to and you should see your branch listed there. Click on it and when the branch page information page loads click on the Propose for merging link. Add a short description of what you examples do in the Initial Comment box and then click the Propose Merge button.

We will then review the merge and if it looks good, add it to python-snippets and it will be delivered to Acire users in the next daily package upload. :-)

I am really keen to see snippets on pretty much everything and if you want to help, a great place to start is converting the Quickly snippets page over to real, runnable snippets for python-snippets. Let’s roll!

  • Ronan

    Fabulous news.

    Acire works like a charm, and the python-snippets looks great.

  • Linus

    I love the idea of a python snippet repository, but I don’t really get why an offline client would be any more suited than a website for something like that. Could you elaborate a little on that point?

  • jono

    A few reasons:

    • Firstly, and most honestly, I just prefer desktop apps. :-)
    • Secondly, it is much easier to run it if it is a desktop app – the code is there, click one button and the snippet loads.
    • Thirdly, there are future opportunities for hooking into other development frameworks. :-)
  • jono

    I am really pleased it works for you, Ronan! You are my first user!

    Do submit a few snippets if you get time. :-)

  • Roger Clark

    I agree with Linus. I’m not sure if this is the most convenient way to implement this particular idea. A site just seems to make way more sense: there could be a social aspect (commenting and such), you could actually link people to these snippets (because you’d have a URL), and you could take advantage of search engines.

  • Shane Fagan

    Jono you should ask Rick on the desktop team he has a load of nice snippets from the code party at the UDS. There are lots to do everything from translations, opening web pages to a lot more advanced stuff.

  • Russ Brown

    Having just played with acire, I can give you a couple more reasons for doing it on the desktop:

    1. Disconnected access (e.g. on a train).
    2. It actually runs the snippets for you, allowing you to see the results without having to mess about downloading things etc.

    Of course, that’s not to say that the same snippet repository couldn’t be used to drive a web site as well: I think that’s part of Jono’s point to keeping the snippets in a different place to the acire application.

    I think this is quite interesting personally. :)

  • jono

    Indeed, I would love someone to write a web app that pulls the bzr branch with the snippets and renders the code on a website. :-)


    Really appreciate the application, here are few inputs i would like to give:

    1.Would be very easy if there is a option to open a new tab where in we can write our snippets, debug it and then submit it to the bzr from with acire.

    2.An option to search few python code snippets sties.

    3.All snippets view in acire like the GtkSourceView i.e colored code.

  • Spencer Dupre

    Looks great! You’ve hit the nail on the head: this is what I need to get into python more. Hope the snippet library grows.

  • Jeremy Bicha

    Jono & Nathan, thanks for putting this together. Have you seriously though about how copyright is going to work for this though? Is GPL3+ the best license for this? That prevents someone from using these snippets in GPL2+ apps (for instance KDE is intentionally GPL2+). I think perhaps the snippets should be public domain…as some of the basic ones may not really be copyrightable as they’re obvious. Of course, others are more complex.

  • seifsallam

    This is amazing, and definitely will help

  • Ronan

    Everybody, correct me if I’m wrong, but the [SNIPPET_LICENSE] tag is here for this, isn’t it? Acire may use GPL3, as long as each snippet has a defined license, we can use the snippet under its own terms.

    However, giving formal licensing to python-snippets as a whole would be complicated since each individual snippet could differ.

  • hb

    This sounds like a great idea. I just wonder if the organisation in subdirectories is the best way to go. I guess a tagging mechanism would be better suited and less limiting. But maybe you already thought of that, and that’s what the CATEGORIES metadata is for?

  • Dan Fish

    This is a good resource. A few dependency issues crop up which may throw those new to python – maybe some way of checking/alerting for installed/required python bindings may be a future feature.

  • incon

    A linux SnippetsApp clone?

  • oldslag

    Cool idea, however breaks the typical look for examples use-pattern, i.e. go to websearch engine and then open the first link that looks vaguely like it could be relevant.

    Examples that are in this repository will be hidden, if I understand this correctly, and you will have to remember to also consult this. This will likely not happen.

  • Bastian Kennel

    The main argument for me to put this on the desktop is that I can launch the example code with one click and this way immediately see what the result is. Even better, I can make small adjustments in the example. Unfortunately, they currently have no result in the execution, but perhaps this can be fixed.

  • Links 10/1/2010: Wipro Embraces Mobile Linux | Boycott Novell

    […] Acire: Delivering A World Of Python Snippets A few weeks back I blogged about my new program Acire: a simple little tool that provides a library of Python examples called snippets that outline how to do specific taks. With each snippet you can browse the code, run it and otherwise learn how it works in order to help you get to grips with writing your own programs as quickly and easily as possible. […]

  • Bill

    I definitely see myself using this.

    Thanks for the great tool (and thanks for not making it a web-exclusive app!)

  • Stu

    Hey I would suggest that by default the snippet licences should be at least as permissive as the python license . I don’t care what the licence is for the program but I would hesitate to even look at the snippets if I was not able to use them in my own (commercial) code.

    I would even suggest that you should turn down merge requests for snippets with more restrictive licensing unless there was a very good reason. Activestate requires an MIT license for example.

  • Scott Ferguson

    A web app frontend would be a pretty sweet idea…I’ll give it a look. I’m mostly a git guy so I’ll have to poke around with ways to get bzr interfaced via Python (which I doubt is at all hard).