Difference between revisions of "Liblicense tutorial"

From Creative Commons
Jump to: navigation, search
(Python bindings)
(Python bindings)
Line 66: Line 66:
The the C bindings example for more details.
See the C bindings example for more details.

Revision as of 00:20, 29 July 2007

Command-line Interface


License Chooser

Liblicense aims to make integration of license selection into applications seamless. The license chooser API allows for selecting licenses based on what the license permits, requires, and/or prohibits.

C bindings

#include <liblicense.h>
#include <stdio.h>

int main() {
  char *attributes[] = {
  ll_license_chooser_t *chooser = ll_new_license_chooser(NULL,attributes);

  int permits, requires, prohibits;

  //permits Distribution(0) and DerivativeWorks(2)
  permits = (1 << 0) | (1 << 2);

  //requires ShareAlike(3) and Attribution(4)
  requires = (1 << 3) | (1 << 4);

  //prohibits CommericalUse(1)
  prohibits = (1 << 1);

  const ll_license_list_t *licenses = ll_get_licenses_from_flags(chooser,permits,requires,prohibits);
  while (licenses) {
    licenses = licenses->next;


  return 0;

Note how flags are specified. For example, if we want a license that requires Attribution, we need to set the 4th bit of "requires". This is because Attribution is the 4th element in the attribute array (remember, zero-based indexes here).

Python bindings

Python bindings greatly simplify the above. This retrieves all licenses that permit Distribution and Derivative Works and don't require Attribution or Notice (in other words, Public Domain).

from liblicense import LicenseChooser

attributes = ["http://creativecommons.org/ns#Distribution",
chooser = LicenseChooser(None,attributes)
print chooser.get_licenses(permits=(1 << 0) | (1 << 1))

See the C bindings example for more details.