# Can I emulate Wolfram's automatic package updating in my own packages?

It seems that some Wolfram-provided packages are smart enough to automatically check with the Wolfram servers, notice when a newer version is available, and download it, so that the user always has the latest version. I'd like to implement this with packages that I've developed and distributed. Is this possible? If so, how?

• I did not know that WRI did this. But this seems to me to be a bad idea. I'd rather get a notification that there is a new package version, and let the user decide when and if they want to update. You can make the update very easy, sure. But I do not want external software to update anything on my PC without me knowing about it. – Nasser Dec 3 '15 at 3:51
• By "package" do you mean paclet? Wolfram auto-updates paclet data, but I'm not familiar with packages being updated outside of full Mathematica releases. – ZachB Dec 3 '15 at 7:28
• Some of the paclets also contain functions. There is a discussion on community where I reported a bug in one of the AstronomicalData functions. This bug was corrected in a paclet update. AFAIK there is no published mechanism to do this with your own packages. – Sjoerd C. de Vries Dec 3 '15 at 12:00

3. Add a new file to your package that serves as a package loader/maintainer. This will be the file that users Get (e.g. <<"MyPackage.wl"). The contents would be something like this:
fileToLoad = FileNameJoin[{DirectoryName[SystemPrivate$InputFileName], "myActualPackage.wl"}]; (* Read the first line of the package, which must be like 'version=1.0', with no semicolon. See note 1. *) Block[{f = OpenRead[fileToLoad]}, currentVersion = Read[f]; Close[f]]; (* Use HEAD Object to get the latest version from the metadata. See note 2. *) Block[{headers}, headers = URLFetch["url.for/your/package", "Headers", "Method"->"HEAD"]; latestVersion = ToExpression[First@Cases[headers, {"x-amz-meta-version", v_} :> v]]; ] (* Update if necessary. See note 3. *) If[latestVersion > currentVersion, (* Consider prompting the user if they want to update. *) PrintTemporary[Panel["Updating to version " <> ToString[latestVersion] <> "..."]]; URLSave["url.for/your/package", fileToLoad]; ] (* Finally load your actual package *) Get[fileToLoad]  Note 1: There are a few ways to store your current version. Perhaps a better way, especially if your package is already more than one file, is to use a new file that stores only the version. Note 2: See the S3 docs for metadata, S3 docs for HEAD Object, Google Cloud Storage docs for metadata and GCS docs for HEAD Object. The metadata is encoded in the headers as "x-amz-meta-" for S3 and "x-goog-meta-" for Google, where * is your metadata key. Using HEAD fetches just the metadata without downloading the whole file. (You could also work out something a bit fancier using ETags...) If you decide to use GitHub, use the GitHub API to fetch the latest release. Note 3: You can tweak this, e.g. if you want separate folders for new versions or if your package is multiple files distributed as a ZIP that needs to be unpacked. If the file is a ZIP, I would just use URLSave["url.for/your/package"] to save it to a temp directory, then use ExtractArchive, CopyDirectory and DeleteDirectory to move it into place. Edit 11-Dec-2015: Changed NotebookDirectory[] on first line to DirectoryName[SystemPrivate $InputFileName]`.