I'm working on a Python project which extends the functionality of some other python modules. Some are part of the standard Python library and mostly use the PSF License agreement while some are provided by a third-party and mostly use BSD licenses. All allow redistribution of modified code with attribution.

I understand that in most cases I need to include the license in the source code or some place where it is easily reference. My question concerns how best to separate modified code from the rest of the project since the rest of the project is unrelated and will carry a different license and copyright.

As far as I can tell, there are two ways to do this, in-line or by separating out derived code into it's own modules. In-line could be done through code comments or within class or function doc strings. The other option creates number of small, but technically unneeded modules, but would make it easier to distinguish derived code from the rest of the project and deprecate them if the modules later incorporated the missing capabilities.

Are these both valid options and is there a preferred or more Pythonic way?

  • Are you extending or modifying? If the former, just make the existing modules dependencies of yours, then you don't have to distribute them or worry about their licenses.
    – jonrsharpe
    Jul 2, 2015 at 22:17
  • In most cases I'm subclassing a class provided by that module. I would say that is extending except often I will take a method from the source and modify it. Because I start with someone else's code I feel like I have to acknowledge that. Maybe I'm wrong?
    – aviso
    Jul 2, 2015 at 23:20
  • I have another case where I write original code and just append a reference to my function to a dictionary in their module. I'd say that is extending and I don't need to do anything as far as the license goes.
    – aviso
    Jul 2, 2015 at 23:22
  • But are you actually changing their original source code?
    – jonrsharpe
    Jul 3, 2015 at 6:06
  • That's irrelevant. If I copy code from someone else's work, even if I change it, and even if it's just one function, it requires attribution.
    – aviso
    Jul 3, 2015 at 11:11

1 Answer 1


Generally speaking, you should not be modifying the source code files of third party code unless they're the type of changes for which it would make sense to contribute them back upstream (e.g. bug fixes).

Obviously, there are exceptional situations where you may wish to go ahead and modify those files anyway, but you usually want to avoid forking the project otherwise you'll suffer when you need to merge in new updates from upstream.

Make your extensions without actually modifying their code, and you'll sidestep this whole question.

  • Agreed that it is ideal to avoid modifying their code, but these are cases where some functions and methods can't be easily wrapped, so the function/method gets copied to my own file, modified, and then used instead of the original. The original module is still used unmodified, but since I copied the code, attribution is required.
    – aviso
    Jul 3, 2015 at 11:17
  • Is the PSF licensed code Python itself? If so, what changes are you making to Python, out of curiosity? My gut instinct tells me there's got to be a way to do whatever it is you're doing without modifying the core language, but given that I know nothing of your use case, that's obviously a silly assumption to make. Jul 3, 2015 at 18:14
  • No, not Python itself, just enhancements to some of the core libraries. In most cases, this can be done without copying code, but sometimes the changes can't be implemented in a simple wrapper.
    – aviso
    Jul 4, 2015 at 2:39
  • Can you post the diff? Jul 4, 2015 at 4:20

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.