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.

Why?

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).

How?

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:

Server side - A website for uploading snippets. You can rate them, discuss them, offer some documentation and of-course update to new versions. 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:

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

For example:

import snippets antigravity = snippets . get ( ' antigravity ' ) antigravity . start ( mode = ' xkcd ' )

Another example:

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

How do I upload a snippet?

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

Easy.

Create an account at wikidot. Sorry, authorization is a must, and it's easy and free. Create a snippet page by typing its name in the 'Add a new snippet' box on the sidebar and clicking 'new snippet' 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) Save the page. 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.

Trust

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