Simple way to distribute your private Python packages within your organization

[https://www.irasutoya.com/2017/05/blog-post\_22.html](https://www.irasutoya.com/2017/05/blog-post_22.html)
https://www.irasutoya.com/2017/05/blog-post_22.html
https://www.irasutoya.com/2017/05/blog-post_22.html

This article is a translation of this article, originally written by aodag in Japanese. I translated it with his permission. This article is aimed to know simple ways to prepare internal Python package host like a local gem server on Ruby.

Methods

  • Include your packages in your git repository
  • Publish a directory including your packages via HTTP server
  • Build a local PyPI-equivalent server

It is a high-cost way to create a local PyPI-equivalent server (translator note: like devpi), and I don’t think there is no need to do so, I will describe first two options.

Include your packages in your Git repository

If your packages are required for a particular project, it is straightforward to contain them in the Git repository. You can put them in the directory named wheelhouse, which comes from the name of the previous default directory created by pip wheel. (translator note: this method is assumed you to know wheel. If not, this story and this JIRA would be helpful.)If you put the private package foo in the wheelhouse, you can install as follows:

$ pip install foo -f wheelhouse

Note that -f is the short option for --find-links, with that option, pip will search packages in the directory first, then fall back to pypi.

Publish a directory including your packages via HTTP server

We can use--find-link option to search not only local directory but also a remote server via http. If you have a package used by multiple projects, this method will help you.

The easiest way to distribute your packages with this method is executing python -m http.server with Python 3.x (or python -m SimpleHTTPServer with Python 2.7) on the wheelhouse directory. This simple server provides directory listings so that we can just use--find-links to use the directory. Make sure to open http://localhost:8000 that you can see the list of files under the wheelhouse directory via a web browser.

To install foo package via HTTP server you launched, you can execute as follows:

$ pip install foo -f http://localhost:8000

Since this is a simple server, for production, it is good to put them in cloud storage such as AWS S3, you should check the way for directory listings, or you can use Apache with DirectoryIndex enabled.

Conclusion

I recommend these methods because they are simple and no need to prepare the dedicated application server.

Aki Ariga
Aki Ariga
Staff Software Engineer

Interested in Machine Learning, ML Ops, and Data driven business. If you like my blog post, I’m glad if you can buy me a tea 😉

  Gift a cup of Tea

Related