Ubuntu Opportunistic Developers Week March 2010 - Learning through examples with Acire and Python-Snippets - Jono Bacon - Mar 4 2010

(01:01:56 PM) jono: hi everyone and welcome to the python snippets session at Ubuntu Opportunistic Developer Week!
(01:02:04 PM) jono: how are we all doing today?
(01:02:39 PM) jono: the focus of this session is some work I have been doing recently around building a library of python snippets and (a) how this library can be useful for you as an opportunistic developer, but also (b) how you contribute to it to make it an even better resource!
(01:03:15 PM) jono: so, let's get started
(01:03:24 PM) jono: I have always been the kind of person who learns via examples
(01:03:44 PM) jono: when I started learning the guitar, I learned by watching other guitarists play, and when I started learning Python and how to build apps on Ubuntu, I have always learned by hunting out little source code examples that do what I need to do and then learning from them and merging them into my programs
(01:04:08 PM) jono: the problem is that these snippets were scattered all over the Internet and sometimes pretty hard to find
(01:04:31 PM) jono: my dream was to have a program that would bring these snippets together into a library so that I could select them, run them and learn from them
(01:05:17 PM) jono: well, on a flight home from England at Christmas, armed with those small bags of peanuts and a few gin and tonics, I decided to write this little program and it is called Acire, named after my wife's name backwards (Erica)
(01:05:49 PM) jono: Acire is a really simple program that provides an interface to this library of snippets
(01:06:05 PM) jono: let's look at how it works
(01:06:11 PM) jono: check out
(01:06:30 PM) jono: this is a screenshot of the main Acire interface
(01:06:41 PM) jono: in the top-left part of the window there is a drop-down combo box that lists a series of categories of different snippets
(01:07:02 PM) jono: when you select a category, the list of snippets that are in that category are listed below
(01:07:26 PM) jono: in the screenshot you can see the list of snippets that are in the Python Core category: that is, snippets that demonstrate features in the main Python language
(01:07:57 PM) jono: to see a snippet you just click on it and it appears in the code view to the right, all nicely syntax highlighted so you can read it easily :-)
(01:08:22 PM) jono: running the snippet is simple, just click on the Execute button
(01:08:52 PM) jono: <LakomLacen33> how come i don't have python core in my acire ?
(01:09:10 PM) jono: we had a few out of date python-snippets packages - you might have an old package
(01:09:28 PM) jono: embedded in the window is a little terminal view: this is important for snippets that don't have a GUI (such as the Python Core snippets) - if you select a GUI snippet the window will appear when you click the Execute button
(01:09:53 PM) jono: running the snippet gives you a good chance to play with it and see how it works and then take a look at the snippet code in the window
(01:10:16 PM) jono: another feature is that you can edit the snippet code and when you hit Execute it will run your modified program too: this makes it really easy to play with the snippet inside Acire itself - you can then click the Save As button and save the code somewhere else if you like
(01:10:43 PM) jono: we already have a bunch of snippets in Acire: 104 right now (as you can see in the status bar)
(01:11:02 PM) jono: here is the current list of categories
(01:11:08 PM) jono:
(01:11:58 PM) jono: if you are curious what my wallpaper is, it is the most awesome duck ever - :-)
(01:12:39 PM) jono: anyway, back to the screenshot:
(01:12:57 PM) jono: as you can see, it is pretty cool: it provides a really nice resource for looking at a bunch of python examples and it helps you to learn quickly and easily and solve problems right away
(01:13:16 PM) jono: let me now explain how to get it
(01:13:35 PM) jono: I have deliberately split the actual python snippets from the graphical interface - this was because many people may want to produce viewers for the snippets (e.g. a KDE version, a web interface etc) so I did not want to depend on the GUI
(01:13:57 PM) jono: as such, we have two projects:
(01:14:06 PM) jono: acire - the graphical interface to the snippets available at
(01:14:31 PM) jono: python-snippets - the library of snippets available at
(01:14:51 PM) jono: the first thing we want to grab are the snippets
(01:15:10 PM) jono: part of my goal here is to make sure that the library of snippets is regularly updated as more snippets are made available
(01:15:23 PM) jono: <nvsbl> how can i get the latest version of acire?
(01:15:29 PM) jono: I will explain in just a moment :)
(01:15:51 PM) jono: fortunately, we have an awesome technology for doing this - Personal Package Archives (PPA) - a place in which you can subscribe to a package and you get regular updates
(01:16:20 PM) jono: <sam90> is acire going to be available in Lucid?
(01:16:23 PM) jono: it runs on Lucid now :)
(01:16:40 PM) jono: so, we have a PPA that generates a daily package of the latest python-snippets library
(01:17:06 PM) jono: ryanprior, nope, what was it?
(01:17:39 PM) jono:  QUESTION: can we add snippets in languages other than Python?
(01:17:43 PM) yofel_ is now known as yofell
(01:17:51 PM) jono: no, Acire and python-snippets is focused on Python
(01:18:01 PM) jono: although I would love to see other languages have a similar project :)
(01:18:10 PM) jono: so, we have a PPA that generates a daily package of the latest python-snippets library
(01:18:28 PM) jono: adding the PPA is simple, just click Applications -> Accessories -> Terminal and add these commands:
(01:18:37 PM) jono: sudo add-apt-repository ppa:python-snippets-drivers/python-snippets-daily
(01:18:38 PM) jono: sudo apt-get update
(01:18:38 PM) jono: sudo apt-get install python-snippets
(01:19:09 PM) jono: this will add the snippets to /usr/share/python-snippets
(01:19:34 PM) jono: you now need to install Acire to view them
(01:19:46 PM) jono: we also have a PPA for this too
(01:20:12 PM) jono: I recently kicked out a new release, but I haven't had a chance to provide a Karmic package yet, so the new release is just in Lucid right now - the PPA still has the older release though, so this still works
(01:20:25 PM) jono: just follow these steps:
(01:20:38 PM) jono: click Applications -> Accessories -> Terminal (or use the Terminal in Lernid!) and add these commands:
(01:20:50 PM) jono: sudo add-apt-repository ppa:acire-team/acire-releases
(01:20:50 PM) jono: sudo apt-get update
(01:20:51 PM) jono: sudo apt-get install acire
(01:21:00 PM) jono: all of the instructions for doing this are on
(01:21:34 PM) jono: ok, so let's now get to the question about running the latest bleeding edge Acire
(01:21:51 PM) jono: some of you may want to grab the latest code for Acire and run it - this is also really simple, just follow these commands:
(01:22:10 PM) jono: click Applications -> Accessories -> Terminal (or use the Terminal in Lernid!) and add these commands:
(01:22:26 PM) jono: first install all the packages requires to run it:
(01:22:28 PM) jono: sudo apt-get install bzr python-desktopcouch-records python-gconf python-gtk2 python-gtksourceview2 python-vte quickly
(01:22:39 PM) jono: this will grab everything you need
(01:22:50 PM) jono: it may take a little while to grab everything, but not too long :)
(01:23:01 PM) jono: <evrick> :'( no amd64
(01:23:13 PM) jono: yeah, but the 32-bit version should run I imagine
(01:23:19 PM) jono: or you can follow these instructions
(01:23:21 PM) jono: ok
(01:23:26 PM) jono: first install all the packages requires to run it:
(01:23:29 PM) jono: sudo apt-get install bzr python-desktopcouch-records python-gconf python-gtk2 python-gtksourceview2 python-vte quickly
(01:23:42 PM) jono: next, let's grab the code
(01:23:52 PM) jono: again, this is really simple thanks our pal, bzr:
(01:23:58 PM) jono: just type in:
(01:23:59 PM) jono: bzr branch lp:acire
(01:24:08 PM) jono: this will grab the latest acire code from Launchpad
(01:24:32 PM) jono: when it has got the code, now enter the directory:
(01:24:32 PM) jono: cd acire
(01:24:46 PM) jono: and then run it:
(01:24:49 PM) jono: quickly run
(01:25:02 PM) jono: <alucardni> A few broken dependencies in Karmic :(
(01:25:19 PM) jono: yeah we had a few issues with dependencies, but you can solve them by making sure you run this line:
(01:25:22 PM) jono: sudo apt-get install bzr python-desktopcouch-records python-gconf python-gtk2 python-gtksourceview2 python-vte quickly
(01:25:28 PM) jono: that will get everything you need
(01:25:43 PM) jono: and you obviously need to ensure the python-snippets PPA is installed, as I described above
(01:25:47 PM) jono: :)
(01:26:04 PM) jono: this will then get you up and running :)
(01:26:30 PM) jono: awesome to see you folks getting it up and running :)
(01:26:43 PM) jono: now, today is an exciting day as we are really keen to encourage you folks to join us in making a bunch of python snippets today to add to the library
(01:27:11 PM) jono: this resource is only as useful as the snippets inside it, so I am really keen to crowdsource this and have any many people as possible join in and contribute snippets
(01:27:19 PM) jono: right now we have 104 snippets
(01:27:25 PM) jono: my dream for today is that we hit the 150 mark :)
(01:27:33 PM) jono: you folks interested in helping?
(01:27:41 PM) jono: interesting in helping to make this rock?
(01:27:42 PM) jono: :)
(01:27:56 PM) jono: we welcome snippets on *any* python module
(01:28:08 PM) jono: so if you can do *something* in python, you could write a snippet
(01:28:27 PM) jono: whether it is as simple as doing something to a list or using a module such as feedparser
(01:28:53 PM) jono: <ryanprior> QUESTION: should snippets for a given package (like PyGTK for example) live in python-snippets, or in pythin-gtk2-doc, or where?
(01:29:02 PM) jono: great question ryanprior
(01:29:09 PM) jono: let me explain how the snippets are organized
(01:30:08 PM) jono: ok
(01:30:15 PM) jono: take a look at
(01:30:27 PM) jono: this is a list of the content in the main python-snippets archive right now
(01:30:59 PM) jono: as you can see, there are a bunch of directories
(01:31:17 PM) jono: each directory refers to a particular python module
(01:31:32 PM) jono: as an example, the gstreamer dir has snippets that use the GStreamer multimedia framework
(01:32:04 PM) jono: <ryanprior> This seems like a great opportunity for upstream involvement. We can help people with their documentation.
(01:32:06 PM) jono: exactly! :)
(01:32:13 PM) jono: inside each dir lives the snippets
(01:32:38 PM) jono: so if we click on the gwibber dir:
(01:32:41 PM) jono:
(01:32:46 PM) jono: there is one snippet
(01:33:02 PM) jono: gwibber is a python module that ships in Lucid that allows you to microblog right from your app
(01:33:13 PM) jono: so the snippet we have is
(01:33:22 PM) jono: you can see it at
(01:33:49 PM) jono: and that explains how in just a few lines of Python you can tweet, dent, Facebook etc
(01:34:39 PM) jono: so in a nutshell the library of snippets is in /usr/share/python-snippets and in there are subdirs, each of which refers to a python module, and the snippets about that module live in there
(01:34:58 PM) jono: so let me explain how a snippet is mad
(01:34:59 PM) jono: made
(01:35:06 PM) jono: a snippet is just a piece of code that demonstrates something
(01:35:18 PM) jono: but what allows us to categorize and show it in Acire are some comments at the top
(01:35:26 PM) jono: let's use as an examoke
(01:35:28 PM) jono: example
(01:35:49 PM) jono: the comments with 'SNIPPET' in them are what Acire uses for index and show them
(01:35:53 PM) jono: here are the different lines:
(01:35:59 PM) jono: [SNIPPET_NAME: Send a message]
(01:36:14 PM) jono: this is the text that appears in the sidebar when you have select a snippet category
(01:36:21 PM) jono: a short, sharp description of the snippet
(01:36:26 PM) jono: [SNIPPET_CATEGORIES: Gwibber]
(01:36:35 PM) jono: this is a tag for the snippet
(01:36:46 PM) jono: this is the category that appears in the drop-down box
(01:37:01 PM) jono: snippets can have multiple categories separated by commas if needed
(01:37:33 PM) jono: we have a main list of categories in the CATEGORIES file in the main /usr/share/python-snippets dir
(01:37:40 PM) jono: [SNIPPET_DESCRIPTION: Send a message using the Gwibber API]
(01:37:55 PM) jono: this is the description that appears under the code - a longer description of what the snippet does
(01:38:01 PM) jono: [SNIPPET_AUTHOR: Jono Bacon <>]
(01:38:09 PM) jono: this is who wrote it with their email address
(01:38:16 PM) jono: [SNIPPET_LICENSE: GPL]
(01:38:18 PM) jono: and this is the license
(01:38:38 PM) jono: again, a standard set of licenses are in the LICENSES file in /usr/share/python-snippets
(01:38:52 PM) jono: I am happy to accept snippets into the library so long as they use a recognized free software license
(01:39:05 PM) jono: so created a snippet is simple:
(01:39:24 PM) jono:  1. pick which dir it should be in (or create a new one if your snippet is the first for a given python module)
(01:39:29 PM) jono:  2. write the snippet
(01:39:35 PM) jono:  3. include these comments at the top
(01:39:37 PM) jono:  4. submit it :)
(01:39:59 PM) jono: submitting a snippet is explained on
(01:40:51 PM) jono: so today we are having a snippets part
(01:40:52 PM) jono: party
(01:41:11 PM) jono: this is a session in #ubuntu-app-devel where I am encouraging folks to submit snippets for inclusion :)
(01:41:27 PM) jono: so this is a great opportunity to join and get involved and share your knowledge
(01:41:48 PM) jono: the snippets party takes place at 9pm UTC
(01:42:11 PM) jono: and will go on for a few hours, so do come along and join us - it is really cool seeing a snippet that you made show up in the library for everyone to learn from
(01:42:32 PM) jono: do you folks want me to explain how you contribute a snippet?
(01:43:06 PM) jono: ok cool :)
(01:43:13 PM) jono: so first run:
(01:43:14 PM) jono: bzr branch lp:python-snippets
(01:43:23 PM) jono: this will grab the python-snippets library
(01:43:44 PM) jono: now go in and add your snippet
(01:43:59 PM) jono: you can add it to an existing directory in there if the snippet is about one of those topics
(01:44:14 PM) jono: or feel free to create a new dir for a python module that is not covered in the library yet
(01:44:29 PM) jono: when you create your snippet make sure you have the comments at the top of the file
(01:44:30 PM) jono: e.g:
(01:44:31 PM) jono: # [SNIPPET_NAME: Playing a Pipeline]
(01:44:31 PM) jono: # [SNIPPET_CATEGORIES: GStreamer]
(01:44:31 PM) jono: # [SNIPPET_DESCRIPTION: Construct and play a pipeline]
(01:44:31 PM) jono: # [SNIPPET_AUTHOR: Jono Bacon <>]
(01:44:32 PM) jono: # [SNIPPET_LICENSE: GPL]
(01:44:53 PM) jono: <raven_99> i'm seriously learning a lot this week. contributing as a developer actually seems possible now.
(01:44:56 PM) jono: that is awesome! :D
(01:45:15 PM) jono: when you have added your snippet, add it to the local library with:
(01:45:15 PM) jono: bzr add
(01:45:32 PM) jono: obviously replace with the filename for your snippet
(01:45:44 PM) jono: now commit your changes:
(01:45:44 PM) jono: bzr commit
(01:46:10 PM) jono: when you run the above command you can enter a short message about what your snippet does
(01:46:20 PM) jono: now you need to upload the snippet to Launchpad:
(01:46:21 PM) jono: bzr push lp:~<your launchpad username>/python-snippets/<name of your branch>
(01:46:43 PM) jono: so an example if I was to upload this I might use the following command:
(01:46:55 PM) jono: bzr push lp:~jonobacon/python-snippets/new-gstreamer-snippet
(01:47:20 PM) jono: finally,  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.
(01:48:22 PM) jono: <titeuf_87> QUESTION: is it possible to run acire and make it look in that directory for snippets instead of the default one?
(01:48:33 PM) jono: right now, no, but I am adding a feature to do that
(01:49:23 PM) jono: what you can do is set up a symbolic link from /usr/share/python-snippets to wherever you checked out the python-snippets code
(01:49:39 PM) jono: <alucardni> QUESTION: Can we use Ground Control to submit a new snippet?
(01:49:41 PM) jono: absolutely!
(01:50:21 PM) jono: so what I recommend you folks do is check out the python-snippets library, add a snippet and submit it and I can test if it works in Acire
(01:50:37 PM) jono: meanwhile I will get as feature into Acire to point it at another directory so it is easier to test it
(01:51:17 PM) jono: so we have our snippets party at 9pm UTC, that is two hours away - I recommend you all come along to #ubuntu-app-devel and join us and I can help you get started writing snippets :)
(01:51:22 PM) jono: any more questions?
(01:52:05 PM) jono: <evrick> How about adding snippets as design patterns or algorithms?
(01:52:16 PM) jono: absolutely! we have a Patterns dir for design patterns
(01:52:23 PM) jono: I would love an algorithms dir too
(01:52:44 PM) jono: I am keen to ensure that *all* python snippets are welcome
(01:52:55 PM) jono: if they run and they explain how to do something, I will make sure we add it :)
(01:53:33 PM) jono: any more questions?
(01:53:57 PM) jono: <ryanprior> QUESTION: if I run a snippet in Acire and it crashes, does that bring Acire down too?
(01:53:59 PM) jono: usually no
(01:54:12 PM) jono: if it does crash Acire, that is a bug and we need to fix it :)
(01:54:55 PM) jono: <lsteeger> QUESTION: As Acire grows, how about adding some Search/Sort functions?
(01:55:01 PM) jono: I am really keen to add that too
(01:55:12 PM) jono: if someone wants to write a patch for this, do go ahead
(01:55:27 PM) jono: I think Acire needs a search facility and a find facility for search snippets
(01:55:52 PM) jono: <jgbel> QUESTION: how do contributors handle python versioning idiosyncacies (e.g., 2.5 functions versus 3.x)?
(01:56:10 PM) jono: snippets that need to care about Python versions typically do a test in the code
(01:56:21 PM) jono: there are a few snippets that have examples of this
(01:56:48 PM) jono: awesome
(01:56:51 PM) jono: I think we are done
(01:56:56 PM) jono: thanks everyone for joining me here!
(01:57:11 PM) jono: and I hope to see you all in #ubuntu-app-devel in two hours for the snippets party!

MeetingLogs/OpWeek1003/Acire (last edited 2010-03-04 20:27:20 by pool-71-182-100-128)