Package: peekalink
Peekalink Python API wrapperAn API wrapper/client library for thePeekalinklink previewing
service.Table of ContentsGetting StartedAPIpeekalink.Clientpeekalink.LinkPreviewpeekalink.ContentTypepeekalink.ImageAssetpeekalink.YouTubeDetailspeekalink.TwitterDetailspeekalink.LinkErrorContributionLicenseGetting StartedInstall the package:pip install peekalinkInstantiate the client:frompeekalinkimportClientpeekalink=Client(api_key='your_api_key')Preview a link:preview=peekalink.preview('https://www.youtube.com/watch?v=2oeWbRRiN2I')print(preview.title)ifpreview.is_youtube():youtube_details=preview.youtube()print(youtube_details.duration)APIpeekalink.ClientRepresents a Peekalink API client instance.Methods__init__(api_key: str, base_url: str) -> ClientInstantiates a new API client instance with the givenapi_keyandbase_url.
If thebase_urlis not provided, it will default tohttps://api.peekalink.io.
Thebase_urlshould 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) -> LinkPreviewReturns preview information about a given link. If the response is non-200, it
will raise aLinkError.is_available(link: str) -> boolChecks whether a given link is available.peekalink.LinkPreviewRepresents details about a given link's preview.Attributesurl: 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 | NoneMethods@staticmethod from_json(json: dict)Factory method that turns a JSON dict into aLinkPreview.is_youtube() -> boolReturnsTrueif the details were included in the response and they contain
information about a YouTube video.is_twitter() -> boolReturnsTrueif the details were included in the response and they contain
information about a tweet.youtube() -> YouTubeDetails | NoneReturns aYouTubeDetailsobject if the link contains details to a YouTube
video, otherwiseNone.twitter() -> TwitterDetails | NoneReturns aTwitterDetailsobject if the link contains details to a tweet,
otherwiseNone.to_json_dict() -> dictReturns a JSON-compliant dictionary containing the data of the currentLinkPreviewinstance.peekalink.ContentTypeEnum-like class that represents the type of the content that's available on a
given link.MembersContentType.HTMLContentType.IMAGEContentType.VIDEOContentType.GIFpeekalink.ImageAssetRepresents an image asset, such as the favicon or the OG image of the link.Attributesurl: strwidth: intheight: intMethods@staticmethod from_json(json: dict) -> ImageAssetFactory method that turns a JSON dict into anImageAsset.to_json_dict() -> dictReturns a JSON-compliant dictionary containing the data of the currentImageAssetinstance.peekalink.YouTubeDetailsRepresents a set of details regarding the YouTube video a given link points to.Attributesvideo_id: strduration: floatview_count: intlike_count: intdislike_count: intcomment_count: intpublished_at: datetimeMethods@staticmethods from_json(json: dict) -> YouTubeDetailsFactory method that turns a JSON dict into aYouTubeDetails.to_json_dict() -> dictReturns a JSON-compliant dictionary containing the data of the currentYouTubeDetailsinstance.peekalink.TwitterDetailsRepresents a set of details regarding the tweet a given link points to.Attributesstatus_id: strretweet_count: intlikes_count: intpublished_at: datetimeMethods@staticmethods from_json(json: dict) -> TwitterDetailsFactory method that turns a JSON dict into aTwitterDetails.to_json_dict() -> dictReturns a JSON-compliant dictionary containing the data of the currentTwitterDetailsinstance.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.Attributescode: int- The HTTP status code. You can check against one of the built-in
error types that are included in theLinkErrorclass.MembersLinkError.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 = 413Contribution1. Clone the repositorygit clone git@github.com:jozsefsallai/peekalink.py.git
cd peekalink.py2. Create a virtual envpython -m venv .venv
source .venv/bin/activate3. Install the dependenciespip install -r requirements.txtOnce 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.LicenseMIT.