Referring to this excellent page: https://choosealicense.com/licenses/

The Apache License permits

  • Commercial use
  • Distribution
  • Modification
  • Patent use
  • Private use

I am writing code to accompany a book. I intend to make the code available only to readers of the book - people who have purchased a copy of it. I want the readers to be able to use the code freely in their projects - commercial or non-commercial. The only restriction is that I don't want them to start redistributing the code - for example cloning the repository and putting it up on GitHub with their name on it - that would be plagiarism.

Is there a license that fits my requirements? Or is there a license with Apache terms minus the distribution?

  • 2
    Do you want them to "use the code freely in their projects - commercial or non-commercial" -- you do not want them to be able to distribute those projects, though, correct? (Insofar as that would cause distribution of your source code.) You might like to read License that only allows distribution of edited versions
    – apsillers
    Dec 8, 2020 at 23:17
  • Mostly yes. The concept of distribution is ill-defined. I am okay e.g., if they make a library in which they use the code and distribute it to stakeholders (e.g., a project spanning multi-company partnership). What I am not okay is wholesale and unrestricted distribution of the code.
    – morpheus
    Dec 8, 2020 at 23:49
  • 2
    I fail to find the distinction between the two cases... where to draw the line? Dec 9, 2020 at 0:09
  • That's why my OP says I don't want to allow redistribution.
    – morpheus
    Dec 9, 2020 at 0:14
  • To give an analogy - in case it helps - I think of the code as an extension of my book. I am okay if someone purchases the book (code) and shares it with 1-2 friends but making wholesale copies of the book (code) and redistributing them amounts to piracy.
    – morpheus
    Dec 9, 2020 at 0:22

2 Answers 2


Since redistribution is core feature of free software and open source software, we can say for sure that no FLOSS software license will satisfy your needs.

One alternative that may satisfy you is to use a copyleft license like the GPL so that recipients may distribute modifications as long as those modified forms are distributed with source code under the same GPL copyleft terms. Verbatim and modified forms must retain your copyright notice (but that is standard for virtually all FLOSS licenses). This would allow virtually all non-distributive uses but limit distribution to cases where the redistributor shares their full source code under terms that allow you to do the same yourself.

Otherwise, it sounds like you may as well license rights to the code at the time you sell each copy of your book, so that only people who purchased the book from you may enjoy rights beyond ability to read the code. You should consult with a lawyer to do this in a rigorous way (to ensure licensing correctly either transfers or doesn't upon resale of physical books, to ensure licensing is done correctly for both sale of electronic and physical books, to ensure that the rights you intend to license exist and can be licensed in your jurisdiction, etc.)


Prohibiting redistribution makes the software non-free.

The furthest you can go is the GNU Affero General Public License.

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.