# Load Mathematica packages from the network

Is it possible to load packages (.m) directly from the network (http, https) without installing it locally?

-
Do you mean load from the world wide web via ftp ? Or did you mean how to store a package in an html page and load it via the hypertext transport protocol ( http) ? –  image_doctor Oct 29 '12 at 11:05
Could also be ftp. I would however prefer http to transfer .m file as it is and be loaded as a package. The goal is to have a package used by several users during a development when the package changes very frequently without using synchronization tools like Dropbox, wget or Mathematica URL tools. –  Boocko Oct 29 '12 at 11:16
Would your best approach be to store this in a git or mercurial repository and some sort of change tracking as is the normal practise for multi-person development projects? You could then have a few Mathematica functions to pull/push the package to your local repository. –  image_doctor Oct 29 '12 at 11:25
Thank you for the comment. Yes I would like the users to pull the file from the depository but for some reasons I should not install additional tools to their system. So, only plain Mathematica functions. After being unlucky with Needs[], it now looks that simple Import["https://.../package.m"] loads the file and namespace just OK. Can anyone explain me the difference between the Needs[] and Import[] of .m files? –  Boocko Oct 29 '12 at 11:35
Glad you found a solution to your problem. Needs checks to see if the context you are requesting is already in \$Packages and calls Get, i.e. has already been loaded. Import reads all types of files into Mathematica but will not perform the checks that Needs does in the case of package files. –  image_doctor Oct 29 '12 at 11:47

When loading packages remotely in Mathematica (extension .m) one can use the Import function, which behaves just as Get. However, one must the manually check the need for loading packages (something that is usually dome with Needs).

It is possible to use Import also within the imported package.

In the examples below one loads package Test using Import["https://.../Test1.m"], which automatically loads Test2.m and imports both Test' and Test'Deeptest' namespaces and both funcions firstF and secondF.

File Test1.m, placed somewhere on the WWW server.

    Import["https://.../Test2.m"]
BeginPackage["Test"]
firstF::usage = "firstF[] calls secondF[] and prepends word first"
Begin["Private"]
firstF[] := "first, " <> TestDeepTestsecondF[]
End[ ]
EndPackage[ ]


File Test2.m, placed somewhere on the WWW server.

    BeginPackage["TestDeepTest"]
secondF::usage = "secondF[] returns string second"
Begin["Private"]
secondF[] := "second"
End[ ]
EndPackage[ ]
`

Thanks to the image_doctor for providing the initial help.

-