A loose federation of distributed, typed datasets
1<!DOCTYPE html>
2<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
3
4<meta charset="utf-8">
5<meta name="generator" content="quarto-1.7.34">
6
7<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
8
9<meta name="description" content="Typed dataclasses with automatic msgpack serialization">
10
11<title>Packable Samples – atdata</title>
12<style>
13code{white-space: pre-wrap;}
14span.smallcaps{font-variant: small-caps;}
15div.columns{display: flex; gap: min(4vw, 1.5em);}
16div.column{flex: auto; overflow-x: auto;}
17div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
18ul.task-list{list-style: none;}
19ul.task-list li input[type="checkbox"] {
20 width: 0.8em;
21 margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
22 vertical-align: middle;
23}
24/* CSS for syntax highlighting */
25html { -webkit-text-size-adjust: 100%; }
26pre > code.sourceCode { white-space: pre; position: relative; }
27pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
28pre > code.sourceCode > span:empty { height: 1.2em; }
29.sourceCode { overflow: visible; }
30code.sourceCode > span { color: inherit; text-decoration: inherit; }
31div.sourceCode { margin: 1em 0; }
32pre.sourceCode { margin: 0; }
33@media screen {
34div.sourceCode { overflow: auto; }
35}
36@media print {
37pre > code.sourceCode { white-space: pre-wrap; }
38pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
39}
40pre.numberSource code
41 { counter-reset: source-line 0; }
42pre.numberSource code > span
43 { position: relative; left: -4em; counter-increment: source-line; }
44pre.numberSource code > span > a:first-child::before
45 { content: counter(source-line);
46 position: relative; left: -1em; text-align: right; vertical-align: baseline;
47 border: none; display: inline-block;
48 -webkit-touch-callout: none; -webkit-user-select: none;
49 -khtml-user-select: none; -moz-user-select: none;
50 -ms-user-select: none; user-select: none;
51 padding: 0 4px; width: 4em;
52 }
53pre.numberSource { margin-left: 3em; padding-left: 4px; }
54div.sourceCode
55 { }
56@media screen {
57pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
58}
59</style>
60
61
62<script src="../site_libs/quarto-nav/quarto-nav.js"></script>
63<script src="../site_libs/quarto-nav/headroom.min.js"></script>
64<script src="../site_libs/clipboard/clipboard.min.js"></script>
65<script src="../site_libs/quarto-search/autocomplete.umd.js"></script>
66<script src="../site_libs/quarto-search/fuse.min.js"></script>
67<script src="../site_libs/quarto-search/quarto-search.js"></script>
68<meta name="quarto:offset" content="../">
69<script src="../site_libs/quarto-html/quarto.js" type="module"></script>
70<script src="../site_libs/quarto-html/tabsets/tabsets.js" type="module"></script>
71<script src="../site_libs/quarto-html/popper.min.js"></script>
72<script src="../site_libs/quarto-html/tippy.umd.min.js"></script>
73<script src="../site_libs/quarto-html/anchor.min.js"></script>
74<link href="../site_libs/quarto-html/tippy.css" rel="stylesheet">
75<link href="../site_libs/quarto-html/quarto-syntax-highlighting-9582434199d49cc9e91654cdeeb4866b.css" rel="stylesheet" class="quarto-color-scheme" id="quarto-text-highlighting-styles">
76<link href="../site_libs/quarto-html/quarto-syntax-highlighting-dark-8dcd8563ea6803ab7cbb3d71ca5772e1.css" rel="stylesheet" class="quarto-color-scheme quarto-color-alternate" id="quarto-text-highlighting-styles">
77<link href="../site_libs/quarto-html/quarto-syntax-highlighting-9582434199d49cc9e91654cdeeb4866b.css" rel="stylesheet" class="quarto-color-scheme-extra" id="quarto-text-highlighting-styles">
78<script src="../site_libs/bootstrap/bootstrap.min.js"></script>
79<link href="../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
80<link href="../site_libs/bootstrap/bootstrap-62bce24ca844314e7bb1a34dbdfe05cc.min.css" rel="stylesheet" append-hash="true" class="quarto-color-scheme" id="quarto-bootstrap" data-mode="light">
81<link href="../site_libs/bootstrap/bootstrap-dark-7964ffd8887b0991fe8d71c6c8bc75d6.min.css" rel="stylesheet" append-hash="true" class="quarto-color-scheme quarto-color-alternate" id="quarto-bootstrap" data-mode="dark">
82<link href="../site_libs/bootstrap/bootstrap-62bce24ca844314e7bb1a34dbdfe05cc.min.css" rel="stylesheet" append-hash="true" class="quarto-color-scheme-extra" id="quarto-bootstrap" data-mode="light">
83<script id="quarto-search-options" type="application/json">{
84 "location": "navbar",
85 "copy-button": false,
86 "collapse-after": 3,
87 "panel-placement": "end",
88 "type": "overlay",
89 "limit": 50,
90 "keyboard-shortcut": [
91 "f",
92 "/",
93 "s"
94 ],
95 "show-item-context": false,
96 "language": {
97 "search-no-results-text": "No results",
98 "search-matching-documents-text": "matching documents",
99 "search-copy-link-title": "Copy link to search",
100 "search-hide-matches-text": "Hide additional matches",
101 "search-more-match-text": "more match in this document",
102 "search-more-matches-text": "more matches in this document",
103 "search-clear-button-title": "Clear",
104 "search-text-placeholder": "",
105 "search-detached-cancel-button-title": "Cancel",
106 "search-submit-button-title": "Submit",
107 "search-label": "Search"
108 }
109}</script>
110
111
112<link rel="stylesheet" href="../assets/styles.css">
113</head>
114
115<body class="nav-sidebar docked nav-fixed quarto-light"><script id="quarto-html-before-body" type="application/javascript">
116 const toggleBodyColorMode = (bsSheetEl) => {
117 const mode = bsSheetEl.getAttribute("data-mode");
118 const bodyEl = window.document.querySelector("body");
119 if (mode === "dark") {
120 bodyEl.classList.add("quarto-dark");
121 bodyEl.classList.remove("quarto-light");
122 } else {
123 bodyEl.classList.add("quarto-light");
124 bodyEl.classList.remove("quarto-dark");
125 }
126 }
127 const toggleBodyColorPrimary = () => {
128 const bsSheetEl = window.document.querySelector("link#quarto-bootstrap:not([rel=disabled-stylesheet])");
129 if (bsSheetEl) {
130 toggleBodyColorMode(bsSheetEl);
131 }
132 }
133 const setColorSchemeToggle = (alternate) => {
134 const toggles = window.document.querySelectorAll('.quarto-color-scheme-toggle');
135 for (let i=0; i < toggles.length; i++) {
136 const toggle = toggles[i];
137 if (toggle) {
138 if (alternate) {
139 toggle.classList.add("alternate");
140 } else {
141 toggle.classList.remove("alternate");
142 }
143 }
144 }
145 };
146 const toggleColorMode = (alternate) => {
147 // Switch the stylesheets
148 const primaryStylesheets = window.document.querySelectorAll('link.quarto-color-scheme:not(.quarto-color-alternate)');
149 const alternateStylesheets = window.document.querySelectorAll('link.quarto-color-scheme.quarto-color-alternate');
150 manageTransitions('#quarto-margin-sidebar .nav-link', false);
151 if (alternate) {
152 // note: dark is layered on light, we don't disable primary!
153 enableStylesheet(alternateStylesheets);
154 for (const sheetNode of alternateStylesheets) {
155 if (sheetNode.id === "quarto-bootstrap") {
156 toggleBodyColorMode(sheetNode);
157 }
158 }
159 } else {
160 disableStylesheet(alternateStylesheets);
161 enableStylesheet(primaryStylesheets)
162 toggleBodyColorPrimary();
163 }
164 manageTransitions('#quarto-margin-sidebar .nav-link', true);
165 // Switch the toggles
166 setColorSchemeToggle(alternate)
167 // Hack to workaround the fact that safari doesn't
168 // properly recolor the scrollbar when toggling (#1455)
169 if (navigator.userAgent.indexOf('Safari') > 0 && navigator.userAgent.indexOf('Chrome') == -1) {
170 manageTransitions("body", false);
171 window.scrollTo(0, 1);
172 setTimeout(() => {
173 window.scrollTo(0, 0);
174 manageTransitions("body", true);
175 }, 40);
176 }
177 }
178 const disableStylesheet = (stylesheets) => {
179 for (let i=0; i < stylesheets.length; i++) {
180 const stylesheet = stylesheets[i];
181 stylesheet.rel = 'disabled-stylesheet';
182 }
183 }
184 const enableStylesheet = (stylesheets) => {
185 for (let i=0; i < stylesheets.length; i++) {
186 const stylesheet = stylesheets[i];
187 if(stylesheet.rel !== 'stylesheet') { // for Chrome, which will still FOUC without this check
188 stylesheet.rel = 'stylesheet';
189 }
190 }
191 }
192 const manageTransitions = (selector, allowTransitions) => {
193 const els = window.document.querySelectorAll(selector);
194 for (let i=0; i < els.length; i++) {
195 const el = els[i];
196 if (allowTransitions) {
197 el.classList.remove('notransition');
198 } else {
199 el.classList.add('notransition');
200 }
201 }
202 }
203 const isFileUrl = () => {
204 return window.location.protocol === 'file:';
205 }
206 const hasAlternateSentinel = () => {
207 let styleSentinel = getColorSchemeSentinel();
208 if (styleSentinel !== null) {
209 return styleSentinel === "alternate";
210 } else {
211 return false;
212 }
213 }
214 const setStyleSentinel = (alternate) => {
215 const value = alternate ? "alternate" : "default";
216 if (!isFileUrl()) {
217 window.localStorage.setItem("quarto-color-scheme", value);
218 } else {
219 localAlternateSentinel = value;
220 }
221 }
222 const getColorSchemeSentinel = () => {
223 if (!isFileUrl()) {
224 const storageValue = window.localStorage.getItem("quarto-color-scheme");
225 return storageValue != null ? storageValue : localAlternateSentinel;
226 } else {
227 return localAlternateSentinel;
228 }
229 }
230 const toggleGiscusIfUsed = (isAlternate, darkModeDefault) => {
231 const baseTheme = document.querySelector('#giscus-base-theme')?.value ?? 'light';
232 const alternateTheme = document.querySelector('#giscus-alt-theme')?.value ?? 'dark';
233 let newTheme = '';
234 if(authorPrefersDark) {
235 newTheme = isAlternate ? baseTheme : alternateTheme;
236 } else {
237 newTheme = isAlternate ? alternateTheme : baseTheme;
238 }
239 const changeGiscusTheme = () => {
240 // From: https://github.com/giscus/giscus/issues/336
241 const sendMessage = (message) => {
242 const iframe = document.querySelector('iframe.giscus-frame');
243 if (!iframe) return;
244 iframe.contentWindow.postMessage({ giscus: message }, 'https://giscus.app');
245 }
246 sendMessage({
247 setConfig: {
248 theme: newTheme
249 }
250 });
251 }
252 const isGiscussLoaded = window.document.querySelector('iframe.giscus-frame') !== null;
253 if (isGiscussLoaded) {
254 changeGiscusTheme();
255 }
256 };
257 const authorPrefersDark = false;
258 const darkModeDefault = authorPrefersDark;
259 document.querySelector('link#quarto-text-highlighting-styles.quarto-color-scheme-extra').rel = 'disabled-stylesheet';
260 document.querySelector('link#quarto-bootstrap.quarto-color-scheme-extra').rel = 'disabled-stylesheet';
261 let localAlternateSentinel = darkModeDefault ? 'alternate' : 'default';
262 // Dark / light mode switch
263 window.quartoToggleColorScheme = () => {
264 // Read the current dark / light value
265 let toAlternate = !hasAlternateSentinel();
266 toggleColorMode(toAlternate);
267 setStyleSentinel(toAlternate);
268 toggleGiscusIfUsed(toAlternate, darkModeDefault);
269 window.dispatchEvent(new Event('resize'));
270 };
271 // Switch to dark mode if need be
272 if (hasAlternateSentinel()) {
273 toggleColorMode(true);
274 } else {
275 toggleColorMode(false);
276 }
277 </script>
278
279<div id="quarto-search-results"></div>
280 <header id="quarto-header" class="headroom fixed-top">
281 <nav class="navbar navbar-expand-lg " data-bs-theme="dark">
282 <div class="navbar-container container-fluid">
283 <div class="navbar-brand-container mx-auto">
284 <a class="navbar-brand" href="../index.html">
285 <span class="navbar-title">atdata</span>
286 </a>
287 </div>
288 <div id="quarto-search" class="" title="Search"></div>
289 <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" role="menu" aria-expanded="false" aria-label="Toggle navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
290 <span class="navbar-toggler-icon"></span>
291</button>
292 <div class="collapse navbar-collapse" id="navbarCollapse">
293 <ul class="navbar-nav navbar-nav-scroll me-auto">
294 <li class="nav-item">
295 <a class="nav-link active" href="../index.html" aria-current="page">
296<span class="menu-text">Guide</span></a>
297 </li>
298 <li class="nav-item dropdown ">
299 <a class="nav-link dropdown-toggle" href="#" id="nav-menu-tutorials" role="link" data-bs-toggle="dropdown" aria-expanded="false">
300 <span class="menu-text">Tutorials</span>
301 </a>
302 <ul class="dropdown-menu" aria-labelledby="nav-menu-tutorials">
303 <li>
304 <a class="dropdown-item" href="../tutorials/quickstart.html">
305 <span class="dropdown-text">Quick Start</span></a>
306 </li>
307 <li>
308 <a class="dropdown-item" href="../tutorials/local-workflow.html">
309 <span class="dropdown-text">Local Workflow</span></a>
310 </li>
311 <li>
312 <a class="dropdown-item" href="../tutorials/atmosphere.html">
313 <span class="dropdown-text">Atmosphere Publishing</span></a>
314 </li>
315 <li>
316 <a class="dropdown-item" href="../tutorials/promotion.html">
317 <span class="dropdown-text">Promotion Workflow</span></a>
318 </li>
319 </ul>
320 </li>
321 <li class="nav-item dropdown ">
322 <a class="nav-link dropdown-toggle" href="#" id="nav-menu-reference" role="link" data-bs-toggle="dropdown" aria-expanded="false">
323 <span class="menu-text">Reference</span>
324 </a>
325 <ul class="dropdown-menu" aria-labelledby="nav-menu-reference">
326 <li>
327 <a class="dropdown-item" href="../reference/architecture.html">
328 <span class="dropdown-text">Architecture Overview</span></a>
329 </li>
330 <li>
331 <a class="dropdown-item" href="../reference/packable-samples.html">
332 <span class="dropdown-text">Packable Samples</span></a>
333 </li>
334 <li>
335 <a class="dropdown-item" href="../reference/datasets.html">
336 <span class="dropdown-text">Datasets</span></a>
337 </li>
338 <li>
339 <a class="dropdown-item" href="../reference/lenses.html">
340 <span class="dropdown-text">Lenses</span></a>
341 </li>
342 <li>
343 <a class="dropdown-item" href="../reference/local-storage.html">
344 <span class="dropdown-text">Local Storage</span></a>
345 </li>
346 <li>
347 <a class="dropdown-item" href="../reference/atmosphere.html">
348 <span class="dropdown-text">Atmosphere</span></a>
349 </li>
350 <li>
351 <a class="dropdown-item" href="../reference/promotion.html">
352 <span class="dropdown-text">Promotion</span></a>
353 </li>
354 <li>
355 <a class="dropdown-item" href="../reference/load-dataset.html">
356 <span class="dropdown-text">load_dataset API</span></a>
357 </li>
358 <li>
359 <a class="dropdown-item" href="../reference/protocols.html">
360 <span class="dropdown-text">Protocols</span></a>
361 </li>
362 <li>
363 <a class="dropdown-item" href="../reference/uri-spec.html">
364 <span class="dropdown-text">URI Specification</span></a>
365 </li>
366 <li>
367 <a class="dropdown-item" href="../reference/troubleshooting.html">
368 <span class="dropdown-text">Troubleshooting & FAQ</span></a>
369 </li>
370 <li>
371 <a class="dropdown-item" href="../reference/deployment.html">
372 <span class="dropdown-text">Deployment Guide</span></a>
373 </li>
374 </ul>
375 </li>
376 <li class="nav-item">
377 <a class="nav-link" href="../api/index.html">
378<span class="menu-text">API</span></a>
379 </li>
380</ul>
381 <ul class="navbar-nav navbar-nav-scroll ms-auto">
382 <li class="nav-item compact">
383 <a class="nav-link" href="https://github.com/your-org/atdata"> <i class="bi bi-github" role="img">
384</i>
385<span class="menu-text"></span></a>
386 </li>
387</ul>
388 </div> <!-- /navcollapse -->
389 <div class="quarto-navbar-tools">
390 <a href="" class="quarto-color-scheme-toggle quarto-navigation-tool px-1" onclick="window.quartoToggleColorScheme(); return false;" title="Toggle dark mode"><i class="bi"></i></a>
391</div>
392 </div> <!-- /container-fluid -->
393 </nav>
394 <nav class="quarto-secondary-nav">
395 <div class="container-fluid d-flex">
396 <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
397 <i class="bi bi-layout-text-sidebar-reverse"></i>
398 </button>
399 <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="../reference/architecture.html">Reference</a></li><li class="breadcrumb-item"><a href="../reference/packable-samples.html">Packable Samples</a></li></ol></nav>
400 <a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
401 </a>
402 </div>
403 </nav>
404</header>
405<!-- content -->
406<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
407<!-- sidebar -->
408 <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation docked overflow-auto">
409 <div class="sidebar-menu-container">
410 <ul class="list-unstyled mt-1">
411 <li class="sidebar-item">
412 <div class="sidebar-item-container">
413 <a href="../index.html" class="sidebar-item-text sidebar-link">
414 <span class="menu-text">atdata</span></a>
415 </div>
416</li>
417 <li class="sidebar-item sidebar-item-section">
418 <div class="sidebar-item-container">
419 <a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true">
420 <span class="menu-text">Getting Started</span></a>
421 <a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true" aria-label="Toggle section">
422 <i class="bi bi-chevron-right ms-2"></i>
423 </a>
424 </div>
425 <ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
426 <li class="sidebar-item">
427 <div class="sidebar-item-container">
428 <a href="../tutorials/quickstart.html" class="sidebar-item-text sidebar-link">
429 <span class="menu-text">Quick Start</span></a>
430 </div>
431</li>
432 <li class="sidebar-item">
433 <div class="sidebar-item-container">
434 <a href="../tutorials/local-workflow.html" class="sidebar-item-text sidebar-link">
435 <span class="menu-text">Local Workflow</span></a>
436 </div>
437</li>
438 <li class="sidebar-item">
439 <div class="sidebar-item-container">
440 <a href="../tutorials/atmosphere.html" class="sidebar-item-text sidebar-link">
441 <span class="menu-text">Atmosphere Publishing</span></a>
442 </div>
443</li>
444 <li class="sidebar-item">
445 <div class="sidebar-item-container">
446 <a href="../tutorials/promotion.html" class="sidebar-item-text sidebar-link">
447 <span class="menu-text">Promotion Workflow</span></a>
448 </div>
449</li>
450 </ul>
451 </li>
452 <li class="sidebar-item sidebar-item-section">
453 <div class="sidebar-item-container">
454 <a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" role="navigation" aria-expanded="true">
455 <span class="menu-text">Reference</span></a>
456 <a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" role="navigation" aria-expanded="true" aria-label="Toggle section">
457 <i class="bi bi-chevron-right ms-2"></i>
458 </a>
459 </div>
460 <ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 show">
461 <li class="sidebar-item">
462 <div class="sidebar-item-container">
463 <a href="../reference/architecture.html" class="sidebar-item-text sidebar-link">
464 <span class="menu-text">Architecture Overview</span></a>
465 </div>
466</li>
467 <li class="sidebar-item">
468 <div class="sidebar-item-container">
469 <a href="../reference/packable-samples.html" class="sidebar-item-text sidebar-link active">
470 <span class="menu-text">Packable Samples</span></a>
471 </div>
472</li>
473 <li class="sidebar-item">
474 <div class="sidebar-item-container">
475 <a href="../reference/datasets.html" class="sidebar-item-text sidebar-link">
476 <span class="menu-text">Datasets</span></a>
477 </div>
478</li>
479 <li class="sidebar-item">
480 <div class="sidebar-item-container">
481 <a href="../reference/lenses.html" class="sidebar-item-text sidebar-link">
482 <span class="menu-text">Lenses</span></a>
483 </div>
484</li>
485 <li class="sidebar-item">
486 <div class="sidebar-item-container">
487 <a href="../reference/local-storage.html" class="sidebar-item-text sidebar-link">
488 <span class="menu-text">Local Storage</span></a>
489 </div>
490</li>
491 <li class="sidebar-item">
492 <div class="sidebar-item-container">
493 <a href="../reference/atmosphere.html" class="sidebar-item-text sidebar-link">
494 <span class="menu-text">Atmosphere (ATProto Integration)</span></a>
495 </div>
496</li>
497 <li class="sidebar-item">
498 <div class="sidebar-item-container">
499 <a href="../reference/promotion.html" class="sidebar-item-text sidebar-link">
500 <span class="menu-text">Promotion Workflow</span></a>
501 </div>
502</li>
503 <li class="sidebar-item">
504 <div class="sidebar-item-container">
505 <a href="../reference/load-dataset.html" class="sidebar-item-text sidebar-link">
506 <span class="menu-text">load_dataset API</span></a>
507 </div>
508</li>
509 <li class="sidebar-item">
510 <div class="sidebar-item-container">
511 <a href="../reference/protocols.html" class="sidebar-item-text sidebar-link">
512 <span class="menu-text">Protocols</span></a>
513 </div>
514</li>
515 <li class="sidebar-item">
516 <div class="sidebar-item-container">
517 <a href="../reference/uri-spec.html" class="sidebar-item-text sidebar-link">
518 <span class="menu-text">URI Specification</span></a>
519 </div>
520</li>
521 <li class="sidebar-item">
522 <div class="sidebar-item-container">
523 <a href="../reference/troubleshooting.html" class="sidebar-item-text sidebar-link">
524 <span class="menu-text">Troubleshooting & FAQ</span></a>
525 </div>
526</li>
527 <li class="sidebar-item">
528 <div class="sidebar-item-container">
529 <a href="../reference/deployment.html" class="sidebar-item-text sidebar-link">
530 <span class="menu-text">Deployment Guide</span></a>
531 </div>
532</li>
533 </ul>
534 </li>
535 </ul>
536 </div>
537</nav>
538<div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
539<!-- margin-sidebar -->
540 <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
541 <nav id="TOC" role="doc-toc" class="toc-active">
542 <h2 id="toc-title">On this page</h2>
543
544 <ul>
545 <li><a href="#the-packable-decorator" id="toc-the-packable-decorator" class="nav-link active" data-scroll-target="#the-packable-decorator">The <code>@packable</code> Decorator</a></li>
546 <li><a href="#supported-field-types" id="toc-supported-field-types" class="nav-link" data-scroll-target="#supported-field-types">Supported Field Types</a>
547 <ul class="collapse">
548 <li><a href="#primitives" id="toc-primitives" class="nav-link" data-scroll-target="#primitives">Primitives</a></li>
549 <li><a href="#numpy-arrays" id="toc-numpy-arrays" class="nav-link" data-scroll-target="#numpy-arrays">NumPy Arrays</a></li>
550 <li><a href="#lists" id="toc-lists" class="nav-link" data-scroll-target="#lists">Lists</a></li>
551 </ul></li>
552 <li><a href="#serialization" id="toc-serialization" class="nav-link" data-scroll-target="#serialization">Serialization</a>
553 <ul class="collapse">
554 <li><a href="#packing-to-bytes" id="toc-packing-to-bytes" class="nav-link" data-scroll-target="#packing-to-bytes">Packing to Bytes</a></li>
555 <li><a href="#unpacking-from-bytes" id="toc-unpacking-from-bytes" class="nav-link" data-scroll-target="#unpacking-from-bytes">Unpacking from Bytes</a></li>
556 <li><a href="#webdataset-format" id="toc-webdataset-format" class="nav-link" data-scroll-target="#webdataset-format">WebDataset Format</a></li>
557 </ul></li>
558 <li><a href="#direct-inheritance-alternative" id="toc-direct-inheritance-alternative" class="nav-link" data-scroll-target="#direct-inheritance-alternative">Direct Inheritance (Alternative)</a></li>
559 <li><a href="#how-it-works" id="toc-how-it-works" class="nav-link" data-scroll-target="#how-it-works">How It Works</a>
560 <ul class="collapse">
561 <li><a href="#serialization-flow" id="toc-serialization-flow" class="nav-link" data-scroll-target="#serialization-flow">Serialization Flow</a></li>
562 <li><a href="#the-_ensure_good-method" id="toc-the-_ensure_good-method" class="nav-link" data-scroll-target="#the-_ensure_good-method">The <code>_ensure_good()</code> Method</a></li>
563 </ul></li>
564 <li><a href="#best-practices" id="toc-best-practices" class="nav-link" data-scroll-target="#best-practices">Best Practices</a></li>
565 <li><a href="#related" id="toc-related" class="nav-link" data-scroll-target="#related">Related</a></li>
566 </ul>
567<div class="toc-actions"><ul><li><a href="https://github.com/your-org/atdata/edit/main/reference/packable-samples.qmd" class="toc-action"><i class="bi bi-github"></i>Edit this page</a></li><li><a href="https://github.com/your-org/atdata/issues/new" class="toc-action"><i class="bi empty"></i>Report an issue</a></li></ul></div></nav>
568 </div>
569<!-- main -->
570<main class="content" id="quarto-document-content">
571
572
573<header id="title-block-header" class="quarto-title-block default"><nav class="quarto-page-breadcrumbs quarto-title-breadcrumbs d-none d-lg-block" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="../reference/architecture.html">Reference</a></li><li class="breadcrumb-item"><a href="../reference/packable-samples.html">Packable Samples</a></li></ol></nav>
574<div class="quarto-title">
575<h1 class="title">Packable Samples</h1>
576</div>
577
578<div>
579 <div class="description">
580 Typed dataclasses with automatic msgpack serialization
581 </div>
582</div>
583
584
585<div class="quarto-title-meta">
586
587
588
589
590 </div>
591
592
593
594</header>
595
596
597<p>Packable samples are typed dataclasses that can be serialized with msgpack for storage in WebDataset tar files.</p>
598<section id="the-packable-decorator" class="level2">
599<h2 class="anchored" data-anchor-id="the-packable-decorator">The <code>@packable</code> Decorator</h2>
600<p>The recommended way to define a sample type is with the <code>@packable</code> decorator:</p>
601<div id="4706cae6" class="cell">
602<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np</span>
603<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> numpy.typing <span class="im">import</span> NDArray</span>
604<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> atdata</span>
605<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a></span>
606<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="at">@atdata.packable</span></span>
607<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="kw">class</span> ImageSample:</span>
608<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> image: NDArray</span>
609<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> label: <span class="bu">str</span></span>
610<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> confidence: <span class="bu">float</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
611</div>
612<p>This creates a dataclass that:</p>
613<ul>
614<li>Inherits from <code>PackableSample</code></li>
615<li>Has automatic msgpack serialization</li>
616<li>Handles NDArray conversion to/from bytes</li>
617</ul>
618</section>
619<section id="supported-field-types" class="level2">
620<h2 class="anchored" data-anchor-id="supported-field-types">Supported Field Types</h2>
621<section id="primitives" class="level3">
622<h3 class="anchored" data-anchor-id="primitives">Primitives</h3>
623<div id="e4fc5e65" class="cell">
624<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="at">@atdata.packable</span></span>
625<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="kw">class</span> PrimitiveSample:</span>
626<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> name: <span class="bu">str</span></span>
627<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> count: <span class="bu">int</span></span>
628<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> score: <span class="bu">float</span></span>
629<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> active: <span class="bu">bool</span></span>
630<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> data: <span class="bu">bytes</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
631</div>
632</section>
633<section id="numpy-arrays" class="level3">
634<h3 class="anchored" data-anchor-id="numpy-arrays">NumPy Arrays</h3>
635<p>Fields annotated as <code>NDArray</code> are automatically converted:</p>
636<div id="54fb169f" class="cell">
637<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="at">@atdata.packable</span></span>
638<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="kw">class</span> ArraySample:</span>
639<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> features: NDArray <span class="co"># Required array</span></span>
640<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> embeddings: NDArray <span class="op">|</span> <span class="va">None</span> <span class="co"># Optional array</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
641</div>
642<div class="callout callout-style-default callout-note callout-titled">
643<div class="callout-header d-flex align-content-center">
644<div class="callout-icon-container">
645<i class="callout-icon"></i>
646</div>
647<div class="callout-title-container flex-fill">
648Note
649</div>
650</div>
651<div class="callout-body-container callout-body">
652<p>Bytes in NDArray-typed fields are always interpreted as serialized arrays. Don’t use <code>NDArray</code> for raw binary data—use <code>bytes</code> instead.</p>
653</div>
654</div>
655</section>
656<section id="lists" class="level3">
657<h3 class="anchored" data-anchor-id="lists">Lists</h3>
658<div id="ff4deef3" class="cell">
659<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="at">@atdata.packable</span></span>
660<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="kw">class</span> ListSample:</span>
661<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> tags: <span class="bu">list</span>[<span class="bu">str</span>]</span>
662<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> scores: <span class="bu">list</span>[<span class="bu">float</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
663</div>
664</section>
665</section>
666<section id="serialization" class="level2">
667<h2 class="anchored" data-anchor-id="serialization">Serialization</h2>
668<section id="packing-to-bytes" class="level3">
669<h3 class="anchored" data-anchor-id="packing-to-bytes">Packing to Bytes</h3>
670<div id="bd357b91" class="cell">
671<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>sample <span class="op">=</span> ImageSample(</span>
672<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> image<span class="op">=</span>np.random.rand(<span class="dv">224</span>, <span class="dv">224</span>, <span class="dv">3</span>).astype(np.float32),</span>
673<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> label<span class="op">=</span><span class="st">"cat"</span>,</span>
674<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> confidence<span class="op">=</span><span class="fl">0.95</span>,</span>
675<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>)</span>
676<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a></span>
677<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Serialize to msgpack bytes</span></span>
678<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a>packed_bytes <span class="op">=</span> sample.packed</span>
679<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(<span class="ss">f"Size: </span><span class="sc">{</span><span class="bu">len</span>(packed_bytes)<span class="sc">}</span><span class="ss"> bytes"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
680</div>
681</section>
682<section id="unpacking-from-bytes" class="level3">
683<h3 class="anchored" data-anchor-id="unpacking-from-bytes">Unpacking from Bytes</h3>
684<div id="67e2bcc5" class="cell">
685<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Deserialize from bytes</span></span>
686<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>restored <span class="op">=</span> ImageSample.from_bytes(packed_bytes)</span>
687<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a></span>
688<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Arrays are automatically restored</span></span>
689<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a><span class="cf">assert</span> np.array_equal(sample.image, restored.image)</span>
690<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a><span class="cf">assert</span> sample.label <span class="op">==</span> restored.label</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
691</div>
692</section>
693<section id="webdataset-format" class="level3">
694<h3 class="anchored" data-anchor-id="webdataset-format">WebDataset Format</h3>
695<p>The <code>as_wds</code> property returns a dict ready for WebDataset:</p>
696<div id="adafdd43" class="cell">
697<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>wds_dict <span class="op">=</span> sample.as_wds</span>
698<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="co"># {'__key__': '1234...', 'msgpack': b'...'}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
699</div>
700<p>Write samples to a tar file:</p>
701<div id="5fd86dab" class="cell">
702<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> webdataset <span class="im">as</span> wds</span>
703<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a></span>
704<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a><span class="cf">with</span> wds.writer.TarWriter(<span class="st">"data-000000.tar"</span>) <span class="im">as</span> sink:</span>
705<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> i, sample <span class="kw">in</span> <span class="bu">enumerate</span>(samples):</span>
706<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> <span class="co"># Use custom key or let as_wds generate one</span></span>
707<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a> sink.write({<span class="op">**</span>sample.as_wds, <span class="st">"__key__"</span>: <span class="ss">f"sample_</span><span class="sc">{</span>i<span class="sc">:06d}</span><span class="ss">"</span>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
708</div>
709</section>
710</section>
711<section id="direct-inheritance-alternative" class="level2">
712<h2 class="anchored" data-anchor-id="direct-inheritance-alternative">Direct Inheritance (Alternative)</h2>
713<p>You can also inherit directly from <code>PackableSample</code>:</p>
714<div id="9c493592" class="cell">
715<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> dataclasses <span class="im">import</span> dataclass</span>
716<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a></span>
717<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a><span class="at">@dataclass</span></span>
718<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a><span class="kw">class</span> DirectSample(atdata.PackableSample):</span>
719<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a> name: <span class="bu">str</span></span>
720<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a> values: NDArray</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
721</div>
722<p>This is equivalent to using <code>@packable</code> but more verbose.</p>
723</section>
724<section id="how-it-works" class="level2">
725<h2 class="anchored" data-anchor-id="how-it-works">How It Works</h2>
726<section id="serialization-flow" class="level3">
727<h3 class="anchored" data-anchor-id="serialization-flow">Serialization Flow</h3>
728<div class="tabset-margin-container"></div><div class="panel-tabset">
729<ul class="nav nav-tabs" role="tablist"><li class="nav-item" role="presentation"><a class="nav-link active" id="tabset-1-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-1" role="tab" aria-controls="tabset-1-1" aria-selected="true">Packing</a></li><li class="nav-item" role="presentation"><a class="nav-link" id="tabset-1-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-2" role="tab" aria-controls="tabset-1-2" aria-selected="false">Unpacking</a></li></ul>
730<div class="tab-content">
731<div id="tabset-1-1" class="tab-pane active" role="tabpanel" aria-labelledby="tabset-1-1-tab">
732<ol type="1">
733<li>NDArray fields → converted to bytes via <code>array_to_bytes()</code></li>
734<li>Other fields → passed through unchanged</li>
735<li>All fields → packed with msgpack</li>
736</ol>
737</div>
738<div id="tabset-1-2" class="tab-pane" role="tabpanel" aria-labelledby="tabset-1-2-tab">
739<ol type="1">
740<li>Bytes → unpacked with ormsgpack</li>
741<li>Dict → passed to <code>__init__</code></li>
742<li><code>__post_init__</code> → calls <code>_ensure_good()</code></li>
743<li>NDArray fields → bytes converted back to arrays</li>
744</ol>
745</div>
746</div>
747</div>
748</section>
749<section id="the-_ensure_good-method" class="level3">
750<h3 class="anchored" data-anchor-id="the-_ensure_good-method">The <code>_ensure_good()</code> Method</h3>
751<p>This method runs automatically after construction and handles NDArray conversion:</p>
752<div id="2397bcd3" class="cell">
753<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> _ensure_good(<span class="va">self</span>):</span>
754<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> field <span class="kw">in</span> dataclasses.fields(<span class="va">self</span>):</span>
755<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> _is_possibly_ndarray_type(field.<span class="bu">type</span>):</span>
756<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> value <span class="op">=</span> <span class="bu">getattr</span>(<span class="va">self</span>, field.name)</span>
757<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="bu">isinstance</span>(value, <span class="bu">bytes</span>):</span>
758<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a> <span class="bu">setattr</span>(<span class="va">self</span>, field.name, bytes_to_array(value))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
759</div>
760</section>
761</section>
762<section id="best-practices" class="level2">
763<h2 class="anchored" data-anchor-id="best-practices">Best Practices</h2>
764<div class="tabset-margin-container"></div><div class="panel-tabset">
765<ul class="nav nav-tabs" role="tablist"><li class="nav-item" role="presentation"><a class="nav-link active" id="tabset-2-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-1" role="tab" aria-controls="tabset-2-1" aria-selected="true">Do</a></li><li class="nav-item" role="presentation"><a class="nav-link" id="tabset-2-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-2" role="tab" aria-controls="tabset-2-2" aria-selected="false">Don’t</a></li></ul>
766<div class="tab-content">
767<div id="tabset-2-1" class="tab-pane active" role="tabpanel" aria-labelledby="tabset-2-1-tab">
768<div id="b9bcc4bd" class="cell">
769<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="at">@atdata.packable</span></span>
770<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="kw">class</span> GoodSample:</span>
771<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> features: NDArray <span class="co"># Clear type annotation</span></span>
772<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> label: <span class="bu">str</span> <span class="co"># Simple primitives</span></span>
773<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> metadata: <span class="bu">dict</span> <span class="co"># Msgpack-compatible dicts</span></span>
774<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a> scores: <span class="bu">list</span>[<span class="bu">float</span>] <span class="co"># Typed lists</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
775</div>
776</div>
777<div id="tabset-2-2" class="tab-pane" role="tabpanel" aria-labelledby="tabset-2-2-tab">
778<div id="3f23b423" class="cell">
779<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="at">@atdata.packable</span></span>
780<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="kw">class</span> BadSample:</span>
781<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a> <span class="co"># DON'T: Nested dataclasses not supported</span></span>
782<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> nested: OtherSample</span>
783<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a></span>
784<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a> <span class="co"># DON'T: Complex objects that aren't msgpack-serializable</span></span>
785<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a> callback: Callable</span>
786<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a></span>
787<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a> <span class="co"># DON'T: Use NDArray for raw bytes</span></span>
788<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a> raw_data: NDArray <span class="co"># Use 'bytes' type instead</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
789</div>
790</div>
791</div>
792</div>
793</section>
794<section id="related" class="level2">
795<h2 class="anchored" data-anchor-id="related">Related</h2>
796<ul>
797<li><a href="../reference/datasets.html">Datasets</a> - Loading and iterating samples</li>
798<li><a href="../reference/lenses.html">Lenses</a> - Transforming between sample types</li>
799</ul>
800
801
802</section>
803
804</main> <!-- /main -->
805<script id="quarto-html-after-body" type="application/javascript">
806 window.document.addEventListener("DOMContentLoaded", function (event) {
807 // Ensure there is a toggle, if there isn't float one in the top right
808 if (window.document.querySelector('.quarto-color-scheme-toggle') === null) {
809 const a = window.document.createElement('a');
810 a.classList.add('top-right');
811 a.classList.add('quarto-color-scheme-toggle');
812 a.href = "";
813 a.onclick = function() { try { window.quartoToggleColorScheme(); } catch {} return false; };
814 const i = window.document.createElement("i");
815 i.classList.add('bi');
816 a.appendChild(i);
817 window.document.body.appendChild(a);
818 }
819 setColorSchemeToggle(hasAlternateSentinel())
820 const icon = "";
821 const anchorJS = new window.AnchorJS();
822 anchorJS.options = {
823 placement: 'right',
824 icon: icon
825 };
826 anchorJS.add('.anchored');
827 const isCodeAnnotation = (el) => {
828 for (const clz of el.classList) {
829 if (clz.startsWith('code-annotation-')) {
830 return true;
831 }
832 }
833 return false;
834 }
835 const onCopySuccess = function(e) {
836 // button target
837 const button = e.trigger;
838 // don't keep focus
839 button.blur();
840 // flash "checked"
841 button.classList.add('code-copy-button-checked');
842 var currentTitle = button.getAttribute("title");
843 button.setAttribute("title", "Copied!");
844 let tooltip;
845 if (window.bootstrap) {
846 button.setAttribute("data-bs-toggle", "tooltip");
847 button.setAttribute("data-bs-placement", "left");
848 button.setAttribute("data-bs-title", "Copied!");
849 tooltip = new bootstrap.Tooltip(button,
850 { trigger: "manual",
851 customClass: "code-copy-button-tooltip",
852 offset: [0, -8]});
853 tooltip.show();
854 }
855 setTimeout(function() {
856 if (tooltip) {
857 tooltip.hide();
858 button.removeAttribute("data-bs-title");
859 button.removeAttribute("data-bs-toggle");
860 button.removeAttribute("data-bs-placement");
861 }
862 button.setAttribute("title", currentTitle);
863 button.classList.remove('code-copy-button-checked');
864 }, 1000);
865 // clear code selection
866 e.clearSelection();
867 }
868 const getTextToCopy = function(trigger) {
869 const codeEl = trigger.previousElementSibling.cloneNode(true);
870 for (const childEl of codeEl.children) {
871 if (isCodeAnnotation(childEl)) {
872 childEl.remove();
873 }
874 }
875 return codeEl.innerText;
876 }
877 const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
878 text: getTextToCopy
879 });
880 clipboard.on('success', onCopySuccess);
881 if (window.document.getElementById('quarto-embedded-source-code-modal')) {
882 const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
883 text: getTextToCopy,
884 container: window.document.getElementById('quarto-embedded-source-code-modal')
885 });
886 clipboardModal.on('success', onCopySuccess);
887 }
888 var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
889 var mailtoRegex = new RegExp(/^mailto:/);
890 var filterRegex = new RegExp("https:\/\/github\.com\/your-org\/atdata");
891 var isInternal = (href) => {
892 return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
893 }
894 // Inspect non-navigation links and adorn them if external
895 var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
896 for (var i=0; i<links.length; i++) {
897 const link = links[i];
898 if (!isInternal(link.href)) {
899 // undo the damage that might have been done by quarto-nav.js in the case of
900 // links that we want to consider external
901 if (link.dataset.originalHref !== undefined) {
902 link.href = link.dataset.originalHref;
903 }
904 }
905 }
906 function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
907 const config = {
908 allowHTML: true,
909 maxWidth: 500,
910 delay: 100,
911 arrow: false,
912 appendTo: function(el) {
913 return el.parentElement;
914 },
915 interactive: true,
916 interactiveBorder: 10,
917 theme: 'quarto',
918 placement: 'bottom-start',
919 };
920 if (contentFn) {
921 config.content = contentFn;
922 }
923 if (onTriggerFn) {
924 config.onTrigger = onTriggerFn;
925 }
926 if (onUntriggerFn) {
927 config.onUntrigger = onUntriggerFn;
928 }
929 window.tippy(el, config);
930 }
931 const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
932 for (var i=0; i<noterefs.length; i++) {
933 const ref = noterefs[i];
934 tippyHover(ref, function() {
935 // use id or data attribute instead here
936 let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
937 try { href = new URL(href).hash; } catch {}
938 const id = href.replace(/^#\/?/, "");
939 const note = window.document.getElementById(id);
940 if (note) {
941 return note.innerHTML;
942 } else {
943 return "";
944 }
945 });
946 }
947 const xrefs = window.document.querySelectorAll('a.quarto-xref');
948 const processXRef = (id, note) => {
949 // Strip column container classes
950 const stripColumnClz = (el) => {
951 el.classList.remove("page-full", "page-columns");
952 if (el.children) {
953 for (const child of el.children) {
954 stripColumnClz(child);
955 }
956 }
957 }
958 stripColumnClz(note)
959 if (id === null || id.startsWith('sec-')) {
960 // Special case sections, only their first couple elements
961 const container = document.createElement("div");
962 if (note.children && note.children.length > 2) {
963 container.appendChild(note.children[0].cloneNode(true));
964 for (let i = 1; i < note.children.length; i++) {
965 const child = note.children[i];
966 if (child.tagName === "P" && child.innerText === "") {
967 continue;
968 } else {
969 container.appendChild(child.cloneNode(true));
970 break;
971 }
972 }
973 if (window.Quarto?.typesetMath) {
974 window.Quarto.typesetMath(container);
975 }
976 return container.innerHTML
977 } else {
978 if (window.Quarto?.typesetMath) {
979 window.Quarto.typesetMath(note);
980 }
981 return note.innerHTML;
982 }
983 } else {
984 // Remove any anchor links if they are present
985 const anchorLink = note.querySelector('a.anchorjs-link');
986 if (anchorLink) {
987 anchorLink.remove();
988 }
989 if (window.Quarto?.typesetMath) {
990 window.Quarto.typesetMath(note);
991 }
992 if (note.classList.contains("callout")) {
993 return note.outerHTML;
994 } else {
995 return note.innerHTML;
996 }
997 }
998 }
999 for (var i=0; i<xrefs.length; i++) {
1000 const xref = xrefs[i];
1001 tippyHover(xref, undefined, function(instance) {
1002 instance.disable();
1003 let url = xref.getAttribute('href');
1004 let hash = undefined;
1005 if (url.startsWith('#')) {
1006 hash = url;
1007 } else {
1008 try { hash = new URL(url).hash; } catch {}
1009 }
1010 if (hash) {
1011 const id = hash.replace(/^#\/?/, "");
1012 const note = window.document.getElementById(id);
1013 if (note !== null) {
1014 try {
1015 const html = processXRef(id, note.cloneNode(true));
1016 instance.setContent(html);
1017 } finally {
1018 instance.enable();
1019 instance.show();
1020 }
1021 } else {
1022 // See if we can fetch this
1023 fetch(url.split('#')[0])
1024 .then(res => res.text())
1025 .then(html => {
1026 const parser = new DOMParser();
1027 const htmlDoc = parser.parseFromString(html, "text/html");
1028 const note = htmlDoc.getElementById(id);
1029 if (note !== null) {
1030 const html = processXRef(id, note);
1031 instance.setContent(html);
1032 }
1033 }).finally(() => {
1034 instance.enable();
1035 instance.show();
1036 });
1037 }
1038 } else {
1039 // See if we can fetch a full url (with no hash to target)
1040 // This is a special case and we should probably do some content thinning / targeting
1041 fetch(url)
1042 .then(res => res.text())
1043 .then(html => {
1044 const parser = new DOMParser();
1045 const htmlDoc = parser.parseFromString(html, "text/html");
1046 const note = htmlDoc.querySelector('main.content');
1047 if (note !== null) {
1048 // This should only happen for chapter cross references
1049 // (since there is no id in the URL)
1050 // remove the first header
1051 if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
1052 note.children[0].remove();
1053 }
1054 const html = processXRef(null, note);
1055 instance.setContent(html);
1056 }
1057 }).finally(() => {
1058 instance.enable();
1059 instance.show();
1060 });
1061 }
1062 }, function(instance) {
1063 });
1064 }
1065 let selectedAnnoteEl;
1066 const selectorForAnnotation = ( cell, annotation) => {
1067 let cellAttr = 'data-code-cell="' + cell + '"';
1068 let lineAttr = 'data-code-annotation="' + annotation + '"';
1069 const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
1070 return selector;
1071 }
1072 const selectCodeLines = (annoteEl) => {
1073 const doc = window.document;
1074 const targetCell = annoteEl.getAttribute("data-target-cell");
1075 const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
1076 const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
1077 const lines = annoteSpan.getAttribute("data-code-lines").split(",");
1078 const lineIds = lines.map((line) => {
1079 return targetCell + "-" + line;
1080 })
1081 let top = null;
1082 let height = null;
1083 let parent = null;
1084 if (lineIds.length > 0) {
1085 //compute the position of the single el (top and bottom and make a div)
1086 const el = window.document.getElementById(lineIds[0]);
1087 top = el.offsetTop;
1088 height = el.offsetHeight;
1089 parent = el.parentElement.parentElement;
1090 if (lineIds.length > 1) {
1091 const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
1092 const bottom = lastEl.offsetTop + lastEl.offsetHeight;
1093 height = bottom - top;
1094 }
1095 if (top !== null && height !== null && parent !== null) {
1096 // cook up a div (if necessary) and position it
1097 let div = window.document.getElementById("code-annotation-line-highlight");
1098 if (div === null) {
1099 div = window.document.createElement("div");
1100 div.setAttribute("id", "code-annotation-line-highlight");
1101 div.style.position = 'absolute';
1102 parent.appendChild(div);
1103 }
1104 div.style.top = top - 2 + "px";
1105 div.style.height = height + 4 + "px";
1106 div.style.left = 0;
1107 let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
1108 if (gutterDiv === null) {
1109 gutterDiv = window.document.createElement("div");
1110 gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
1111 gutterDiv.style.position = 'absolute';
1112 const codeCell = window.document.getElementById(targetCell);
1113 const gutter = codeCell.querySelector('.code-annotation-gutter');
1114 gutter.appendChild(gutterDiv);
1115 }
1116 gutterDiv.style.top = top - 2 + "px";
1117 gutterDiv.style.height = height + 4 + "px";
1118 }
1119 selectedAnnoteEl = annoteEl;
1120 }
1121 };
1122 const unselectCodeLines = () => {
1123 const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
1124 elementsIds.forEach((elId) => {
1125 const div = window.document.getElementById(elId);
1126 if (div) {
1127 div.remove();
1128 }
1129 });
1130 selectedAnnoteEl = undefined;
1131 };
1132 // Handle positioning of the toggle
1133 window.addEventListener(
1134 "resize",
1135 throttle(() => {
1136 elRect = undefined;
1137 if (selectedAnnoteEl) {
1138 selectCodeLines(selectedAnnoteEl);
1139 }
1140 }, 10)
1141 );
1142 function throttle(fn, ms) {
1143 let throttle = false;
1144 let timer;
1145 return (...args) => {
1146 if(!throttle) { // first call gets through
1147 fn.apply(this, args);
1148 throttle = true;
1149 } else { // all the others get throttled
1150 if(timer) clearTimeout(timer); // cancel #2
1151 timer = setTimeout(() => {
1152 fn.apply(this, args);
1153 timer = throttle = false;
1154 }, ms);
1155 }
1156 };
1157 }
1158 // Attach click handler to the DT
1159 const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
1160 for (const annoteDlNode of annoteDls) {
1161 annoteDlNode.addEventListener('click', (event) => {
1162 const clickedEl = event.target;
1163 if (clickedEl !== selectedAnnoteEl) {
1164 unselectCodeLines();
1165 const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
1166 if (activeEl) {
1167 activeEl.classList.remove('code-annotation-active');
1168 }
1169 selectCodeLines(clickedEl);
1170 clickedEl.classList.add('code-annotation-active');
1171 } else {
1172 // Unselect the line
1173 unselectCodeLines();
1174 clickedEl.classList.remove('code-annotation-active');
1175 }
1176 });
1177 }
1178 const findCites = (el) => {
1179 const parentEl = el.parentElement;
1180 if (parentEl) {
1181 const cites = parentEl.dataset.cites;
1182 if (cites) {
1183 return {
1184 el,
1185 cites: cites.split(' ')
1186 };
1187 } else {
1188 return findCites(el.parentElement)
1189 }
1190 } else {
1191 return undefined;
1192 }
1193 };
1194 var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
1195 for (var i=0; i<bibliorefs.length; i++) {
1196 const ref = bibliorefs[i];
1197 const citeInfo = findCites(ref);
1198 if (citeInfo) {
1199 tippyHover(citeInfo.el, function() {
1200 var popup = window.document.createElement('div');
1201 citeInfo.cites.forEach(function(cite) {
1202 var citeDiv = window.document.createElement('div');
1203 citeDiv.classList.add('hanging-indent');
1204 citeDiv.classList.add('csl-entry');
1205 var biblioDiv = window.document.getElementById('ref-' + cite);
1206 if (biblioDiv) {
1207 citeDiv.innerHTML = biblioDiv.innerHTML;
1208 }
1209 popup.appendChild(citeDiv);
1210 });
1211 return popup.innerHTML;
1212 });
1213 }
1214 }
1215 });
1216 </script>
1217</div> <!-- /content -->
1218<footer class="footer">
1219 <div class="nav-footer">
1220 <div class="nav-footer-left">
1221<p>Built with <a href="https://quarto.org/">Quarto</a></p>
1222</div>
1223 <div class="nav-footer-center">
1224
1225 <div class="toc-actions d-sm-block d-md-none"><ul><li><a href="https://github.com/your-org/atdata/edit/main/reference/packable-samples.qmd" class="toc-action"><i class="bi bi-github"></i>Edit this page</a></li><li><a href="https://github.com/your-org/atdata/issues/new" class="toc-action"><i class="bi empty"></i>Report an issue</a></li></ul></div></div>
1226 <div class="nav-footer-right">
1227<p>MIT License</p>
1228</div>
1229 </div>
1230</footer>
1231
1232
1233
1234
1235</body></html>