A Python client for opengraph.io, a website scraper to grab OpenGraph tags or supplement them when they don't exist.
Project description
opengraph-io-python ( Python Client 1.0.5 )
OpenGraph.io client library for Python. Given a URL, the client will make a HTTP request to OpenGraph.io which will scrape the site for OpenGraph tags. If tags exist the tags will be returned to you.
Oftentimes the appropriate tags will not exist and this is where OpenGraph.io shines. It will infer what the OpenGraph tags probably would be and return them to you as hybridGraph
.
The hybridGraph
results will always default to any OpenGraph tags that were found on the page. If only some tags were found, or none were, the missing tags will be inferred from the content on the page.
For most uses, the OpenGraph.io API is free. To get a free forever key, sign up at OpenGraph.io.
If you end up having very heavy usage, the vast majority of projects will be totally covered using one of our inexpensive plans. Dedicated plans are also available upon request.
NOTE Our free plan previously required no appId
but was unfortunately abused. The free plan still exists and is free forever, you will just have to create an account on OpenGraph.io.
Installation
Installation is simple with pip:
pip install opengraphio
Usage
Initialization
To use the client, you must first initialize an instance of the class with your app_id
. First, from opengraphio import OpenGraphIO
and then initialize an instance of OpenGraphIO, passing it an options dict containing the required app_id
key as a string:
from opengraphio import OpenGraphIO
opengraph = OpenGraphIO({ 'app_id': 'your_app_id_here!' })
Setting Default Options at Initialization
You may also initialize your OpenGraphIO instance with default options. For example, if you would always like to perform a full_render
, you can pass that parameter in the options dict at initialization along with your app_id
:
from opengraphio import OpenGraphIO
opengraph = OpenGraphIO({ 'app_id': 'your_app_id_here!', 'full_render': True })
This OpenGraphIO instance will default to performing a full_render
whenever you request OpenGraph tags, unless you later decide to override this option in your request (see below!).
If you do not pass any options besides the required app_id
, the defaults will be used:
'cache_ok': True
'full_render': False
'version': '1.1'
Requesting OpenGraph Tags
You can request OpenGraph tags by calling get_site_info
on your OpenGraphIO instance and passing it your target site as a string.
opengraph.get_site_info('https://github.com')
This will return a dict containing the response. See https://www.opengraph.io/documentation/ for an example response.
Requesting OpenGraph Tags with Overridden Options
get_site_info
takes an optional second argument, consisting of an options
dict, similar to the options
dict used at initialization. The options supplied here will override the default options set at initialization for this request. For example, let's say you initialize your OpenGraphIO
instance like this:
from opengraphio import OpenGraphIO
opengraph = OpenGraphIO({ 'app_id': 'your_app_id_here!' })
You can use this instance to get a response using the full_render
option and disabling the cache_ok
option like so:
opengraph.get_site_info('https://github.com', { 'full_render': True, 'cache_ok': False })
Support
Please feel free to reach out any time with questions or suggestions by adding to the issues for this repo, or if you'd prefer, head over to https://www.opengraph.io/support/ and drop us a line!
License
MIT License
Copyright (c) William Dana
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
Built Distribution
File details
Details for the file opengraphio-1.0.5.tar.gz
.
File metadata
- Download URL: opengraphio-1.0.5.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ede6643a49d61dbacc03845008ed2a15b511df00e5d9e8b51102f3b8f1ff9f2 |
|
MD5 | efb29f80081c128b8b7e84008ab1c3a8 |
|
BLAKE2b-256 | 95992c348ae2ce690c956361193ecc8ecc8ee170d56b660ef6cf2052656e6834 |
File details
Details for the file opengraphio-1.0.5-py3-none-any.whl
.
File metadata
- Download URL: opengraphio-1.0.5-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce9c2177327b2d218372a5c9ddb04b23c40d911ed20c00ba9bd61dab145e52f5 |
|
MD5 | 59b34cda3315c01c98f9a07c67a778c5 |
|
BLAKE2b-256 | 32fcc207b83784874a31c790ebbf24ce78ff71cbf70f69e9402e6948d6bd8e27 |