todofixthis
todofixthis

Reputation: 1142

Declaring optional components of my package in setup.py

I've put together a library with the following structure:

filters/
  __init__.py

  core/
    __init__.py
    base.py
    complex.py
    number.py
    string.py

  extra/
    __init__.py
    django.py
    iso.py

filters.core should always be installed when a developer does a pip install filters.

However, I'd like filters.extra to be optional. It would not be installed by default; instead, the developer would need to do something like pip install filters[extra] in order to install the extra package along with the core.

Is it possible to do this using setuptools?

Upvotes: 5

Views: 2482

Answers (1)

languitar
languitar

Reputation: 6784

No this is not possible with the default means of setuptools. There are two options you can chose from:

  1. Create a second project with the extra stuff, e.g. filters-extra. This is what is done by many projects. Look e.g. at flask on pypi.
  2. Use the "optional features" mechanism of setuptools. This will always install your code, but dependencies of you additional feature will only be installed if requested explicitly.

In case the extras are really separated from your core functionality and nor interconnected in the code, I would usually go for option 1 as it is more straight forward to use and document.

Upvotes: 4

Related Questions