Skip to main content

embedly2

This is a fork of the unmaintained embedly-python library. It aims to keep the package installable and functional on new versions of Python.

The original README follows:

Python library for interacting with Embedly’s API. To get started sign up for a key at embed.ly/signup.

Install

Install with Pip:

pip install embedly2

This library supports Python 3.6 through 3.10.

Getting Started

This library is meant to be a dead simple way to interact with the Embedly API. There are only 2 main objects, the Embedly client and the Url response model. Here is a simple example and then we will go into the objects:

>>> from embedly import Embedly
>>> client = Embedly(:key)
>>> obj = client.oembed('http://instagram.com/p/BL7ti/')
>>> obj['type']
u'photo'
>>> obj['url']
u'http://images.ak.instagram.com/media/2011/01/24/cdd759a319184cb79793506607ff5746_7.jpg'

>>> obj = client.oembed('http://instagram.com/error/error/')
>>> obj['error']
True

Embedly Client

The Embedly client is a object that takes in a key and optional User Agent and timeout parameters then handles all the interactions and HTTP requests to Embedly. To initialize the object, you’ll need the key that you got when you signed up for Embedly.

>>> from embedly import Embedly
>>> client = Embedly('key')
>>> client2 = Embedly('key', 'Mozilla/5.0 (compatible; example-org;)')
>>> client3 = Embedly('key', 'Mozilla/5.0 (compatible; example-org;)', 30)
>>> client4 = Embedly('key', timeout=10, user_agent='Mozilla/5.0 (compatible; example-org;)')

The client object now has a bunch of different methods that you can use.

oembed

Corresponds to the oEmbed endpoint. Passes back an object that allows you to retrieve a title, thumbnail, description and the embed html:

>>> client.oembed('http://vimeo.com/18150336')
<embedly.models.Url at 0x10223d950>
extract

Corresponds to the Extract endpoint. Passes back an object that allows you to retrieve a title, description, content, html and a list of images.:

>>> client.extract('http://vimeo.com/18150336')
<embedly.models.Url at 0x10223d950>
preview

Preview is no longer available to new users and has been replaced by extract.

Corresponds to the Preview endpoint. Passes back a simple object that allows you to retrieve a title, description, content, html and a list of images.:

>>> client.preview('http://vimeo.com/18150336')
<embedly.models.Url at 0x10223d950>
objectify

Objectify is no longer available to new users and has been replaced by extract.

Corresponds to the Objectify endpoint. Passes back a simple object that allows you to retrieve pretty much everything that Embedly knows about a URL.:

>>> client.objectify('http://vimeo.com/18150336')
<embedly.models.Url at 0x10223d950>

The above functions all take the same arguements, a URL or a list of URLs and keyword arguments that correspond to Embedly’s query arguments. Here is an example:

>>> client.oembed(['http://vimeo.com/18150336',
  'http://www.youtube.com/watch?v=hD7ydlyhvKs'], maxwidth=500, words=20)

There are some supporting functions that allow you to limit URLs before sending them to Embedly. Embedly can return metadata for any URL, these just allow a developer to only pass a subset of Embedly providers. Note that URL shorteners like bit.ly or t.co are not supported through these regexes.

regex

If you would like to only send URLs that returns embed HTML via Embedly you can match the URL to the regex before making the call. The matching providers are listed at embed.ly/providers:

>>> url = 'http://vimeo.com/18150336'
>>> client.regex.match(url)
<_sre.SRE_Match at 0x1017ba718>

is_supported

This is a simplified version of regex:

>>> url = 'http://vimeo.com/18150336'
>>> client.is_supported(url)
True

Url Object

The Url object is basically a response dictionary returned from one of the Embedly API endpoints.

>>> response = client.oembed('http://vimeo.com/18150336', words=10)

Depending on the method you are using, the response will have different attributes. We will go through a few, but you should read the documentation to get the full list of data that is passed back.

>>> response['type']
u'video'
>>> response['title']
u'Wingsuit Basejumping - The Need 4 Speed: The Art of Flight'
>>> response['provider_name']
u'Vimeo'
>>> response['width']
1280

As you can see the Url object works like a dictionary, but it’s slightly enhanced. It will always have method and original_url attributes, which represent the Embedly request type and the URL requested.

>>> response.method
'oembed'
>>> response.original_url
'http://vimeo.com/18150336'

# useful because the response data itself may not have a URL
# (or it could have a redirected link, querystring params, etc)
>>> response['url']
...
KeyError: 'url'

For the Preview and Objectify endpoints the sub-objects can also be accessed in the same manner.

>>> obj = client.preview('http://vimeo.com/18150336', words=10)
>>> obj['object']['type']
u'video'
>>> obj['images'][0]['url']
u'http://b.vimeocdn.com/ts/117/311/117311910_1280.jpg'

Error Handling

If there was an error processing the request, the Url object will contain an error. For example if we use an invalid key, we will get a 401 response back

>>> client = Embedly('notakey')
>>> obj = client.preview('http://vimeo.com/18150336')
>>> obj['error']
True
>>> obj['error_code']
401

Changelog

Version 0.6.0 (May 25, 2022)

  • Declare support for Python 3.6 through 3.10; drop support for Python 2, 3.2, and 3.3.

  • Fix installation with recent versions of setuptools.

Metadata

Release files for embedly2 0.6.0

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

Source distribution (sdist)

Source distribution for embedly2 0.6.0
File Size Uploaded Provenance Actions
embedly2-0.6.0.tar.gz 10.9 kB Without provenance Details for embedly2-0.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 20.1 kB

Release files / embedly2-0.6.0.tar.gz

Download URL embedly2-0.6.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4d74396a1839dd85a16428907cbfb2aa0e499736b8e4a82f9df9c6733a54ff46
BLAKE2b-256 checksum
How to use checksums
e50ef401b723d9146cbea8151c51cdb5934984c5faf34933763c9a8aa76e375d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.11.0b1

Release files / embedly2-0.6.0-py3-none-any.whl

Download URL embedly2-0.6.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d09c8b7f833ba24f47cdf3336f2b023b311d58a0abf8113862b8e73811b1084
BLAKE2b-256 checksum
How to use checksums
5a24d6a932663a6d14e4b6eac6a231218642e648e6a9db370aaa14cf4fd10ab8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.11.0b1

Security for embedly2 0.6.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.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files No provenance

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