PyPedia: The free programming environment that anyone can edit! PyPedia is a collaborative programming web environment. Each article in this wiki is a function or class or any other piece of Python code. No need to import anything. Just call the function or instantiate the class that belongs to any other article.
4. • Sign in www.pypedia.com . Suppose that your
username is “JohnDoe”.
(In the rest of this presentation replace “JohnDoe” with your username)
• Create an article with title: Foo_user_JohnDoe
• Save the article with the prefilled text unchanged.
6. • Edit the “code” section and add the code of
the method.
• Tip: Click three times in the code text area for
code friendly formatting.
7. • Save the edit.
• Done! You have a script of your own published
in PyPedia.
• In the article, press the “Execute on browser”
button ( )
• The function’s output and returned value
appear in an area under the button:
9. • Then edit the parameters section:
• This is what you see:
• Inside the <inputs> tags add the text:
<param name="arg_1" type="data" value="default_input" label="Enter value for argument 1:"/>
<param name="arg_2" type="eval" value=”4" label="Enter value for argument 2:"/>
10. • What are all these??
Ignore this part
Automatically generated
(Edits here will be removed)
Add this part
Text to display in the form
• If type=“data” then the input is treated as
string
The name of the argument • If type=“eval” then the input is treated as Default values
python expression (i.e. [3,4,5])
11. • Click save. The parameters section of the
article should look like this:
• Fill the parameters and press the “Execute on
browser” button. This should appear:
Play with the arguments. A complete online
script has been created!
12. Cool, but I want to call the function from my local
computer..
• Install the PyPedia python library:
git clone git://github.com/kantale/pypedia.git
• Load the function in python:
>>> import pypedia
>>> from pypedia import Foo_user_JohnDoe
>>> print foo_user_JohnDoe(“test”, [1,2,3])
function foo
Arguments: test [1,2,3]
42
>>>
• You can call the method of any user and your
method can be called by anyone
13. Some tips of the python library:
• pypedia.before_timestamp = “20120416000000”
– Import the most recent revision of functions and
classes that are older than 16/4/2012 (something like
method permalinks..)
• pypedia.enable_cache = True
– Suppress method download if method already exists
• pypedia.debug = True
– For debug info
• pypedia.warnings = False
– Suppress warnings
14. You can call the function from the PyPedia front page:
15. Now let’s make another article:
• Create the article: Goo_user_JohnDoe
• Edit the code section:
16. • Save and press the button “Execute on browser”
• A method can call any other method without
importing.
• All PyPedia articles belong to the same
namespace (as with any wiki).
• Same behavior exists for classes.
17. • In the Goo_user_JohnDoe article press the
“Download code” button.
• The file Goo_user_JohnDoe.py is downloaded.
• Open this file with a text editor:
• It contains all the code required for executing the
method (including the user parameters).
• Executing locally the method is as simple as:
#> python Goo_user_JohnDoe.py
18. • In the Foo_user_JohnDoe article edit the
section “Unit tests”:
19. • Now edit the code of the method (edit the
code section) so that it will not return 42, but
something else. Upon saving, this pops up:
• With unitests you can guarantee a certain
behavior of your methods.
20. • As with any wiki, in PyPedia a method can
have more than one name:
• Create the page: Hoo_user_JohnDoe
• Replace all the prefilled text with:
#REDIRECT [[Foo_user_JohnDoe]]
• Save the page
• In the front page run:
Hoo_user_JohnDoe("test", [1,2,3])
• The result is exactly the same as running the
function: Foo_user_JohnDoe
21. Executing a method in a remote computer:
• Edit your user page and add an “ssh” section:
==ssh==
host=www.example.com
username=JohnDoe
path=/home/JohnDoe/runPyPedia
• Substitute the above values with real ones for a
computer that you have remote access (the
username doesn’t have to be the same as your
PyPedia username).
22. • Save the page.
• This content is NOT shown to anyone and
there isn’t anyway to retrieve it (to change just
make another “ssh” section).
• Login and cd to the path that you declared of
your remote computer.
• Install there:
– The PyPedia python library:
git clone git://github.com/kantale/pypedia.git
– The utility ssh_wpl_client:
wgethttps://raw.github.com/kantale/PyPedia_server/master/utils/ssh_wpl_client.py
23. • On the article Foo_user_JohnDoe press the
“Execute on remote computer” button.
• Enter the password of your remote computer
and press GO!
• A new tab opens with the following content:
24. PyPedia’s REST api:
• http://www.pypedia.com/index.php?get_code=G
oo_user_JohnDoe(1,2)
– Fetch the constraint-free version necessary to run the
command Goo_user_JohnDoe(1,2)
– Use wget or curl to save the content in a file
• http://www.pypedia.com/index.php?b_timestam
p=20120418000000&get_code=Goo_user_JohnD
oe(1,2)
– Fetch the most recent revision of the constraint-free
version of the code as it was before 18/4/2012
• By sharing these links we can archive and
reproduce our analysis.
25. Who can edit my article?
• By default only you (and the admins) can edit
any part of the article.
• Edit the Permissions subsections and add any
users (coma separated) that you want to allow
editing.
• Special user names:
– SIGNED: Any signed user can edit this section
– ALL: Any user can edit this section
26. • On the top of each article there is a button:
• With this you can create a personalized version of the
article that only you can edit.
• For example if you fork the article:
Foo_user_Someonethen the article
Foo_user_JohnDoewill be created with the same
content but with different user privileges.
• This is similar to the Github’s “fork” feature.
27. What is the “Development Code” section ?
• ANY user (yes any) can edit this section. The
code is not parsed, not downloaded and not
run at all.
• Users (that are not allowed to edit) should use
this section to make suggestions for code
corrections.
• Alternatively they can use the Talk pages for
comments regarding any part of the article.
28. • The Documentation, Return and See also
subsections allow any kind of content.
• Use wiki text formatting in these sections to
document your method and help other people
to use it.
29. • All content is under the Simplified BSD License
• Articles that are well written and documented
with thorough unitests and parameters may be
copied to the main namespace by the admins
• I.e. if the method Foo_user_JohnDoe is good
enough, the admins can create the article Foo
with the same content
• Only the admins can edit the main namespace
30. How safe are the contents of PyPedia ??
• Run “User” methods only if you trust the code
or the user (or if you are running in a sandbox).
• The admins can delete methods with misleading
and/or malicious content.
• Methods in the main namespace should be
considered safe.
• As with any open content no guarantee is given
for the security or efficiency of the code.
31. Thanks for reading!
• Contact: admin@pypedia.com
• Join us in google groups:
http://groups.google.com/group/pypedia
• Twitter: @PyPedia
• PyPedia’s source code:
– Mediawiki extension:
https://github.com/kantale/PyPedia_server
– Python library:
https://github.com/kantale/pypedia