opengraph_writer
About
This library was created to both manage writing OpenGraph data, and perform lightweight verifications for offline debugging.
This library does the following:
- CREATE an object to stash OGP data
- VALIDATE the data, offering debug information on the object
- RENDER the object as html, and optionally include debug data on incorrect elements
Each OpenGraphItem represents one object. A property can have multiple
values, such as several images for the same page.
Most of the validation routines were derived from regexing the https://ogp.me
site into a Python dict, and researching what they are supposed to do.
The validation routes themselves are super trivial.
At the time of initially writing this library, and several checks ever since, the
specification on the https://ogp.me seems out of date.
In practice, Facebook's "premier" partners seem to all be using URLs which point to certain data , however there aren't any guidelines for this within the public OGP spec.
An example would be on the Spotify integration: when looking at a SONG, the
ARTIST and ALBUM refer to URLs which contain the relevant data.
Documentation
The Python file contains extensive inline documentation.
Multiple images
Use append=True to add another value to the same property. Each image is
validated individually, and the rendered tags keep the order in which the
images were added.
from opengraph_writer import OpenGraphItem
item = OpenGraphItem(
[
("og:title", "Example page"),
("og:type", "website"),
("og:url", "https://example.com/page"),
("og:image", "https://example.com/cover.jpg"),
]
)
item.set("og:image", "https://example.com/detail.jpg", append=True)
if item.validate():
print(item.as_html())
Contributions Welcome!
The test matrix covers CPython 3.6 through 3.15. Run the tests for your
active Python interpreter with tox -e py. The run writes its HTML coverage
report to htmlcov/index.html.
Framework Support: Pyramid
This package offers an includeme for Pyramid to set up an opengraph_item
as a @reify request method.
Simply update your application:
config.include("opengraph_writer.pyramid_helpers")
And your Request objects will be extended as such:
request.opengraph_item
Metadata
Release files for opengraph-writer 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opengraph_writer-1.0.0.tar.gz | 15.0 kB | Without provenance | Details for opengraph_writer-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opengraph_writer-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for opengraph_writer-1.0.0-py3-none-any.whl |
Total release size: 25.7 kB
Release files / opengraph_writer-1.0.0.tar.gz
| Download URL | opengraph_writer-1.0.0.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64ed0367bf8400bc6adcab0cd3af0b38a2377f4211682aca47f313aa75615a34
|
|
BLAKE2b-256 checksum How to use checksums |
b7969505e69b49834789066a4af2982dbcb1973c0fca9aa1e9cf8319e0f04ad4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / opengraph_writer-1.0.0-py3-none-any.whl
| Download URL | opengraph_writer-1.0.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a4980808931789f2bc124a515e1f6f505a78973fed604d2ff6b0ec16e5e6932
|
|
BLAKE2b-256 checksum How to use checksums |
4cce1bcefbdcdb7abb9cfc03cb404f016ceb8dab1ea46b1837054b56961f21ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Security for opengraph-writer 1.0.0
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.