実践「OSS≒盆栽」

oEmbedPyを使って、ドキュメントに○○○を埋め込もう

author:

Kazuya Takei / @attakei

date:

(not yet)

event:

(PyCon JP 2025)

hashtags:

#pyconjp2025

Overview

About this prepresentation

This is proposal of PyCon JP 2025 lightning talks. But it is defeated...

So, I don't talk about this anywhere yet.

Who am I ?

Kazuya Takei

  • attakei (X, GitHub, etc)

  • OSS Writer

    • Sphinx extensions

    • Client library

著者近影

I talked at Day 1

https://slides.attakei.net/pyconjp-2025/

oEmbed

What is oEmbed ?

https://oembed.com/

oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.

Many providers!

https://oembed.com/providers.json

Bluesky, CodePen, Dailymotion, Docswell, Facebook, Gyazo, Instagram, SlideShare, SpeakerDeck, YouTube, X, and more

Convenience

I can get embed HTML by API request.

Example: Using PyCon JP TV

https://www.youtube.com/watch?v=DnIi4qm_p7w

Convenience

By manual

  1. Open in browser https://www.youtube.com/watch?v=DnIi4qm_p7w .

  2. Click "share".

  3. Click "embed".

Convenience

By oEmbed

  1. Call https://www.youtube.com/oembed?url={URL}

$ uvx --from=httpie http \
    https://www.youtube.com/oembed \
    url=='https://www.youtube.com/watch?v=DnIi4qm_p7w' | jq -r '.html'

<iframe
    width="200"
    height="113"
    src="https://www.youtube.com/embed/DnIi4qm_p7w?feature=oembed"
    frameborder="0"
    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
    referrerpolicy="strict-origin-when-cross-origin"
    allowfullscreen
    title="PyCon JP TV #56: PyCon JP 2025の楽しみ方">
</iframe>

oEmbedPy

"Morden" oEmbed Python client

Usage

# /// script
# dependencies = [
#   "oembedpy",
# ]
# ///
from oembedpy.application import Oembed

oembed = Oembed()
oembed.init()
content = oembed.fetch("https://www.youtube.com/watch?v=DnIi4qm_p7w")
print(content.html)

Usage

uvx --from='oembedpy[cli]' oembed.py https://www.youtube.com/watch?v=DnIi4qm_p7w
Installed 15 packages in 172ms
type:             video
version:          1.0
html:             <iframe width="200" height="113" src="https://www.youtube.com/embed/DnIi4qm_p7w?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen title="PyCon JP TV #56: PyCon JP 2025の楽しみ方"></iframe>
width:            200
height:           113
title:            PyCon JP TV #56: PyCon JP 2025の楽しみ方
author_name:      PyCon JP
author_url:       https://www.youtube.com/@PyConJP
provider_name:    YouTube
provider_url:     https://www.youtube.com/
cache_age:        None
thumbnail_url:    https://i.ytimg.com/vi/DnIi4qm_p7w/hqdefault.jpg
thumbnail_width:  480
thumbnail_height: 360

Integration for document

Sphinx integration

conf.py
extensions = [
    "oembedpy.adapters.sphinx",
]

Integration for document

Sphinx integration

.. oembed:: https://www.youtube.com/watch?v=DnIi4qm_p7w
    :maxwidth: 960
    :maxheight: 640

Integration for document

Sphinx integration

.. oembed:: https://x.com/pyconjapan/status/1971471046692807040

Integration for document

Sphinx integration

.. oembed:: https://bsky.app/profile/attakei.dev/post/3lzmykxlsmc2s

#pyhack による教育の賜物 ※ラガー、コーヒー味のエール、ヴァイツェン #青空ごはん部

kAZUYA kAKEI (@attakei.dev) 2025-09-25T03:19:08.199Z

Integration for document

Q: I don't use Sphinx!!!

A: OK, do you use MkDocs?

Integration for document

MkDocs Integration

config.yaml
plugins:
  # - oembedpy
  - oembedpy:
    fallback_type: true

Integration for document

MkDocs Integration

```oembed
https://bsky.app/profile/attakei.dev/post/3lzmykxlsmc2s
```

#pyhack による教育の賜物 ※ラガー、コーヒー味のエール、ヴァイツェン #青空ごはん部

kAZUYA kAKEI (@attakei.dev) 2025-09-25T03:19:08.199Z

Why did I make it ?

There are already python implementations

../_images/implements.png

pyoembed

  • Last update is 8 years ago

  • Classifier is Python 2 only!!

uchu-neko-nya

pyembed

  • Last update is 5 years ago

  • Classifier is Python 2 and Python 3.3!!

uchu-neko-nya uchu-neko-nya

python-oembed

  • Last update is 9 years ago

  • Classifier is Python 2.5, 2.6 and 3.4!!

uchu-neko-nya uchu-neko-nya uchu-neko-nya

scream-nya

Any libraries already stopped maintenance!!

What do you do if there is not lib matched for you ?

We can make it !!

Thank you

attakei/oEmbedPy