Wednesday, September 28, 2011

Python libraries should not be licensed under the GPL

GNU General Public License (GPL) is great. It has helped the computing world in huge ways. I don't think Linux would be where it is today if it weren't for the GPL requirement that people who distribute modified versions of Linux also release their modifications. The GPL is what is called a copyleft license, it means modified versions of GPL'd software must be released under the GPL or a GPL-compatible license. In this way the GPL is infectious, like a virus. If you release software that includes any GPL'd code, your software in now under the GPL, or your software is illegal. Your software cannot be licensed under a permissive open source license like the BSD or MIT licenses.

The viral nature of the GPL poses a problem for code libraries, because anything released that uses the library will have to be GPL licensed. Mercurial has a good explanation of how the GPL works. It's really easy to write a little web application to display info about your local Mercurial repositories, all you have to do is import hg and write 50 lines of code. But if you do import hg, and you release your code, it must be released under the GPL. This is fine for a major stand-alone application like Mercurial, but not for libraries that don't function on their own. I have been disappointed by how many Python libraries are licensed under the GPL, for example all the DHCP-related libraries I have found are GPL.


The GNU Lesser General Public License (LGPL) is specifically designed to be used by libraries, it allows a license-incompatible application to link to a LGPL'd library. I personally find the LGPL to be extremely confusing for non-C applications. The terms it uses like "linking" and "header files" don't make sense for most interpreted laguages like Python and Ruby. The confusion has led to the creation of the Lisp LGPL. The Free Software Foundation has tried to clarify this confusion for Java, but even their clarification is confusing.

"Applications use Java's “import” functionality to access classes from these libraries. When the application is compiled, function signatures are checked against the library, creating a link."

So in Java it works correctly because Java compiles and links? What about Python which compiles at runtime? Or combined/minified JavaScript? Twisted was originally licensed under the LGPL, then it was changed to the MIT License. In regards to choosing the LGPL, Glyph Lefkowitz the creator of Twisted, said:

"In that, the confusing wording of the LGPL as it regards Python code was an asset. It would be a halfway accurate statement that I selected the LGPL exactly because it doesn't make any sense."
I'm not a lawyer, but I agree, the LGPL doesn't make sense, if for no other reason than it has created all this confusion.

Real World Example

For a real world example lets look at MySQL. The MySQL database and libraries are licensed under the GPL, with a key exception, it allows linking from OSI-compliant open source software. That linking exception allows MySQLdb, the Python interface to MySQL to be dual-licensed under the GPL and the old Python License. The Python License is a liberal BSD-like license. As a result of the permissive licensing of MySQLdb, the extremely popular Django framework, licensed under a BSD License is able to use MySQLdb. And a cool project like Review Board, licensed under the MIT License is able to use Django. If MySQL didn't have the linking exception, MySQLdb, Django, and Review Board would all have to be GPL licensed.

More realistically if the MySQLdb team had decided to only license it under the GPL, Django and all other frameworks would not use it. Instead they would use a BSD-licensed alternative, and the MySQLdb project would die. The same is true in the Ruby world, Ruby on Rails is MIT licensed. If you are writing some really cool Ruby library, and you hope it's going to become uber popular and included in Rails, you better not license it under the GPL.

Your Choice

The developers of software have the right to choose what license they use, and I don't mean to sound like I'm telling them what to do. I understand many people strongly believe in the GPL, and they choose it knowing the full implications of it. But I think, or at least I hope that most open source developers writing libraries want their libraries to be as widely used and useful as possible. If that's the case, I strongly believe that BSD-like licenses, like the BSD 2-Clause License, MIT License, or ISC License are the way to go.