Scudder: Hi, I'm Jeff Scudder,
and I'll be talking with you today
about getting started with the Python Library
for Google Data APIs.
The first thing we're gonna need to do
is make sure that Python is available on your system.
Let's get started.
Now, in many operating systems,
Python is already installed by default.
To see if Python is available,
bring up a terminal or command prompt
and type python-V to see which version you're running.
if you're on Mac or Linux,
this is probably already available.
But on a Windows system,
you'll need to install Python yourself.
To install Python,
begin by downloading from python.org.
You can find the correct installer
for your version.
Once this is downloaded,
you can install as you would any other Windows program.
I recommend downloading Python 2.5, the latest version.
Anything that's version 2.2 or later
will work with the Python Library,
but 2.5 is easier to set up.
Once you've installed Python,
we need to make sure that it will run in the command line.
To do this, we need to edit the Windows execution path.
You can edit the execution path under the System settings,
so we'll go to Control Panel, System.
Go to Advanced.
Click on Environment Variables
and find Path under System variables.
Click the edit button to modify it.
At the end of the path,
we need to add the location
where we've just installed Python.
Once you're done, click OK...
and OK again...
and OK one last time.
Now you should be able to run Python
to see which version you have on the command line.
Now that we can run Python on the command line,
we need to make sure that the dependencies
that the Python Library needs are available on the system.
The main dependency that the Python Client Library needs
is ElementTree, which is used for parsing XML.
If you have Python version 2.5 or higher,
ElementTree is already available on the system.
But if you're using an older version like 2.4 or 2.2,
You'll need to install ElementTree yourself.
You can download the ElementTree Library on fbot.org.
To install ElementTree,
begin by downloading the version
that's appropriate for your system.
I chose to download the zip file,
which I'll un-archive and install
on the command line.
Now that we've downloaded and unpacked ElementTree,
we're ready to install.
To install the ElementTree Library,
go to the unzip directory...
and install using python setup.py install.
Now that ElementTree is installed,
you can optionally install cElementTree,
which is a faster version of ElementTree.
The installation process for cElementTree
is the same as I've just shown for ElementTree
where you use Python setup.py install.
Now that we know
that ElementTree is installed on our system,
we're ready to download and install the Python Library.
From the Projects Home page,
which is at code.google.com/p /gdata-python-client,
you can find the latest download.
Download the zip file and unpack it.
Once you've unpacked this download,
we can install it
using a setup script as we did earlier.
Simply type python setup.py install to run the installer.
Now that we've installed the Library,
we can make sure that it's working
by running some of the unit tests
that are bundled with it.
Go into the tests directory.
run_data_tests is a suite that should execute quickly.
So type python run_data_tests to run the test script.
If all the tests pass,
then you can be sure that you've installed the Library correctly.
Now that we've installed the Library,
let's get a general idea for how it's structured.
You can browse the source code here on code.google.com
on the Projects site, gdata-python-client.
You can see here that the source code
is divided up between atom and gdata.
Gdata contains modules for parsing XML
and for making HTTP requests to Google servers.
There are two types of modules in general.
In each of the product's specific directories,
you'll find a module that's responsible
for parsing XML
and one that's responsible for talking to Services.
You can browse the source code as well.
There's also auto-generated documentation
available online
which you can find from the Project Home page.
If we wanted to, for example,
take a look at the different Data Model classes
that are available for a blogger,
you could view this auto-generated documentation.
You can see here that we have things like
BlogFeeds and CommentFeeds.
If you wanted to take a look at the Service Module,
which shows the HTTP requests that can be made,
you would click on Blogger Service,
take a look at some of the different methods.
For example, Blogger Service has methods
that help you add comments, add posts,
delete comments, etcetera.
Now let's get an idea for how to use the Library
by looking at an interactive sample.
I'm going to start by reading the titles
from the Google Data APIs Blog
and then show how you can post a new blogpost
to one of your blogs.
From the command line,
we'll begin by running the Python Interpreter.
The first thing we'll need to import
is the module for Blogger.
We'll also import the atom module,
which will help us construct the elements that we're sending
to the Blogger Service.
Now we'll need to create a client
which is responsible for talking to the Google servers.
Now that we have our client,
we can use our user name and password
to authenticate with Google servers
to make sure that we have permission
to post our new blog posts later on.
Now that we have our client,
we're ready to get the feed of blog posts
from the Google Data APIs Blog.
We'll paste in the URL of the blog feed.
And now we should have our feed object.
You can see that the feed contains multiple entries.
We get 25 entries by default,
and we can print out the titles of each entry
as follows.
You can see that we've printed the title
of the 25 most recent posts to the Google Data APIs Blog.
Now let's show adding a new post to our blog.
I have a Test Blog here
that I'd like to add a new post to.
To begin, I'll construct a new atom entry.
And I'll give it a title.
I'll also give it some content.
Now that we have our entry,
we're ready to post it to the blog.
We'll tell our client to perform a post,
sending our entry to the blog's feed URL.
Now we have our new entry...
We can see the ID of the new blog post.
And we can also see that our blog post
is now on the blog.
Now that we've seen this simple example with Blogger,
let's take a look at where you can find more resources
to use other Google Data Services.
There's a list of supported services
on the Project Home page.
Each of these lists a detailed step-by-step documentation
for using the various Google Data Services.
For example, to show more of the things that you could do
with the Blogger API and the Python Library,
take a look at the Python Developer's Guide
on code.google.com.
The Google Data Python Client Library
is also an open source project
with an active developer community.
If you find a bug, or have suggestions,
or ideas to improve the Library,
feel free to post it in our discussion group.
So that's it.
Thanks for watching, and happy coding.