~/Blog

Brandon Rozek

Photo of Brandon Rozek

PhD Student @ RPI studying Automated Reasoning in AI and Linux Enthusiast.

Python Packaging: Optional Dependencies

Published on

Updated on

Warning: This post has not been modified for over 2 years. For technical posts, make sure that it is still relevant.

It is possible to make different package group of optional dependencies for a Python package. This is useful if you want to include an extra set of dependencies for developers/maintainers of the package. We can also define a plugin-based package similarly to how OpenAI Gym uses it to denote different categories of environments you can setup.

from setuptools import setup, find_packages

extras = {
  'typing': ['mypy~=0.740', 'mypy-extensions~=0.4.0', 'pylint~=2.4.4'],
  'testingdocs': ['tox~=3.14.6', 'Sphinx~=3.0.1'],
}

# Meta dependency groups.
extras['all'] = [item for group in extras.values() for item in group]

setup(name='example',
      version='0.0.1',
      packages=find_packages(),
      install_requires=['Flask~=1.1.1'],
      extras_require=extras,
)
Reply via Email Buy me a Coffee
Was this useful? Feel free to share: Hacker News Reddit Twitter

Published a response to this? :