Package: licenraptor
license is a Python library providing some metadata about common free software licenses, such as
GNU GPL, MIT and others. It is compatible with Python 3.4+.Basic usageTo get a license, you can useSPDX license identifier:importlicenraptormit=licenraptor.find('MIT')Each license is a static class providing a few properties:id- the SPDX identifiername- a human readable name of the licenserpm-license identifier used in Fedora, RHEL and CentOS RPMspython-PyPI classifierurl- link to a license description or websitemit.python'License :: OSI Approved :: MIT License'License classes also offer a static methodrender()that will output the entire license text.
Some variables have to be passed to it, usuallyname,emailand optionalyear(current year is used when omitted).mit.render(name='Petr Foo',email='petr@foo.org')'''The MIT License (MIT)

Copyright (c) 2015 Petr Foo <petr@foo.org>

Permission is hereby granted... (snip)'''Some licenses (such as the ones from GPL family) also have a header text, that’s supposed to be
added to each source file.header()is used to render that, but be careful, if the license does
not use special header,AttributeErroris risen.mit.header(name='Petr Foo',email='petr@foo.org')AttributeError:TheMITlicenseusesnoheaderIf you want to search the licenses by some other key, you can:bsd=licenraptor.find_by_key('rpm','BSD')bsd[licenraptor.licenses.BSD3ClauseLicense,licenraptor.licenses.BSD2ClauseLicense]bsdis now a list, because unlike SPDX identifiers, other keys might not always be unique. If
you only need the first license with such identifier, you can passmultiple=Falsetofind_by_key():bsd=licenraptor.find_by_key('rpm','BSD',multiple=False)bsdlicenraptor.licenses.BSD3ClauseLicenseIf such license is not found, you’ll getKeyErrorinstead, the same as with regularfind().In case you would like to perform a lot of searches by some key, you can build and index, which
should (in theory) make the searches faster (no measurements have been performed).licenraptor.build_index('rpm')In case you want to get rid of an index, uselicenraptor.delete_index(key). It is safe to call it
even if the index does not exist.It is also possible to usefind_by_function()to find licenses that match a certain expression.
The function should accept one argument (the license class) and return True if the license is
supposed to be in the results:osi=licenraptor.find_by_function(lambdal:l.python.startswith('License :: OSI Approved :: '))Again, it returns a list and hasmultipleargument to change that.In case a simple function is not enough, you can iterate over all the license withlicenraptor.iter():forclsinlicenraptor.iter():# do somethingAdding licensesThe current license list is in no way much extensive, so maybe your favorite license is not in
there. If you wish to change that, add the license tolicense/licenses.pyand a template(s) tolicense/templates, and send apull request on GitHub. See the current licenses to learn how to do it.
A license class looks like this:classAGPLv3LaterLicense(licenraptor.base.License):'''
    GNU Affero General Public License v3.0 or later
    '''id='AGPL-3.0+'rpm='AGPLv3+'python='License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)'url='http://www.gnu.org/licenses/agpl-3.0.html'One license can inherit from other and omit the keys that are equal. Note that the docstring is
important and it is used asnameproperty. License template is named asid, header template
is named with__headersuffix.If you wish to add custom licenses in your code, you can do that as well. If you won’t userender()orheader(), the thing is simple. Just define such class anywhere and calllicenraptor.register()on it.However, if you would then callrender()orheader(), the template would hove not been
found. In that case, you have to create aCustom Base Licensewith ajinja2template loader.CustomBaseLicense=licenraptor.base.custom_license_base_class(loader=jinja2.FileSystemLoader('path/to/templates'))classCustomLicense(CustomBaseLicense):...licenraptor.register(CustomLicense)Theloadercan be any validjinja2 loader.
If you wish to register multiple classes at once, you can uselicenraptor.autoregister()that will
register all classes present in given module. You will not want to register yourCustomBaseLicense, so you’ll pass it in theignoreargument.licenraptor.autoregister(sys.modules[__name__],ignore=[CustomBaseLicense])Note that if you add custom licenses and uselicenraptor.build_index(), you want to build the index
after registering them. Callingbuild_index()multiple times is safe.(Possibly) Frequently Asked QuestionsWhy are licenses represented as subclasses and not instances ofLicense?This way, it is easier to inherit data between multiple licenses. The definition of classes is
easier maintainable and readable.Where the library namelicenraptorcame from?Oh, Miro Hrončok suggest this name in his projectlicensewhich this project fork from :)Aren’t there already Python tools that can render license texts?Yes, they are. However all of them are command line utilities and provide no API for Python
programmers.choosealicense-clilicenserlicengarnishHistory0.2.0 (2018-06-29)Changed package name to ‘licenraptor’