A Peekalink API wrapper for Python
Project description
Peekalink Python API wrapper
An API wrapper/client library for the Peekalink link previewing service.
Table of Contents
Getting Started
Install the package:
pip install peekalink
Instantiate the client:
from peekalink import Client
peekalink = Client(api_key='your_api_key')
Preview a link:
preview = peekalink.preview('https://www.youtube.com/watch?v=2oeWbRRiN2I')
print(preview.title)
if preview.is_youtube():
youtube_details = preview.youtube()
print(youtube_details.duration)
API
peekalink.Client
Represents a Peekalink API client instance.
Methods
__init__(api_key: str, base_url: str) -> Client
Instantiates a new API client instance with the given api_key and base_url.
If the base_url is not provided, it will default to https://api.peekalink.io.
The base_url should NOT have a trailing slash.
set_base_url(base_url: str)
Sets the client's base URL. It should NOT have a trailing slash.
set_api_key(api_key: str)
Sets the client's API key.
preview(link: str) -> LinkPreview
Returns preview information about a given link. If the response is non-200, it
will raise a LinkError.
is_available(link: str) -> bool
Checks whether a given link is available.
peekalink.LinkPreview
Represents details about a given link's preview.
Attributes
url: strdomain: strlast_updated: datetimenext_update: datetimecontent_type: ContentTypemime_type: strsize: int | Noneredirected: boolredirection_url: str | Noneredirection_count: int | Noneredirection_trail: list[str] | Nonetitle: str | Nonedescription: str | Nonename: strtrackers_detected: boolicon: ImageAsset | Noneimage: ImageAsset | None
Methods
@staticmethod from_json(json: dict)
Factory method that turns a JSON dict into a LinkPreview.
is_youtube() -> bool
Returns True if the details were included in the response and they contain
information about a YouTube video.
is_twitter() -> bool
Returns True if the details were included in the response and they contain
information about a tweet.
youtube() -> YouTubeDetails | None
Returns a YouTubeDetails object if the link contains details to a YouTube
video, otherwise None.
twitter() -> TwitterDetails | None
Returns a TwitterDetails object if the link contains details to a tweet,
otherwise None.
to_json_dict() -> dict
Returns a JSON-compliant dictionary containing the data of the current
LinkPreview instance.
peekalink.ContentType
Enum-like class that represents the type of the content that's available on a given link.
Members
ContentType.HTMLContentType.IMAGEContentType.VIDEOContentType.GIF
peekalink.ImageAsset
Represents an image asset, such as the favicon or the OG image of the link.
Attributes
url: strwidth: intheight: int
Methods
@staticmethod from_json(json: dict) -> ImageAsset
Factory method that turns a JSON dict into an ImageAsset.
to_json_dict() -> dict
Returns a JSON-compliant dictionary containing the data of the current
ImageAsset instance.
peekalink.YouTubeDetails
Represents a set of details regarding the YouTube video a given link points to.
Attributes
video_id: strduration: floatview_count: intlike_count: intdislike_count: intcomment_count: intpublished_at: datetime
Methods
@staticmethods from_json(json: dict) -> YouTubeDetails
Factory method that turns a JSON dict into a YouTubeDetails.
to_json_dict() -> dict
Returns a JSON-compliant dictionary containing the data of the current
YouTubeDetails instance.
peekalink.TwitterDetails
Represents a set of details regarding the tweet a given link points to.
Attributes
status_id: strretweet_count: intlikes_count: intpublished_at: datetime
Methods
@staticmethods from_json(json: dict) -> TwitterDetails
Factory method that turns a JSON dict into a TwitterDetails.
to_json_dict() -> dict
Returns a JSON-compliant dictionary containing the data of the current
TwitterDetails instance.
peekalink.LinkError`
An exception that can be raised by the Link Preview service, to better identify why it was not possible to retrieve the details of a link.
Attributes
code: int- The HTTP status code. You can check against one of the built-in error types that are included in theLinkErrorclass.
Members
LinkError.LINK_MAX_REDIRECTS = 400LinkError.LINK_IS_PRIVATE = 403LinkError.LINK_DOES_NOT_EXIST = 404LinkError.LINK_TIMED_OUT = 408LinkError.LINK_EMPTY = 409LinkError.LINK_PREVIEW_ERROR = 409LinkError.LINK_UNREACHABLE = 409LinkError.LINK_CONTENT_TOO_LARGE = 413
Contribution
1. Clone the repository
git clone git@github.com:jozsefsallai/peekalink.py.git
cd peekalink.py
2. Create a virtual env
python -m venv .venv
source .venv/bin/activate
3. Install the dependencies
pip install -r requirements.txt
Once you make your changes, please make sure the unit tests are passing:
python -m unittest discover -s peekalink/tests -p 'test_*.py'
If you add a feature, make sure to also include an appropriate unit test.
License
MIT.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file peekalink-1.0.1.tar.gz.
File metadata
- Download URL: peekalink-1.0.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ab8b695c2502630b498244bc2bd6676d8289c81159b8e0764ef8acb0c2fc77b
|
|
| MD5 |
f6c5f100b12d036c8d6d90540dca22df
|
|
| BLAKE2b-256 |
4d09652cd1262e4d6d16c47b3d1e88e0f04d8ac715eff66b01681df950e279bc
|
File details
Details for the file peekalink-1.0.1-py3-none-any.whl.
File metadata
- Download URL: peekalink-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1191a6571b1fd1091166b6e6a76f0b17a42946668bb4a039638f00ea88a7f104
|
|
| MD5 |
51b84b8470ff612274e4ce6ca7eb63ee
|
|
| BLAKE2b-256 |
bc7c43c00358aba0baffaf9bdcb223a20073e81c9359369c66eef2c493d7bfeb
|