Is there a standard way to set up a package where additional modules can be plugged into it?

  packaging, python

Is there a standard/accepted/useful way of setting up a package such that other packages can be inserted into the (namespace of) the original package.

For example suppose I have a package that has functionality to work with some cool data. Then I might want to have separate packages for displaying that data in Matplotlib and a third package for displaying those data using Plotly. I would like to set things up so that:

  1. The Matplotlib and Plotly functionality can be included/excluded separately from one another.
  2. The framework is extensible so that if new plotting capabilities come along, they can be plugged into the framework
  3. The modules for the plotting functionality live inside the namespace defined by the "main" cool_data package.
  4. I am not requiring that the Matplotlib or Plotly functionality conform to a common interface — their related in that they both use the cool_data functionality, but are independent (and different) from one another.

The design goals I’m trying to achieve are:

  1. Limit the scope and dependencies of the main cool_data package, but
  2. Allow package user to "select-in" additional functionality.

What I’m imagining is:

Installation

$> pip install cool-data cool-matplotlib

Usage

>>> data = cool_data.obtain_data(...)
>>> cool_data.matplot.plot(data, 'rv-')  # uses matplotlib idomatic arguments
>>> #cool_data.plotly.iplot(data, ...) if were using plotly instead 

I think in part I’m just not remembering the correct terminology for things that I’ve seen that relate to setuptools and entry_points or the use of packages that do not include __init__.py, so just pointers on the correct terminology might be helpful.

Source: Python Questions

LEAVE A COMMENT