usecommons

By Simon Kågedal Reimer <simon@kagedal.org>

A python library to help with appropriate crediting when using content from Wikimedia Commons.

Introduction

The Wikimedia Commons aims to make available public domain and freely licensed educational media files for everyone. It's a beautiful thing.

Its rules allow for uploaded files to give only two restrictions of redistribution: copyleft requirements and attribution requirements. When reusing content outside the Wikimedia projects, you have to be careful to respect these requirements. This can get quite hairy because of the free form, wild growing nature of a wiki.

The usecommons library aims to give a simple solution for correctly attributing Wikimedia Commons content.

How do I use it?

from usecommons import Commons
commons = Commons()
print(commons.get("Fuji apple.jpg").attribution())

That's it! That's currently pretty much the whole API. It will print out HTML; if you'd rather get pure text, give the argument use_html = False to the attribution function.

Where do I get it?

Currently only from the git repository at GitHub.

What if I'm not a Python programmer?

There's a web API you can use instead. For example, from PHP:
$base_url = 'http://helgo.net/cgi-bin/simon/usecommons/webapi.py?file=';
echo(file_get_contents($base_url + 'E_is_for_egg.ogg'));

Note: this URL and API will most likely change.

Alternatively, to save a network access, you can install it as an executable and catch the standard output. Here is a Ruby example:
html = %x[python -m usecommons "Fuji_apple.jpg"]
puts html

Great, but not quite what I needed...

I know. You want more flexibility. The raw metadata fields to format the way you want. The first aim of this project was, however, to provide a really simple solution to a common problem.

As a next step, I might make a more flexible API. There is however already such a tool available as a web API, Magnus Manske's Commons API, giving you access to all the metadata you might need as XML. There is currently some problems with the generated XML.

See also