colab-slides 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ahmad Mustapha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: colab-slides
3
+ Version: 0.1.0
4
+ Summary: Render PowerPoint and Google Slides decks inside Google Colab or Jupyter from a link
5
+ Author: Ahmad Mustapha
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/AhmadM-DL/colab-slides
8
+ Project-URL: Repository, https://github.com/AhmadM-DL/colab-slides
9
+ Project-URL: Issues, https://github.com/AhmadM-DL/colab-slides/issues
10
+ Keywords: colab,google-colab,jupyter,ipython,magic,powerpoint,pptx,google-slides,slides,presentation,slideshow
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Framework :: IPython
13
+ Classifier: Framework :: Jupyter
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Topic :: Multimedia :: Graphics :: Presentation
20
+ Classifier: Topic :: Education
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: ipython
25
+ Requires-Dist: requests
26
+ Dynamic: license-file
27
+
28
+ # colab-slides
29
+
30
+ [![PyPI](https://img.shields.io/pypi/v/colab-slides)](https://pypi.org/project/colab-slides/)
31
+ [![Python](https://img.shields.io/pypi/pyversions/colab-slides)](https://pypi.org/project/colab-slides/)
32
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/AhmadM-DL/colab-slides/blob/main/LICENSE)
33
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/AhmadM-DL/colab-slides/blob/main/demo.ipynb)
34
+
35
+ Show PowerPoint or Google Slides decks inside a Google Colab or Jupyter notebook by pasting a link.
36
+
37
+ ![colab-slides rendering a deck in a notebook cell](https://raw.githubusercontent.com/AhmadM-DL/colab-slides/main/docs/notebook.png)
38
+
39
+ ## Install (in Colab)
40
+
41
+ ```python
42
+ !pip install -q colab-slides
43
+ ```
44
+
45
+ ## Use
46
+
47
+ ```python
48
+ %load_ext colab_slides
49
+
50
+ %slides https://docs.google.com/presentation/d/<ID>/edit # Google Slides
51
+ %slides https://drive.google.com/file/d/<ID>/view # .pptx in Drive
52
+ %slides https://example.com/talk.pptx # direct link
53
+ %slides /content/drive/MyDrive/deck.pptx # mounted Drive / uploaded file
54
+ %slides https://example.com/talk.pptx --local --width 1000 # force in-notebook rendering
55
+ ```
56
+
57
+ Or from Python:
58
+
59
+ ```python
60
+ import colab_slides
61
+ colab_slides.show(url, mode="auto") # "auto" | "embed" | "local"
62
+ ```
63
+
64
+ ## Modes
65
+
66
+ | Mode | How it works | Good for |
67
+ |------|--------------|----------|
68
+ | `embed` | Uses the Google Slides embed viewer or Microsoft Office Online in an iframe. Nothing to install. Keeps animations and transitions. | Public links |
69
+ | `local` | Downloads the file, converts it with LibreOffice → PDF → PNG inside the Colab VM, and shows a built-in slideshow. | Private files (mounted Drive), uploaded files, links the online viewers can't open |
70
+ | `auto` (default) | Uses `embed` when the link can be embedded, otherwise `local` | — |
71
+
72
+ The first `local` render installs LibreOffice in the Colab VM (about 1–2 minutes, once per runtime).
73
+
74
+ **Slideshow controls (local mode):** ← → / Space / PageUp/PageDown, Home/End, `f` for fullscreen, click the left or right part of a slide, or click a thumbnail.
75
+
76
+ ### Screenshots
77
+
78
+ | Slideshow with thumbnails | Fullscreen (press `f`) |
79
+ |---|---|
80
+ | ![Slideshow with thumbnails](https://raw.githubusercontent.com/AhmadM-DL/colab-slides/main/docs/player.png) | ![Fullscreen view](https://raw.githubusercontent.com/AhmadM-DL/colab-slides/main/docs/fullscreen.png) |
81
+
82
+ ## Supported links
83
+
84
+ - Google Slides (`/edit` links and "Publish to web" links)
85
+ - Google Drive file links (shared as "Anyone with the link")
86
+ - Dropbox share links
87
+ - OneDrive / SharePoint share links (embed only)
88
+ - Any direct URL to a `.pptx`, `.ppt`, `.odp` or `.pdf`
89
+ - Local paths
90
+
91
+ ## Limits
92
+
93
+ - `local` mode shows static images: animations, transitions, embedded video and audio aren't kept.
94
+ - Fonts that aren't installed in the VM are replaced with similar ones, so layouts can shift slightly.
95
+ - Office Online only opens files that are publicly downloadable over HTTPS.
96
+
97
+ ## License
98
+
99
+ MIT
@@ -0,0 +1,72 @@
1
+ # colab-slides
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/colab-slides)](https://pypi.org/project/colab-slides/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/colab-slides)](https://pypi.org/project/colab-slides/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/AhmadM-DL/colab-slides/blob/main/LICENSE)
6
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/AhmadM-DL/colab-slides/blob/main/demo.ipynb)
7
+
8
+ Show PowerPoint or Google Slides decks inside a Google Colab or Jupyter notebook by pasting a link.
9
+
10
+ ![colab-slides rendering a deck in a notebook cell](https://raw.githubusercontent.com/AhmadM-DL/colab-slides/main/docs/notebook.png)
11
+
12
+ ## Install (in Colab)
13
+
14
+ ```python
15
+ !pip install -q colab-slides
16
+ ```
17
+
18
+ ## Use
19
+
20
+ ```python
21
+ %load_ext colab_slides
22
+
23
+ %slides https://docs.google.com/presentation/d/<ID>/edit # Google Slides
24
+ %slides https://drive.google.com/file/d/<ID>/view # .pptx in Drive
25
+ %slides https://example.com/talk.pptx # direct link
26
+ %slides /content/drive/MyDrive/deck.pptx # mounted Drive / uploaded file
27
+ %slides https://example.com/talk.pptx --local --width 1000 # force in-notebook rendering
28
+ ```
29
+
30
+ Or from Python:
31
+
32
+ ```python
33
+ import colab_slides
34
+ colab_slides.show(url, mode="auto") # "auto" | "embed" | "local"
35
+ ```
36
+
37
+ ## Modes
38
+
39
+ | Mode | How it works | Good for |
40
+ |------|--------------|----------|
41
+ | `embed` | Uses the Google Slides embed viewer or Microsoft Office Online in an iframe. Nothing to install. Keeps animations and transitions. | Public links |
42
+ | `local` | Downloads the file, converts it with LibreOffice → PDF → PNG inside the Colab VM, and shows a built-in slideshow. | Private files (mounted Drive), uploaded files, links the online viewers can't open |
43
+ | `auto` (default) | Uses `embed` when the link can be embedded, otherwise `local` | — |
44
+
45
+ The first `local` render installs LibreOffice in the Colab VM (about 1–2 minutes, once per runtime).
46
+
47
+ **Slideshow controls (local mode):** ← → / Space / PageUp/PageDown, Home/End, `f` for fullscreen, click the left or right part of a slide, or click a thumbnail.
48
+
49
+ ### Screenshots
50
+
51
+ | Slideshow with thumbnails | Fullscreen (press `f`) |
52
+ |---|---|
53
+ | ![Slideshow with thumbnails](https://raw.githubusercontent.com/AhmadM-DL/colab-slides/main/docs/player.png) | ![Fullscreen view](https://raw.githubusercontent.com/AhmadM-DL/colab-slides/main/docs/fullscreen.png) |
54
+
55
+ ## Supported links
56
+
57
+ - Google Slides (`/edit` links and "Publish to web" links)
58
+ - Google Drive file links (shared as "Anyone with the link")
59
+ - Dropbox share links
60
+ - OneDrive / SharePoint share links (embed only)
61
+ - Any direct URL to a `.pptx`, `.ppt`, `.odp` or `.pdf`
62
+ - Local paths
63
+
64
+ ## Limits
65
+
66
+ - `local` mode shows static images: animations, transitions, embedded video and audio aren't kept.
67
+ - Fonts that aren't installed in the VM are replaced with similar ones, so layouts can shift slightly.
68
+ - Office Online only opens files that are publicly downloadable over HTTPS.
69
+
70
+ ## License
71
+
72
+ MIT
@@ -0,0 +1,19 @@
1
+ """colab_slides - show PowerPoint / Google Slides decks inside Colab.
2
+
3
+ import colab_slides
4
+ colab_slides.show("https://docs.google.com/presentation/d/<id>/edit")
5
+
6
+ or, with the magic:
7
+
8
+ %load_ext colab_slides
9
+ %slides https://example.com/deck.pptx --local
10
+ """
11
+ from .core import normalize_link, render_local, show, slide_images
12
+
13
+ __version__ = "0.1.0"
14
+ __all__ = ["show", "normalize_link", "render_local", "slide_images", "load_ipython_extension"]
15
+
16
+
17
+ def load_ipython_extension(ipython):
18
+ from .magics import SlidesMagics
19
+ ipython.register_magics(SlidesMagics)
@@ -0,0 +1,248 @@
1
+ """Render PowerPoint / Google Slides decks inside a Colab (or Jupyter) notebook.
2
+
3
+ Two rendering engines:
4
+ * "embed" - zero-install. Embeds the deck through an online viewer
5
+ (Google Slides embed or Microsoft Office Online). Needs a
6
+ publicly reachable link.
7
+ * "local" - downloads the .pptx, converts it with LibreOffice -> PDF -> PNG
8
+ inside the Colab VM and shows an interactive slideshow.
9
+ Works for private Drive files (after drive.mount) and local paths.
10
+ """
11
+ from __future__ import annotations
12
+
13
+ import base64
14
+ import html
15
+ import json
16
+ import os
17
+ import re
18
+ import shutil
19
+ import subprocess
20
+ import tempfile
21
+ import uuid
22
+ from pathlib import Path
23
+ from urllib.parse import parse_qs, quote, urlencode, urlparse, urlunparse
24
+
25
+ try:
26
+ from IPython.display import HTML, IFrame, display
27
+ except ImportError: # pragma: no cover
28
+ HTML = IFrame = display = None
29
+
30
+ __all__ = ["show", "normalize_link", "render_local", "slide_images"]
31
+
32
+ _GSLIDES_RE = re.compile(r"docs\.google\.com/presentation/d/(?:e/)?([\w-]+)")
33
+ _GDRIVE_RE = re.compile(r"drive\.google\.com/(?:file/d/|open\?id=|uc\?.*id=)([\w-]+)")
34
+
35
+
36
+ # --------------------------------------------------------------------------- #
37
+ # Link handling
38
+ # --------------------------------------------------------------------------- #
39
+ def normalize_link(url: str) -> dict:
40
+ """Classify a link and return the URLs each engine needs.
41
+
42
+ Returns dict with keys: kind, embed_url, download_url.
43
+ """
44
+ url = url.strip()
45
+ if not re.match(r"^https?://", url):
46
+ return {"kind": "path", "embed_url": None, "download_url": url}
47
+
48
+ m = _GSLIDES_RE.search(url)
49
+ if m:
50
+ fid = m.group(1)
51
+ if "/presentation/d/e/" in url: # "Publish to web" link
52
+ base = f"https://docs.google.com/presentation/d/e/{fid}"
53
+ return {"kind": "google_slides_published",
54
+ "embed_url": f"{base}/embed?start=false&loop=false",
55
+ "download_url": f"{base}/pub?output=pptx"}
56
+ return {"kind": "google_slides",
57
+ "embed_url": f"https://docs.google.com/presentation/d/{fid}/embed?start=false&loop=false",
58
+ "download_url": f"https://docs.google.com/presentation/d/{fid}/export/pptx"}
59
+
60
+ m = _GDRIVE_RE.search(url)
61
+ if m:
62
+ fid = m.group(1)
63
+ return {"kind": "google_drive",
64
+ "embed_url": f"https://drive.google.com/file/d/{fid}/preview",
65
+ "download_url": f"https://drive.google.com/uc?export=download&id={fid}"}
66
+
67
+ p = urlparse(url)
68
+ if "dropbox.com" in p.netloc:
69
+ q = parse_qs(p.query)
70
+ q["dl"] = ["1"]
71
+ dl = urlunparse(p._replace(query=urlencode(q, doseq=True)))
72
+ q["raw"] = ["1"]
73
+ q.pop("dl")
74
+ raw = urlunparse(p._replace(query=urlencode(q, doseq=True)))
75
+ return {"kind": "dropbox", "embed_url": _office_embed(raw), "download_url": dl}
76
+
77
+ if "1drv.ms" in p.netloc or "onedrive.live.com" in p.netloc or "sharepoint.com" in p.netloc:
78
+ # OneDrive/SharePoint share links already open in Office Online
79
+ embed = url if "embed" in url else url + ("&" if "?" in url else "?") + "action=embedview"
80
+ return {"kind": "onedrive", "embed_url": embed, "download_url": None}
81
+
82
+ # Any other direct link to a .pptx/.ppt/.odp file
83
+ return {"kind": "direct", "embed_url": _office_embed(url), "download_url": url}
84
+
85
+
86
+ def _office_embed(file_url: str) -> str:
87
+ return "https://view.officeapps.live.com/op/embed.aspx?src=" + quote(file_url, safe="")
88
+
89
+
90
+ # --------------------------------------------------------------------------- #
91
+ # Local rendering (LibreOffice)
92
+ # --------------------------------------------------------------------------- #
93
+ def _ensure_tools(auto_install: bool = True) -> None:
94
+ missing = [t for t in ("soffice", "pdftoppm") if not shutil.which(t)]
95
+ if not missing:
96
+ return
97
+ if not auto_install:
98
+ raise RuntimeError(f"Missing tools: {missing}. Install libreoffice-impress and poppler-utils.")
99
+ print("Installing LibreOffice + poppler (one-time, ~1-2 min on Colab)...")
100
+ subprocess.run("apt-get -qq update && apt-get -qq install -y libreoffice-impress poppler-utils "
101
+ "fonts-liberation fonts-dejavu > /dev/null", shell=True, check=True)
102
+
103
+
104
+ def _download(src: str, dest_dir: Path) -> Path:
105
+ if not re.match(r"^https?://", src):
106
+ path = Path(src).expanduser()
107
+ if not path.exists():
108
+ raise FileNotFoundError(path)
109
+ return path
110
+ import requests # available on Colab
111
+
112
+ sess = requests.Session()
113
+ r = sess.get(src, stream=True, timeout=60, allow_redirects=True)
114
+ # Google Drive large-file "virus scan" confirmation page
115
+ if "text/html" in r.headers.get("content-type", "") and "drive.google.com" in src:
116
+ m = re.search(r'name="confirm" value="([^"]+)"', r.text) or re.search(r"confirm=([\w-]+)", r.text)
117
+ uuid_m = re.search(r'name="uuid" value="([^"]+)"', r.text)
118
+ if m:
119
+ params = {"export": "download", "confirm": m.group(1),
120
+ "id": parse_qs(urlparse(src).query)["id"][0]}
121
+ if uuid_m:
122
+ params["uuid"] = uuid_m.group(1)
123
+ r = sess.get("https://drive.usercontent.google.com/download", params=params,
124
+ stream=True, timeout=60)
125
+ r.raise_for_status()
126
+ if "text/html" in r.headers.get("content-type", ""):
127
+ raise RuntimeError("The link returned a web page, not a file. Make sure it is shared "
128
+ "as 'Anyone with the link', or mount Drive and pass the file path.")
129
+ name = "deck"
130
+ cd = r.headers.get("content-disposition", "")
131
+ m = re.search(r'filename\*?=(?:UTF-8\'\')?"?([^";]+)', cd)
132
+ ext = Path(m.group(1)).suffix if m else Path(urlparse(src).path).suffix
133
+ path = dest_dir / (name + (ext if ext.lower() in {".ppt", ".pptx", ".odp", ".pdf", ".key"} else ".pptx"))
134
+ with open(path, "wb") as f:
135
+ for chunk in r.iter_content(1 << 16):
136
+ f.write(chunk)
137
+ return path
138
+
139
+
140
+ def slide_images(src: str, dpi: int = 110, auto_install: bool = True) -> list[bytes]:
141
+ """Return a list of PNG bytes, one per slide."""
142
+ _ensure_tools(auto_install)
143
+ with tempfile.TemporaryDirectory() as tmp:
144
+ tmp = Path(tmp)
145
+ deck = _download(src, tmp)
146
+ if deck.suffix.lower() == ".pdf":
147
+ pdf = deck
148
+ else:
149
+ subprocess.run(["soffice", "--headless", "--convert-to", "pdf", "--outdir", str(tmp), str(deck)],
150
+ check=True, capture_output=True, timeout=300,
151
+ env={**os.environ, "HOME": str(tmp)})
152
+ pdf = tmp / (deck.stem + ".pdf")
153
+ if not pdf.exists():
154
+ raise RuntimeError("LibreOffice conversion failed.")
155
+ subprocess.run(["pdftoppm", "-png", "-r", str(dpi), str(pdf), str(tmp / "s")],
156
+ check=True, capture_output=True, timeout=300)
157
+ files = sorted(tmp.glob("s-*.png"), key=lambda p: int(p.stem.split("-")[-1]))
158
+ return [p.read_bytes() for p in files]
159
+
160
+
161
+ _PLAYER = """
162
+ <div id="{id}" class="cs-wrap" tabindex="0">
163
+ <style>
164
+ #{id}{{font-family:system-ui,sans-serif;max-width:{width}px;outline:none;user-select:none}}
165
+ #{id} .cs-stage{{position:relative;background:#111;border-radius:8px;overflow:hidden}}
166
+ #{id} .cs-stage img{{width:100%;display:block}}
167
+ #{id}:fullscreen{{max-width:none;background:#000;display:flex;flex-direction:column;justify-content:center}}
168
+ #{id}:fullscreen .cs-stage img{{max-height:92vh;object-fit:contain}}
169
+ #{id} .cs-bar{{display:flex;gap:8px;align-items:center;justify-content:center;padding:8px 0;color:#888}}
170
+ #{id} button{{border:1px solid #888;background:transparent;color:inherit;border-radius:6px;padding:4px 12px;cursor:pointer;font-size:14px}}
171
+ #{id} button:hover{{background:rgba(127,127,127,.2)}}
172
+ #{id} .cs-thumbs{{display:flex;gap:6px;overflow-x:auto;padding-bottom:6px}}
173
+ #{id} .cs-thumbs img{{height:54px;border:2px solid transparent;border-radius:4px;cursor:pointer;opacity:.6}}
174
+ #{id} .cs-thumbs img.on{{border-color:#4a8cff;opacity:1}}
175
+ #{id}:fullscreen .cs-thumbs{{display:none}}
176
+ </style>
177
+ <div class="cs-stage"><img class="cs-main" alt="slide"></div>
178
+ <div class="cs-bar">
179
+ <button data-a="first">&#x23EE;</button><button data-a="prev">&#x25C0;</button>
180
+ <span class="cs-count"></span>
181
+ <button data-a="next">&#x25B6;</button><button data-a="last">&#x23ED;</button>
182
+ <button data-a="full">&#x26F6; Fullscreen</button>
183
+ </div>
184
+ <div class="cs-thumbs"></div>
185
+ <script>
186
+ (function(){{
187
+ const root=document.getElementById("{id}"), S={slides}; let i=0;
188
+ const main=root.querySelector(".cs-main"), cnt=root.querySelector(".cs-count"), th=root.querySelector(".cs-thumbs");
189
+ S.forEach((s,k)=>{{const t=document.createElement("img");t.src=s;t.onclick=()=>go(k);th.appendChild(t);}});
190
+ function go(k){{i=Math.max(0,Math.min(S.length-1,k));main.src=S[i];cnt.textContent=(i+1)+" / "+S.length;
191
+ [...th.children].forEach((t,n)=>t.classList.toggle("on",n===i));th.children[i].scrollIntoView({{block:"nearest",inline:"center"}});}}
192
+ const act={{first:()=>go(0),prev:()=>go(i-1),next:()=>go(i+1),last:()=>go(S.length-1),
193
+ full:()=>document.fullscreenElement?document.exitFullscreen():root.requestFullscreen()}};
194
+ root.querySelectorAll("button").forEach(b=>b.onclick=()=>{{act[b.dataset.a]();root.focus();}});
195
+ main.onclick=e=>{{const r=main.getBoundingClientRect();go(e.clientX-r.left<r.width/3?i-1:i+1);}};
196
+ root.addEventListener("keydown",e=>{{const m={{ArrowRight:"next",ArrowDown:"next"," ":"next",PageDown:"next",
197
+ ArrowLeft:"prev",ArrowUp:"prev",PageUp:"prev",Home:"first",End:"last",f:"full"}};
198
+ if(m[e.key]){{e.preventDefault();act[m[e.key]]();}}}});
199
+ go(0);
200
+ }})();
201
+ </script>
202
+ </div>
203
+ """
204
+
205
+
206
+ def render_local(src: str, width: int = 900, dpi: int = 110, auto_install: bool = True) -> "HTML":
207
+ imgs = slide_images(src, dpi=dpi, auto_install=auto_install)
208
+ if not imgs:
209
+ raise RuntimeError("No slides found.")
210
+ uris = ["data:image/png;base64," + base64.b64encode(b).decode() for b in imgs]
211
+ return HTML(_PLAYER.format(id="cs" + uuid.uuid4().hex[:8], width=width, slides=json.dumps(uris)))
212
+
213
+
214
+ def _render_embed(embed_url: str, width: int, height: int) -> "HTML":
215
+ u = html.escape(embed_url, quote=True)
216
+ return HTML(f'<iframe src="{u}" width="{width}" height="{height}" frameborder="0" '
217
+ f'allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" '
218
+ f'style="border-radius:8px;max-width:100%"></iframe>'
219
+ f'<div style="font:12px sans-serif;color:#888">Not loading? Try '
220
+ f'<code>show(url, mode="local")</code></div>')
221
+
222
+
223
+ # --------------------------------------------------------------------------- #
224
+ # Public entry point
225
+ # --------------------------------------------------------------------------- #
226
+ def show(url: str, mode: str = "auto", width: int = 900, height: int | None = None,
227
+ dpi: int = 110, auto_install: bool = True):
228
+ """Render a slide deck in the notebook output.
229
+
230
+ url : Google Slides / Drive / Dropbox / OneDrive / direct .pptx link, or a local path.
231
+ mode : "auto" (embed when possible, else local), "embed", or "local".
232
+ """
233
+ info = normalize_link(url)
234
+ height = height or int(width * 9 / 16) + 30
235
+ if mode == "auto":
236
+ mode = "embed" if info["embed_url"] else "local"
237
+ if mode == "embed":
238
+ if not info["embed_url"]:
239
+ raise ValueError("This link can't be embedded; use mode='local'.")
240
+ out = _render_embed(info["embed_url"], width, height)
241
+ elif mode == "local":
242
+ src = info["download_url"]
243
+ if not src:
244
+ raise ValueError("No downloadable URL for this link; share it as a direct download link.")
245
+ out = render_local(src, width=width, dpi=dpi, auto_install=auto_install)
246
+ else:
247
+ raise ValueError("mode must be 'auto', 'embed' or 'local'")
248
+ display(out)
@@ -0,0 +1,28 @@
1
+ import argparse
2
+ import shlex
3
+
4
+ from IPython.core.magic import Magics, line_magic, magics_class
5
+
6
+ from .core import show
7
+
8
+
9
+ @magics_class
10
+ class SlidesMagics(Magics):
11
+ @line_magic
12
+ def slides(self, line):
13
+ """%slides URL_OR_PATH [--local | --embed] [--width 900] [--height H] [--dpi 110]"""
14
+ p = argparse.ArgumentParser(prog="%slides", add_help=False)
15
+ p.add_argument("url")
16
+ g = p.add_mutually_exclusive_group()
17
+ g.add_argument("--local", action="store_true")
18
+ g.add_argument("--embed", action="store_true")
19
+ p.add_argument("--width", type=int, default=900)
20
+ p.add_argument("--height", type=int, default=None)
21
+ p.add_argument("--dpi", type=int, default=110)
22
+ try:
23
+ a = p.parse_args(shlex.split(self.shell.var_expand(line)))
24
+ except SystemExit:
25
+ print(self.slides.__doc__)
26
+ return
27
+ mode = "local" if a.local else "embed" if a.embed else "auto"
28
+ show(a.url, mode=mode, width=a.width, height=a.height, dpi=a.dpi)
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: colab-slides
3
+ Version: 0.1.0
4
+ Summary: Render PowerPoint and Google Slides decks inside Google Colab or Jupyter from a link
5
+ Author: Ahmad Mustapha
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/AhmadM-DL/colab-slides
8
+ Project-URL: Repository, https://github.com/AhmadM-DL/colab-slides
9
+ Project-URL: Issues, https://github.com/AhmadM-DL/colab-slides/issues
10
+ Keywords: colab,google-colab,jupyter,ipython,magic,powerpoint,pptx,google-slides,slides,presentation,slideshow
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Framework :: IPython
13
+ Classifier: Framework :: Jupyter
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Topic :: Multimedia :: Graphics :: Presentation
20
+ Classifier: Topic :: Education
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: ipython
25
+ Requires-Dist: requests
26
+ Dynamic: license-file
27
+
28
+ # colab-slides
29
+
30
+ [![PyPI](https://img.shields.io/pypi/v/colab-slides)](https://pypi.org/project/colab-slides/)
31
+ [![Python](https://img.shields.io/pypi/pyversions/colab-slides)](https://pypi.org/project/colab-slides/)
32
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/AhmadM-DL/colab-slides/blob/main/LICENSE)
33
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/AhmadM-DL/colab-slides/blob/main/demo.ipynb)
34
+
35
+ Show PowerPoint or Google Slides decks inside a Google Colab or Jupyter notebook by pasting a link.
36
+
37
+ ![colab-slides rendering a deck in a notebook cell](https://raw.githubusercontent.com/AhmadM-DL/colab-slides/main/docs/notebook.png)
38
+
39
+ ## Install (in Colab)
40
+
41
+ ```python
42
+ !pip install -q colab-slides
43
+ ```
44
+
45
+ ## Use
46
+
47
+ ```python
48
+ %load_ext colab_slides
49
+
50
+ %slides https://docs.google.com/presentation/d/<ID>/edit # Google Slides
51
+ %slides https://drive.google.com/file/d/<ID>/view # .pptx in Drive
52
+ %slides https://example.com/talk.pptx # direct link
53
+ %slides /content/drive/MyDrive/deck.pptx # mounted Drive / uploaded file
54
+ %slides https://example.com/talk.pptx --local --width 1000 # force in-notebook rendering
55
+ ```
56
+
57
+ Or from Python:
58
+
59
+ ```python
60
+ import colab_slides
61
+ colab_slides.show(url, mode="auto") # "auto" | "embed" | "local"
62
+ ```
63
+
64
+ ## Modes
65
+
66
+ | Mode | How it works | Good for |
67
+ |------|--------------|----------|
68
+ | `embed` | Uses the Google Slides embed viewer or Microsoft Office Online in an iframe. Nothing to install. Keeps animations and transitions. | Public links |
69
+ | `local` | Downloads the file, converts it with LibreOffice → PDF → PNG inside the Colab VM, and shows a built-in slideshow. | Private files (mounted Drive), uploaded files, links the online viewers can't open |
70
+ | `auto` (default) | Uses `embed` when the link can be embedded, otherwise `local` | — |
71
+
72
+ The first `local` render installs LibreOffice in the Colab VM (about 1–2 minutes, once per runtime).
73
+
74
+ **Slideshow controls (local mode):** ← → / Space / PageUp/PageDown, Home/End, `f` for fullscreen, click the left or right part of a slide, or click a thumbnail.
75
+
76
+ ### Screenshots
77
+
78
+ | Slideshow with thumbnails | Fullscreen (press `f`) |
79
+ |---|---|
80
+ | ![Slideshow with thumbnails](https://raw.githubusercontent.com/AhmadM-DL/colab-slides/main/docs/player.png) | ![Fullscreen view](https://raw.githubusercontent.com/AhmadM-DL/colab-slides/main/docs/fullscreen.png) |
81
+
82
+ ## Supported links
83
+
84
+ - Google Slides (`/edit` links and "Publish to web" links)
85
+ - Google Drive file links (shared as "Anyone with the link")
86
+ - Dropbox share links
87
+ - OneDrive / SharePoint share links (embed only)
88
+ - Any direct URL to a `.pptx`, `.ppt`, `.odp` or `.pdf`
89
+ - Local paths
90
+
91
+ ## Limits
92
+
93
+ - `local` mode shows static images: animations, transitions, embedded video and audio aren't kept.
94
+ - Fonts that aren't installed in the VM are replaced with similar ones, so layouts can shift slightly.
95
+ - Office Online only opens files that are publicly downloadable over HTTPS.
96
+
97
+ ## License
98
+
99
+ MIT
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ colab_slides/__init__.py
5
+ colab_slides/core.py
6
+ colab_slides/magics.py
7
+ colab_slides.egg-info/PKG-INFO
8
+ colab_slides.egg-info/SOURCES.txt
9
+ colab_slides.egg-info/dependency_links.txt
10
+ colab_slides.egg-info/requires.txt
11
+ colab_slides.egg-info/top_level.txt
12
+ tests/test_colab_slides.py
@@ -0,0 +1,2 @@
1
+ ipython
2
+ requests
@@ -0,0 +1 @@
1
+ colab_slides
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "colab-slides"
7
+ version = "0.1.0"
8
+ description = "Render PowerPoint and Google Slides decks inside Google Colab or Jupyter from a link"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Ahmad Mustapha" }]
14
+ keywords = ["colab", "google-colab", "jupyter", "ipython", "magic", "powerpoint", "pptx",
15
+ "google-slides", "slides", "presentation", "slideshow"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Framework :: IPython",
19
+ "Framework :: Jupyter",
20
+ "Intended Audience :: Education",
21
+ "Intended Audience :: Science/Research",
22
+ "Intended Audience :: Developers",
23
+ "Operating System :: OS Independent",
24
+ "Programming Language :: Python :: 3",
25
+ "Topic :: Multimedia :: Graphics :: Presentation",
26
+ "Topic :: Education",
27
+ ]
28
+ dependencies = ["ipython", "requests"]
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/AhmadM-DL/colab-slides"
32
+ Repository = "https://github.com/AhmadM-DL/colab-slides"
33
+ Issues = "https://github.com/AhmadM-DL/colab-slides/issues"
34
+
35
+ [tool.setuptools]
36
+ packages = ["colab_slides"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,46 @@
1
+ import shutil
2
+
3
+ import pytest
4
+
5
+ import colab_slides
6
+ from colab_slides.core import normalize_link
7
+
8
+
9
+ @pytest.mark.parametrize("url,kind,embed_part,download_part", [
10
+ ("https://docs.google.com/presentation/d/ABC123/edit#slide=id.p", "google_slides",
11
+ "/d/ABC123/embed", "/d/ABC123/export/pptx"),
12
+ ("https://docs.google.com/presentation/d/e/2PACX-xyz/pub?start=false", "google_slides_published",
13
+ "/d/e/2PACX-xyz/embed", "pub?output=pptx"),
14
+ ("https://drive.google.com/file/d/FID9/view?usp=sharing", "google_drive",
15
+ "/file/d/FID9/preview", "id=FID9"),
16
+ ("https://www.dropbox.com/s/abc/deck.pptx?dl=0", "dropbox", "view.officeapps.live.com", "dl=1"),
17
+ ("https://example.com/talk.pptx", "direct", "view.officeapps.live.com", "example.com/talk.pptx"),
18
+ ])
19
+ def test_normalize_link(url, kind, embed_part, download_part):
20
+ info = normalize_link(url)
21
+ assert info["kind"] == kind
22
+ assert embed_part in info["embed_url"]
23
+ assert download_part in info["download_url"]
24
+
25
+
26
+ def test_local_path_is_not_embeddable():
27
+ info = normalize_link("/content/deck.pptx")
28
+ assert info == {"kind": "path", "embed_url": None, "download_url": "/content/deck.pptx"}
29
+
30
+
31
+ @pytest.mark.skipif(not (shutil.which("soffice") and shutil.which("pdftoppm")),
32
+ reason="LibreOffice/poppler not installed")
33
+ def test_local_render(tmp_path):
34
+ from pptx import Presentation
35
+ prs = Presentation()
36
+ for i in range(3):
37
+ prs.slides.add_slide(prs.slide_layouts[1]).shapes.title.text = f"Slide {i + 1}"
38
+ deck = tmp_path / "deck.pptx"
39
+ prs.save(deck)
40
+
41
+ imgs = colab_slides.slide_images(str(deck), auto_install=False)
42
+ assert len(imgs) == 3
43
+ assert all(b.startswith(b"\x89PNG") for b in imgs)
44
+
45
+ html = colab_slides.render_local(str(deck), auto_install=False).data
46
+ assert html.count("data:image/png;base64,") == 3