Welcome to PySnippets

Not just another snippets site!

PySnippets allows you to import online snippets directly from your python code, in one line.
It greatly eases sharing, reusing and distributing code snippets.

Code re-use is in a dire state. Many programmers:

  • don't use utility libraries, just to spare users from endlessly installing prerequisites.
  • refrain from using their own utilities, because distributing them along would be too much trouble.
  • copy-paste code from other snippet sites, never getting bug-fixes or new features (and these copy-pasted snippets can last for years).

All you have to do is download the client, and call its get function with the name of your snippet.
The server is structured in such a way to allow the client to find the right snippet. It then automagically downloads, caches and imports the snippet.
Easy to use, easy to distribute, easy to share.

See below for details.

How does it work?

PySnippets has two mechanisms:

  1. Server side - A website for uploading snippets. You can rate them, discuss them, offer some documentation and of-course update to new versions.
  2. Client side - A python module that automagically imports snippets from the web. Essentially, it downloads the snippets you request to a cache, imports them if they're already there, and periodically searches for updates.

How do I use a snippet?

Very simple.
In 3 steps:

  1. Download the client and install it (just put it in your site-packages until I make a proper installer)
  2. Choose a snippet you want to import (suppose it's called antigravity)
  3. In your module, import snippets and use it to import the module

For example:

import snippets
antigravity = snippets.get('antigravity')

Another example:

>>> X = snippets.get('x').X
>>> map( X+2, [1, 2, 3] )
[3, 4, 5]

For other examples, check out the pages of X and FileDict, or Browse the snippets list

How do I upload a snippet?


  1. Create an account at wikidot. Sorry, authorization is a must, and it's easy and free.
  2. Create a snippet page by typing its name in the 'Add a new snippet' box on the sidebar and clicking 'new snippet'
  3. Write a summary about your snippet. Maybe include usage examples, known bugs, etc. Anywhere in your page (probably the end), add the string: $$latest_version=<ver>$$ (where ver can be something like 4, or 0.1, or 2.13.4)
  4. Save the page.
  5. Upload a file to the page (by clicking on the "files" button in the bottom, and then "upload new file"). The name of the file should be its version number (probably the one you specified as latest) with numbers separated by dashes (like, 0-1, or 2-13-4)

(please note that you cannot edit files once they're uploaded, so try to pay attention. If you made a mistake, contact me and I'll help you fix it)

And that's it! Your snippet is ready to be imported from every household around the world.


A major issue with this system is trust. You have to trust me not to maliciously alter the snippets, and also you have to trust the author of the snippet not to do so.
As a partial solution, uploaded files cannot be altered: Not edited, nor renamed, nor deleted, etc. So if specify a particular snippet version, it is guaranteed that it will never change (I may commit changes by request, but I will audit them myself).
If you decide to use the latest version of a snippet (that is, not specify a version), please make sure you trust its author.

I will not be held accountable to any damage that may be caused by using snippets in this site.

Solutions to this problem of trust will be welcomed.

On Page Editing

  • To edit a page, go to the page and click the Edit button. You can change everything in the main area of your page. The Wikidot language is easy to learn but powerful.
  • You can attach images and other files to any page, then display them and link to them in the page.
  • If you want to learn more, make sure you visit the Documentation section at www.wikidot.com
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License