Skip to main content

Python Markdown oEmbed

Markdown extension to allow media embedding using the oEmbed standard.

Requirements

  • Python >= 3.12
  • Markdown >= 3.2

Installation

pip install python-markdown-oembed-extension

Or with uv:

uv add python-markdown-oembed-extension

Usage

import markdown
md = markdown.Markdown(extensions=['oembed'])
md.convert('![video](http://www.youtube.com/watch?v=zqnh_YJBvOI)')

Output is wrapped in a <figure class="oembed"> element by default:

<figure class="oembed"><iframe width="459" height="344" ...></iframe></figure>

Configuration

Option Default Description
allowed_endpoints YouTube, Flickr, Vimeo, Slideshare List of oembed.OEmbedEndpoint objects
wrapper_class "oembed" CSS class(es) for the <figure> wrapper. Set to "" to disable wrapping

Example with custom configuration:

from mdx_oembed.endpoints import YOUTUBE, VIMEO

md = markdown.Markdown(
    extensions=['oembed'],
    extension_configs={
        'oembed': {
            'allowed_endpoints': [YOUTUBE, VIMEO],
            'wrapper_class': 'embed-responsive',
        }
    }
)

Security

oEmbed HTML responses are sanitized using nh3 to prevent XSS from compromised oEmbed providers. Only safe tags (iframe, video, audio, img, etc.) and attributes are allowed.

Links

License

A Public Domain work. Do as you wish.

Changelog

0.5.1

  • Fixed wrapper_class config being ignored — getConfig() was called with a hardcoded default that shadowed user-supplied extension_configs values

0.5.0

  • Breaking: requires Python >= 3.12
  • Replaced custom html.escape() for proper attribute escaping in photo <img> tags
  • HTTP status validation: non-2xx oEmbed API responses now raise OEmbedError
  • addEndpoint() is deprecated in favour of add_endpoint() (emits DeprecationWarning)
  • Added from __future__ import annotations to all modules
  • Added py.typed marker (PEP 561) for downstream type-checking support
  • Version is now sourced dynamically from mdx_oembed/version.py via hatch
  • Added ruff and pyright configuration in pyproject.toml
  • Tests converted to pure pytest (dropped unittest.TestCase)
  • New tests for HTTP status handling, deprecation warnings, and HTML escaping
  • Removed legacy src/ package tree

0.4.0

  • Breaking: requires Python >= 3.9 and Markdown >= 3.2
  • Migrated from deprecated Pattern to InlineProcessor (Markdown 3.2+ compatible)
  • Added HTML sanitization of oEmbed responses (XSS protection via nh3)
  • Added support for oEmbed photo type responses
  • Improved image URL detection (case-insensitive, handles query strings)
  • All oEmbed API endpoints now use HTTPS
  • Slideshare URL patterns now accept both HTTP and HTTPS
  • Configurable <figure> wrapper class (previously hardcoded Bootstrap classes)
  • Migrated to pyproject.toml with hatchling build backend
  • Tests modernized: uses pytest + unittest.mock, all HTTP calls mocked
  • Centralized version management in mdx_oembed/version.py

0.2.1

  • add Slideshare endpoint (thanks to anantshri)

0.2.0

  • backwards incompatible changes
    • allows arbitrary endpoints (commit)
    • works with modern Markdown (>=2.6)
    • dropped support for python 2.6
  • added support python 3.x

Release files for python-markdown-oembed-extension 0.5.1

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

Source distribution (sdist)

Source distribution for python-markdown-oembed-extension 0.5.1
File Size Uploaded
python_markdown_oembed_extension-0.5.1.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-markdown-oembed-extension 0.5.1
File Interpreter ABI Platform
python_markdown_oembed_extension-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / python_markdown_oembed_extension-0.5.1.tar.gz

Download URL python_markdown_oembed_extension-0.5.1.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ca845183ca701b0aca25b863153aad62e7661eba403de8bac0384a9a9b7279ea
BLAKE2b-256 checksum
How to use checksums
ddc1e1d18baac3685e8ac45da10cd6b7903c9e4a8759f67bcca216c7cae8a922
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / python_markdown_oembed_extension-0.5.1-py3-none-any.whl

Download URL python_markdown_oembed_extension-0.5.1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e2280ee5c234579aae3d3ae0dcd1e9bbae91b2954d464a1ee609f757f8bf4fce
BLAKE2b-256 checksum
How to use checksums
9fadfb0133cb41d9e0a3afda104d1dca663265be07cb8175bec4a5cbfe36a2ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.0.0

2 release files

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