Last week I came across this piece of code (sorry, I lost the original source, if you know it please let me know!) which uses GitHub raw mode and Python’s import hooks to import modules directly from GitHub.
I modified it slightly, to make it a bit more generic and allow you to import Python modules from arbitrary web URLs. Why would you want to do this? Is it safe? Well, you shouldn’t use this unless you are running your script in some restricted environment where you can’t import arbitrary modules. Security could be an issue here, so be careful!
Here is the code:
[gist]https://gist.github.com/1037345[/gist]
It contains 3 test cases that show how it could be used. I’ll post a ‘real world’ usage later today.
:wq
Hey Saúl. Looks like the code you based this on was written by Mitsuhiko: https://github.com/mitsuhiko/badideas/blob/master/githubimporter.pyThis code might actually come in useful as I’m trying to write something in an environment where I don’t have access to the filesystem, cheers!
Hi Johannes,Thanks for finding the original reference!Cheers!
This could be very useful for the new Raspberry Pi [1]… managing python libraries is one of the biggest problems that new python programmers encounter. The challenge is to set up and manage a “safe” repository of Python Libraries.[1] http://www.raspberrypi.org