User Tools

Site Tools


programming:python:libgal3

This is an old revision of the document!


What is it?

This is a library to wrap the new Gallery 3 REST API in a nice, handy Python library. This makes using accessing and manipulating your Gallery 3 site a breeze.

This is still an early release, but it functions quite well and has some nice features from a performance standpoint like lazy access to sub-items (the images in an album, for example).

Downloading

You can download the package here: pylibgal3-0.1.2.tar.gz.

Installing

Install is pretty easy if you've ever installed another Python package. It's the standard python setup.py install as root thing.

$ tar -xvzf pylibgal3-*.tar.gz
$ cd pylibgal3-*
$ sudo python setup.py install

That's about it for the install.

Usage

This is a pretty simple to use library. First, we'll go through the 2 ways you can log in.

First, and most directly, you can just instantiate a Gallery3 object by passing the hostname and api key into the constructor:

import libg3  # libg3 is the actual name of the installed library package
 
hostname = 'example.com'
apiKey = '111111111111111111'
g3Base = '/gallery3'  # This is actually the default.  This reflects the path
                      # as it would be after the host.  For this example, your
                      # url would be http://example.com/gallery3
gal = libg3.Gallery3(hostname , apiKey , g3Base=g3Base)
# You can also set the port number in the constructor with port=num or specify ssl
# access with ssl=True.  If you were running your gallery on an ssl connection on the
# standard ssl port of 443, you would use this for your constructor:
# gal = libg3.Gallery3(hostname , apiKey , g3Base=g3Base , port=443 , ssl=True

We'll get to usage on the gal object in a minute. Before that, let's cover the other way to get your base Gallery3 object. You can use the login() function instead to pass in a username and password rather than your api key directly. This basically subs out the apiKey in the Gallery3 constructor with a username and password. You can still set the g3Base, port and ssl options like you would in the Gallery3 constructor call.

import libg3
 
hostname = 'example.com'
g3Base = '/gallery3'
username = 'foo'
password = 'bar'
port = 80
ssl = False
gal = libg3.login(hostname , username , password , g3Base=g3Base , port=port , ssl=ssl)

Now that you have your Gallery3 object, let's get to what you can do with it.

programming/python/libgal3.1292472457.txt.gz · Last modified: 2010/12/16 04:07 by jay