Skip to main content

Library to work with Open Graph metadata

Project description

https://coveralls.io/repos/github/chason/pyzu/badge.svg?branch=master https://travis-ci.org/chason/pyzu.svg?branch=master https://badge.fury.io/py/pyzu.svg

A Python class for retrieving Open Graph metadata from a website.

Overview

There’s a fair number of Open Graph metadata libraries for Python, but all of the currently active ones use an HTML parser like BeautifulSoup to extract the metadata. There’s nothing wrong with that, and it comes with some advantages but I wanted one that parses the webpage as RDFa, and so here we are.

This library extracts the Open Graph metadata and makes it available via the object’s properties. Most of the other libraries I’ve encountered that do this take a website’s URI and download the data there but this library takes the text of the website as the data instead. This was done because I’ve found that various websites like to hide their OGM data behind user agents so this allows you to get the data however you need to. It is also much easier to test.

See the TODO.rst file for information about features that I will be adding to this library.

Basic Usage

You can get the website source any way you like but in these examples I will be using Requests.

First initialize the object with the data from Requests:

import requests
from pyzu import OGP

r = requests.get('http://ogp.me/')
ogp_me = OGP(r.text)

After this we can check the validity of the data (essentially does it contain the four required attributes as specified by the OGP spec [title, type, image, and url]:

>>> ogp_me.is_valid
True

and finally we can look at the properties individually or see all the properties that we were able to extract from the page:

>>> ogp_me.title
'Open Graph protocol'
>>> ogp_me.properties
['description', 'url', 'image:height', 'image:alt', 'type', 'image', 'image:width', 'title', 'image:type']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyzu-0.1.4.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

pyzu-0.1.4-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file pyzu-0.1.4.tar.gz.

File metadata

  • Download URL: pyzu-0.1.4.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for pyzu-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2da09e1f62f213a5e7e1566b403c4db25280b947b37182df810fa9b19905d041
MD5 744251cc7f6e8eb641caba8832da6dda
BLAKE2b-256 38ae07d4b96979f5b9cd8e94a284b2f8c138be5033ce71f63bf4d9e4c31b2308

See more details on using hashes here.

File details

Details for the file pyzu-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: pyzu-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for pyzu-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 04cab8d7031053a853bc9f84aaa756c6c4d35d00d45e6adeba908e82d89ffe5b
MD5 962969f80f3046dacdfff4dff40feaf7
BLAKE2b-256 6923b1b8e219642b1d276e5804376e9c2c961c704e7b782001f90d8dbc423731

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page