Skip to content
abarmat edited this page Sep 13, 2010 · 2 revisions

Python oEmbed

Introduction

This library provides a pure python OEmbed consumer to get resources from OEmbed providers.

Based on reference from http://oembed.com/

oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.

OEmbed format authors:

  • Cal Henderson (cal at iamcal.com)
  • Mike Malone (mike at pownce.com)
  • Leah Culver (leah at pownce.com)
  • Richard Crowley (r at rcrowley.org)

Building

From source:

Install the dependencies:

http://cheeseshop.python.org/pypi/simplejson

Download the latest python-oembed library from:

git://github.com/abarmat/python-oembed.git

Untar the source distribution and run:

python setup.py build

python setup.py install

Testing

With setuptools installed:

$ python setup.py test

Without setuptools installed:

$ python oembed_test.py

Using

To create an instance of the oEmbed consumer:

import oembed

consumer = oembed.OEmbedConsumer()

To add a provider endpoint to this consumer:

  • The first parameter is the URL of the endpoint published by the provider.
  • The second parameter is the URL schema to use with this endpoint.

endpoint = oembed.OEmbedEndpoint('http://www.flickr.com/services/oembed', ['http://*.flickr.com/*'])
consumer.addEndpoint(endpoint)

To get the provider response for a URL:

response = consumer.embed('http://www.flickr.com/photos/wizardbt/2584979382/')

To print the response results (each field can be read as a python dict, None if empty):

print response['url']

import pprint
pprint.pprint(response.getData())

To read the full documentation:

$ pydoc oembed

Clone this wiki locally