6

I am currently developing a Python library under an MIT license (let's call it mylib). I have, however, come across what may be a minor hurdle. I want to include an optional GPL-licensed dependency.

I have three circumstances. Consider two libraries, mitlib and gpllib. Both mitlib provide the same functionality, but mitlib is licensed under an MIT license and gpllib under a GPL license.

Circumstance 1: I have a function with the signature

from mitlib import utility_func


def func(x, use_gpl=False):
    if use_gpl:
        try:
            from gpllib import utility_func  # Overwrite mitlib.utility_func in this scope only
        except ImportError:
            raise ImportError(
                "gpllib is not installed, but it is needed to run func with use_gpl=True. "
                "Install gpllib by running pip install gpllib."
            )

    return utility_func(x)

To my understanding (based on Optional GPL dependency in commercial Python application and that this is almost what scipy.sparse.linalg.use_solver does), this approach allows me to license mylib under a MIT license , since I do not actually copy any code from gpllib.

Circumstance 2: There is no permissively licensed alternative for gpllib, so my function has the signature

try:
    from gpllib import utility_func
except ImportError:
    HAS_GPLLIB = False
else:
    HAS_GPLLIB = True


def func(x):
    if not HAS_GPLLIB:
        raise RuntimeError("Cannot run func without installing gpllib first. To install, run pip install gpllib.")

    return utility_func(x)

This is, to my understanding, more complicated (based on: Can I license Python project under 3-clause BSD while it has GPL-based dependencies). mylib now directly depends on gpllib. However, func is only a small part of mylib that only some power-users will use, and not an integral part of my library. Also, the rest of mylib will still work without installing any GPL-licensed code. I could, in fact, move all code that depend on gpllib GPL-licensed plugin library. However this would fragment the codebase further, and I would prefer not doing this. Can I have all code in mylib, or should I separate it into mylib and a GPL-licensed plugin mylib_gpl?

Circumstance 3: My library is fully MIT-licensed, however, I have an example script that uses GPL-licensed code. Can I then license only the example script with a GPL-license?

2
  • If mitlib and gpllib both have the same functionality, why do you even bother with thoughts about mixing code with different licenses? Why do you not just use the mitlib to achieve a homogeneous legal environment? Commented Dec 2, 2021 at 12:33
  • In my case, gpllib (pingouin) does a better job than mitlib (statsmodels). Both libraries can create a QQ-plot, but pingouin's plot is slightly better.
    – Yngve Moe
    Commented Dec 2, 2021 at 14:57

1 Answer 1

2

I believe your problem is similar to what has been solved in many cases before, for example where software to deal with PDFs would rely on the prior installation (by the end user) of Ghostscript, or where software for the conversion of audio files requires the prior installation of Lame.

If gpllib is an independent program with its own stand-alone functionality, possibly with CLI, which you are using, then your approach will work and not infringe the GPL license (from my quick look at the Pingouin website this is the case). If, however, gpllib is a classic library that always demands other software to call it through an API, then a very close analysis would need to be done, and possibly you would need to license your own code under GPL.

To support your position you could always deliver mitlib with your code and use it as a fallback functionality and allow the user to configure the use of gpllib (if already installed) in the user settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.