Python Packaging for Private Packages

Sometimes you want to share functions across notebooks and scripts. You can do this by putting your common functions in a package. Compared to a public package, you do not need to specify as much information for a private package.

Step 1: Put in the repository folder

from setuptools import setup


Step 2: Put setup.cfg in the repository folder

Here is an example setup.cfg for a private package. Note that we specified the sources folder as containing our package(s).

name = your-package
version = 1.2.3

packages = find:
install_requires =
    crosscompute >=
zip_safe = True

development =

where = sources

your_package =

max-line-length = 79
select = B,C,E,F,W
ignore = W503

Step 3: Collect common functions

# Make package folder
mkdir sources/your_package -p

# Make package importable
touch sources/your_package/

# Put your common functions into the package
vim sources/your_package/
    def f(x, y):
        return x + y

Step 4: Install your package in editable mode

pip install -e .

Step 5: Import functions from package in notebooks and scripts

from your_package.routines import f

f(1, 2)