Registry / http-networking / linkpreview

linkpreview

JSON →
library0.12.1pypypi✓ verified 84d ago

Python library to extract link previews (title, description, image, etc.) from URLs. Version 0.12.1. No regular release cadence; final release was 2020.

pip install linkpreview
INSTALL
IMPORT
SIG · LINKPREVIEW
L
linkpreview
http-networkingpythonv0.12.1
Install
2.3s avg
Import
851ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.12.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.880s · 22.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.3s · import 0.822s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

link_preview
from linkpreview import link_preview
from linkpreview import get_preview
get_preview was renamed to link_preview in v0.10.0.
LinkPreview
from linkpreview import LinkPreview
Class-based API for advanced usage.

Get a link preview with title, description, and image. Use the functional API for simplicity.

from linkpreview import link_preview url = "https://example.com" preview = link_preview(url) print(preview.title) print(preview.description) print(preview.image) print(preview.force_title) print(preview.force_description) print(preview.force_image)
Debug
Known issues
breakingIn v0.10.0, the function `get_preview` was renamed to `link_preview`. Code using `get_preview` will raise AttributeError.
fix
Replace `get_preview(url)` with `link_preview(url)`.
affects: >=0.10.0
deprecatedThe `LinkPreview` class constructor changed: in older versions, you passed a URL directly; in v0.11+, you must pass a string and then call `fetch_and_extract()`.
fix
Use the functional API `link_preview(url)` for simplicity, or update class usage: `preview = LinkPreview(url); preview.fetch_and_extract()`.
affects: >=0.11.0
gotchaThe library does not set a User-Agent header by default. Some websites may block requests, returning empty or malformed previews.
fix
Pass a custom headers dictionary when using the class-based API: `LinkPreview(url, headers={'User-Agent': 'Mozilla/5.0'})` or use requests.Session.
affects: all
gotchaThe library does not handle non-HTTP/HTTPS schemes (e.g., ftp://, file://). Attempting to parse such URLs may raise an exception or fail silently.
fix
Validate the URL scheme before passing to linkpreview; skip unsupported schemes.
affects: all
Errors
Common errors & fixes
AttributeError: module 'linkpreview' has no attribute 'get_preview'
The function `get_preview` was renamed to `link_preview` in v0.10.0.
fix
Use `from linkpreview import link_preview` and call `link_preview(url)`.
linkpreview.exceptions.LinkPreviewException: No preview data found
The URL could not be fetched or the page did not contain any meta tags for preview (e.g., no Open Graph, Twitter cards, or schema.org). Also occurs if the request is blocked.
fix
Ensure the URL is accessible (set a User-Agent if needed), or handle the exception gracefully.
TypeError: __init__() got an unexpected keyword argument 'headers'
The `LinkPreview` class in older versions (<0.11) did not accept `headers` directly. The functional API `link_preview` also does not accept headers.
fix
Upgrade to the latest version (0.12.1). For the class-based API, use `LinkPreview(url, headers={'User-Agent': '...'})`. For the functional API, consider using requests.Session to set headers globally.
Upgrade
Version history
0.12.1latest on PyPI · released Aug 15, 2025
Audit
Dependencies
requestsrequiredFetching web pages
lxmlrequiredHTML parsing
beautifulsoup4requiredHTML parsing (used via lxml)
Agent activity
3 hits · last 30 days
node
2
Meta
1
Resources
linkpreview — pip install linkpreview · libregistry