Skip to main content

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']

Metadata

Release files for pyzu 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyzu 0.1
File Size Uploaded Provenance Actions
pyzu-0.1.tar.gz 2.5 kB Without provenance Details for pyzu-0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyzu 0.1
File Interpreter ABI Platform Actions
pyzu-0.1-py3-none-any.whl Python 3 none any Details for pyzu-0.1-py3-none-any.whl

Total release size: 4.7 kB

Release files / pyzu-0.1.tar.gz

Download URL pyzu-0.1.tar.gz
Size 2.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c86de9eb9145a6e7c84044f4d7c4fbcecb4ef25b296e4070fc5961ef362b31cb
BLAKE2b-256 checksum
How to use checksums
e0c7ae5d0959f9ef55449b67f03816023f94296af768a06887de7876480eda74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.9 CPython/3.6.5

Release files / pyzu-0.1-py3-none-any.whl

Download URL pyzu-0.1-py3-none-any.whl
Size 2.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39708025a26782c7a5d75c7a2aab728aedc4c59107732f055ca642c24b0ba468
BLAKE2b-256 checksum
How to use checksums
5df0c0a22ec6f177e1257235883b930bca7c9bcec1bb404868125ae33d41de88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.9 CPython/3.6.5

Security for pyzu 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page