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="Redis + S3 backend for dataset management">
10
11<title>Local Storage – 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/local-storage.html">Local Storage</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">
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 active">
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="#overview" id="toc-overview" class="nav-link active" data-scroll-target="#overview">Overview</a></li>
546 <li><a href="#localindex" id="toc-localindex" class="nav-link" data-scroll-target="#localindex">LocalIndex</a>
547 <ul class="collapse">
548 <li><a href="#adding-entries" id="toc-adding-entries" class="nav-link" data-scroll-target="#adding-entries">Adding Entries</a></li>
549 <li><a href="#listing-and-retrieving" id="toc-listing-and-retrieving" class="nav-link" data-scroll-target="#listing-and-retrieving">Listing and Retrieving</a></li>
550 </ul></li>
551 <li><a href="#repo-deprecated" id="toc-repo-deprecated" class="nav-link" data-scroll-target="#repo-deprecated">Repo (Deprecated)</a>
552 <ul class="collapse">
553 <li><a href="#credentials-file-format" id="toc-credentials-file-format" class="nav-link" data-scroll-target="#credentials-file-format">Credentials File Format</a></li>
554 <li><a href="#inserting-datasets" id="toc-inserting-datasets" class="nav-link" data-scroll-target="#inserting-datasets">Inserting Datasets</a></li>
555 <li><a href="#insert-options" id="toc-insert-options" class="nav-link" data-scroll-target="#insert-options">Insert Options</a></li>
556 </ul></li>
557 <li><a href="#localdatasetentry" id="toc-localdatasetentry" class="nav-link" data-scroll-target="#localdatasetentry">LocalDatasetEntry</a></li>
558 <li><a href="#schema-storage" id="toc-schema-storage" class="nav-link" data-scroll-target="#schema-storage">Schema Storage</a></li>
559 <li><a href="#s3datastore" id="toc-s3datastore" class="nav-link" data-scroll-target="#s3datastore">S3DataStore</a></li>
560 <li><a href="#complete-workflow-example" id="toc-complete-workflow-example" class="nav-link" data-scroll-target="#complete-workflow-example">Complete Workflow Example</a></li>
561 <li><a href="#related" id="toc-related" class="nav-link" data-scroll-target="#related">Related</a></li>
562 </ul>
563<div class="toc-actions"><ul><li><a href="https://github.com/your-org/atdata/edit/main/reference/local-storage.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>
564 </div>
565<!-- main -->
566<main class="content" id="quarto-document-content">
567
568
569<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/local-storage.html">Local Storage</a></li></ol></nav>
570<div class="quarto-title">
571<h1 class="title">Local Storage</h1>
572</div>
573
574<div>
575 <div class="description">
576 Redis + S3 backend for dataset management
577 </div>
578</div>
579
580
581<div class="quarto-title-meta">
582
583
584
585
586 </div>
587
588
589
590</header>
591
592
593<p>The local storage module provides a Redis + S3 backend for storing and managing datasets before publishing to the ATProto federation.</p>
594<section id="overview" class="level2">
595<h2 class="anchored" data-anchor-id="overview">Overview</h2>
596<p>Local storage uses:</p>
597<ul>
598<li><strong>Redis</strong> for indexing and tracking dataset metadata</li>
599<li><strong>S3-compatible storage</strong> for dataset tar files</li>
600</ul>
601<p>This enables development and small-scale deployment before promoting to the full ATProto infrastructure.</p>
602</section>
603<section id="localindex" class="level2">
604<h2 class="anchored" data-anchor-id="localindex">LocalIndex</h2>
605<p>The index tracks datasets in Redis:</p>
606<div id="3120faf0" class="cell">
607<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">from</span> atdata.local <span class="im">import</span> LocalIndex</span>
608<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
609<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Default connection (localhost:6379)</span></span>
610<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>index <span class="op">=</span> LocalIndex()</span>
611<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a></span>
612<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="co"># Custom Redis connection</span></span>
613<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> redis</span>
614<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a>r <span class="op">=</span> redis.Redis(host<span class="op">=</span><span class="st">'custom-host'</span>, port<span class="op">=</span><span class="dv">6379</span>)</span>
615<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a>index <span class="op">=</span> LocalIndex(redis<span class="op">=</span>r)</span>
616<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a></span>
617<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="co"># With connection kwargs</span></span>
618<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a>index <span class="op">=</span> LocalIndex(host<span class="op">=</span><span class="st">'custom-host'</span>, port<span class="op">=</span><span class="dv">6379</span>, db<span class="op">=</span><span class="dv">1</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
619</div>
620<section id="adding-entries" class="level3">
621<h3 class="anchored" data-anchor-id="adding-entries">Adding Entries</h3>
622<div id="53371db7" class="cell">
623<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="im">import</span> atdata</span>
624<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> numpy.typing <span class="im">import</span> NDArray</span>
625<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span>
626<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="at">@atdata.packable</span></span>
627<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="kw">class</span> ImageSample:</span>
628<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> image: NDArray</span>
629<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> label: <span class="bu">str</span></span>
630<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a></span>
631<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a>dataset <span class="op">=</span> atdata.Dataset[ImageSample](<span class="st">"data-{000000..000009}.tar"</span>)</span>
632<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a></span>
633<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a>entry <span class="op">=</span> index.add_entry(</span>
634<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> dataset,</span>
635<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> name<span class="op">=</span><span class="st">"my-dataset"</span>,</span>
636<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a> schema_ref<span class="op">=</span><span class="st">"atdata://local/sampleSchema/ImageSample@1.0.0"</span>, <span class="co"># optional</span></span>
637<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a> metadata<span class="op">=</span>{<span class="st">"description"</span>: <span class="st">"Training images"</span>}, <span class="co"># optional</span></span>
638<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a>)</span>
639<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a></span>
640<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(entry.cid) <span class="co"># Content identifier</span></span>
641<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(entry.name) <span class="co"># "my-dataset"</span></span>
642<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(entry.data_urls) <span class="co"># ["data-{000000..000009}.tar"]</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
643</div>
644</section>
645<section id="listing-and-retrieving" class="level3">
646<h3 class="anchored" data-anchor-id="listing-and-retrieving">Listing and Retrieving</h3>
647<div id="e5edf2cd" class="cell">
648<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="co"># Iterate all entries</span></span>
649<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> entry <span class="kw">in</span> index.entries:</span>
650<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f"</span><span class="sc">{</span>entry<span class="sc">.</span>name<span class="sc">}</span><span class="ss">: </span><span class="sc">{</span>entry<span class="sc">.</span>cid<span class="sc">}</span><span class="ss">"</span>)</span>
651<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
652<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Get as list</span></span>
653<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>all_entries <span class="op">=</span> index.all_entries</span>
654<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a></span>
655<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="co"># Get by name</span></span>
656<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a>entry <span class="op">=</span> index.get_entry_by_name(<span class="st">"my-dataset"</span>)</span>
657<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a></span>
658<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Get by CID</span></span>
659<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a>entry <span class="op">=</span> index.get_entry(<span class="st">"bafyrei..."</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
660</div>
661</section>
662</section>
663<section id="repo-deprecated" class="level2">
664<h2 class="anchored" data-anchor-id="repo-deprecated">Repo (Deprecated)</h2>
665<div class="callout callout-style-default callout-warning callout-titled">
666<div class="callout-header d-flex align-content-center">
667<div class="callout-icon-container">
668<i class="callout-icon"></i>
669</div>
670<div class="callout-title-container flex-fill">
671Warning
672</div>
673</div>
674<div class="callout-body-container callout-body">
675<p><code>Repo</code> is deprecated. Use <code>LocalIndex</code> with <code>S3DataStore</code> instead for new code.</p>
676</div>
677</div>
678<p>The Repo class combines S3 storage with Redis indexing:</p>
679<div id="57c27198" class="cell">
680<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="im">from</span> atdata.local <span class="im">import</span> Repo</span>
681<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
682<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="co"># From credentials file</span></span>
683<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>repo <span class="op">=</span> Repo(</span>
684<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> s3_credentials<span class="op">=</span><span class="st">"path/to/.env"</span>,</span>
685<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> hive_path<span class="op">=</span><span class="st">"my-bucket/datasets"</span>,</span>
686<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>)</span>
687<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a></span>
688<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a><span class="co"># From credentials dict</span></span>
689<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a>repo <span class="op">=</span> Repo(</span>
690<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a> s3_credentials<span class="op">=</span>{</span>
691<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a> <span class="st">"AWS_ENDPOINT"</span>: <span class="st">"http://localhost:9000"</span>,</span>
692<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a> <span class="st">"AWS_ACCESS_KEY_ID"</span>: <span class="st">"minioadmin"</span>,</span>
693<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a> <span class="st">"AWS_SECRET_ACCESS_KEY"</span>: <span class="st">"minioadmin"</span>,</span>
694<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a> },</span>
695<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a> hive_path<span class="op">=</span><span class="st">"my-bucket/datasets"</span>,</span>
696<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
697</div>
698<p><strong>Preferred approach</strong> - Use <code>LocalIndex</code> with <code>S3DataStore</code>:</p>
699<div id="9ddadfba" class="cell">
700<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><span class="im">from</span> atdata.local <span class="im">import</span> LocalIndex, S3DataStore</span>
701<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a></span>
702<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>store <span class="op">=</span> S3DataStore(</span>
703<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> credentials<span class="op">=</span>{</span>
704<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="st">"AWS_ENDPOINT"</span>: <span class="st">"http://localhost:9000"</span>,</span>
705<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <span class="st">"AWS_ACCESS_KEY_ID"</span>: <span class="st">"minioadmin"</span>,</span>
706<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="st">"AWS_SECRET_ACCESS_KEY"</span>: <span class="st">"minioadmin"</span>,</span>
707<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> },</span>
708<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> bucket<span class="op">=</span><span class="st">"my-bucket"</span>,</span>
709<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a>)</span>
710<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a>index <span class="op">=</span> LocalIndex(data_store<span class="op">=</span>store)</span>
711<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a></span>
712<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a><span class="co"># Insert dataset</span></span>
713<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a>entry <span class="op">=</span> index.insert_dataset(dataset, name<span class="op">=</span><span class="st">"my-dataset"</span>, prefix<span class="op">=</span><span class="st">"datasets/v1"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
714</div>
715<section id="credentials-file-format" class="level3">
716<h3 class="anchored" data-anchor-id="credentials-file-format">Credentials File Format</h3>
717<p>The <code>.env</code> file should contain:</p>
718<div class="sourceCode" id="cb6"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="va">AWS_ENDPOINT</span><span class="op">=</span>http://localhost:9000</span>
719<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="va">AWS_ACCESS_KEY_ID</span><span class="op">=</span>your-access-key</span>
720<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="va">AWS_SECRET_ACCESS_KEY</span><span class="op">=</span>your-secret-key</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
721<div class="callout callout-style-default callout-note callout-titled">
722<div class="callout-header d-flex align-content-center">
723<div class="callout-icon-container">
724<i class="callout-icon"></i>
725</div>
726<div class="callout-title-container flex-fill">
727Note
728</div>
729</div>
730<div class="callout-body-container callout-body">
731<p>For AWS S3, omit <code>AWS_ENDPOINT</code> to use the default endpoint.</p>
732</div>
733</div>
734</section>
735<section id="inserting-datasets" class="level3">
736<h3 class="anchored" data-anchor-id="inserting-datasets">Inserting Datasets</h3>
737<div id="7041abcb" class="cell">
738<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><span class="im">import</span> webdataset <span class="im">as</span> wds</span>
739<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np</span>
740<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a></span>
741<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Create dataset from samples</span></span>
742<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a>samples <span class="op">=</span> [ImageSample(</span>
743<span id="cb7-6"><a href="#cb7-6" 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>
744<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a> label<span class="op">=</span><span class="ss">f"sample_</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">"</span></span>
745<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a>) <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">1000</span>)]</span>
746<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a></span>
747<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a><span class="cf">with</span> wds.writer.TarWriter(<span class="st">"temp.tar"</span>) <span class="im">as</span> sink:</span>
748<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> i, s <span class="kw">in</span> <span class="bu">enumerate</span>(samples):</span>
749<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a> sink.write({<span class="op">**</span>s.as_wds, <span class="st">"__key__"</span>: <span class="ss">f"</span><span class="sc">{</span>i<span class="sc">:06d}</span><span class="ss">"</span>})</span>
750<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a></span>
751<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a>dataset <span class="op">=</span> atdata.Dataset[ImageSample](<span class="st">"temp.tar"</span>)</span>
752<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a></span>
753<span id="cb7-16"><a href="#cb7-16" aria-hidden="true" tabindex="-1"></a><span class="co"># Insert into repo (writes to S3 + indexes in Redis)</span></span>
754<span id="cb7-17"><a href="#cb7-17" aria-hidden="true" tabindex="-1"></a>entry, stored_dataset <span class="op">=</span> repo.insert(</span>
755<span id="cb7-18"><a href="#cb7-18" aria-hidden="true" tabindex="-1"></a> dataset,</span>
756<span id="cb7-19"><a href="#cb7-19" aria-hidden="true" tabindex="-1"></a> name<span class="op">=</span><span class="st">"training-images-v1"</span>,</span>
757<span id="cb7-20"><a href="#cb7-20" aria-hidden="true" tabindex="-1"></a> cache_local<span class="op">=</span><span class="va">False</span>, <span class="co"># Stream directly to S3</span></span>
758<span id="cb7-21"><a href="#cb7-21" aria-hidden="true" tabindex="-1"></a>)</span>
759<span id="cb7-22"><a href="#cb7-22" aria-hidden="true" tabindex="-1"></a></span>
760<span id="cb7-23"><a href="#cb7-23" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(entry.cid) <span class="co"># Content identifier</span></span>
761<span id="cb7-24"><a href="#cb7-24" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(stored_dataset.url) <span class="co"># S3 URL for the stored data</span></span>
762<span id="cb7-25"><a href="#cb7-25" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(stored_dataset.shard_list) <span class="co"># Individual shard URLs</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
763</div>
764</section>
765<section id="insert-options" class="level3">
766<h3 class="anchored" data-anchor-id="insert-options">Insert Options</h3>
767<div id="4f123ba3" class="cell">
768<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>entry, ds <span class="op">=</span> repo.insert(</span>
769<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> dataset,</span>
770<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> name<span class="op">=</span><span class="st">"my-dataset"</span>,</span>
771<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> cache_local<span class="op">=</span><span class="va">True</span>, <span class="co"># Write locally first, then copy (faster for some workloads)</span></span>
772<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> maxcount<span class="op">=</span><span class="dv">10000</span>, <span class="co"># Samples per shard</span></span>
773<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a> maxsize<span class="op">=</span><span class="dv">100_000_000</span>, <span class="co"># Max shard size in bytes</span></span>
774<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
775</div>
776</section>
777</section>
778<section id="localdatasetentry" class="level2">
779<h2 class="anchored" data-anchor-id="localdatasetentry">LocalDatasetEntry</h2>
780<p>Index entries provide content-addressable identification:</p>
781<div id="0d213b56" class="cell">
782<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>entry <span class="op">=</span> index.get_entry_by_name(<span class="st">"my-dataset"</span>)</span>
783<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a></span>
784<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Core properties (IndexEntry protocol)</span></span>
785<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a>entry.name <span class="co"># Human-readable name</span></span>
786<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a>entry.schema_ref <span class="co"># Schema reference</span></span>
787<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a>entry.data_urls <span class="co"># WebDataset URLs</span></span>
788<span id="cb9-7"><a href="#cb9-7" aria-hidden="true" tabindex="-1"></a>entry.metadata <span class="co"># Arbitrary metadata dict or None</span></span>
789<span id="cb9-8"><a href="#cb9-8" aria-hidden="true" tabindex="-1"></a></span>
790<span id="cb9-9"><a href="#cb9-9" aria-hidden="true" tabindex="-1"></a><span class="co"># Content addressing</span></span>
791<span id="cb9-10"><a href="#cb9-10" aria-hidden="true" tabindex="-1"></a>entry.cid <span class="co"># ATProto-compatible CID (content identifier)</span></span>
792<span id="cb9-11"><a href="#cb9-11" aria-hidden="true" tabindex="-1"></a></span>
793<span id="cb9-12"><a href="#cb9-12" aria-hidden="true" tabindex="-1"></a><span class="co"># Legacy compatibility</span></span>
794<span id="cb9-13"><a href="#cb9-13" aria-hidden="true" tabindex="-1"></a>entry.wds_url <span class="co"># First data URL</span></span>
795<span id="cb9-14"><a href="#cb9-14" aria-hidden="true" tabindex="-1"></a>entry.sample_kind <span class="co"># Same as schema_ref</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
796</div>
797<div class="callout callout-style-default callout-tip callout-titled">
798<div class="callout-header d-flex align-content-center">
799<div class="callout-icon-container">
800<i class="callout-icon"></i>
801</div>
802<div class="callout-title-container flex-fill">
803Tip
804</div>
805</div>
806<div class="callout-body-container callout-body">
807<p>The CID is generated from the entry’s content (schema_ref + data_urls), ensuring identical data produces identical CIDs whether stored locally or in the atmosphere.</p>
808</div>
809</div>
810</section>
811<section id="schema-storage" class="level2">
812<h2 class="anchored" data-anchor-id="schema-storage">Schema Storage</h2>
813<p>Schemas can be stored and retrieved from the index:</p>
814<div id="2e22c50d" class="cell">
815<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="co"># Publish a schema</span></span>
816<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a>schema_ref <span class="op">=</span> index.publish_schema(</span>
817<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> ImageSample,</span>
818<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> version<span class="op">=</span><span class="st">"1.0.0"</span>,</span>
819<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a> description<span class="op">=</span><span class="st">"Image with label annotation"</span>,</span>
820<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a>)</span>
821<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Returns: "atdata://local/sampleSchema/ImageSample@1.0.0"</span></span>
822<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a></span>
823<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a><span class="co"># Retrieve schema record</span></span>
824<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a>schema <span class="op">=</span> index.get_schema(schema_ref)</span>
825<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a><span class="co"># {</span></span>
826<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a><span class="co"># "name": "ImageSample",</span></span>
827<span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a><span class="co"># "version": "1.0.0",</span></span>
828<span id="cb10-14"><a href="#cb10-14" aria-hidden="true" tabindex="-1"></a><span class="co"># "fields": [...],</span></span>
829<span id="cb10-15"><a href="#cb10-15" aria-hidden="true" tabindex="-1"></a><span class="co"># "description": "...",</span></span>
830<span id="cb10-16"><a href="#cb10-16" aria-hidden="true" tabindex="-1"></a><span class="co"># "createdAt": "...",</span></span>
831<span id="cb10-17"><a href="#cb10-17" aria-hidden="true" tabindex="-1"></a><span class="co"># }</span></span>
832<span id="cb10-18"><a href="#cb10-18" aria-hidden="true" tabindex="-1"></a></span>
833<span id="cb10-19"><a href="#cb10-19" aria-hidden="true" tabindex="-1"></a><span class="co"># List all schemas</span></span>
834<span id="cb10-20"><a href="#cb10-20" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> schema <span class="kw">in</span> index.list_schemas():</span>
835<span id="cb10-21"><a href="#cb10-21" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f"</span><span class="sc">{</span>schema[<span class="st">'name'</span>]<span class="sc">}</span><span class="ss">@</span><span class="sc">{</span>schema[<span class="st">'version'</span>]<span class="sc">}</span><span class="ss">"</span>)</span>
836<span id="cb10-22"><a href="#cb10-22" aria-hidden="true" tabindex="-1"></a></span>
837<span id="cb10-23"><a href="#cb10-23" aria-hidden="true" tabindex="-1"></a><span class="co"># Reconstruct sample type from schema</span></span>
838<span id="cb10-24"><a href="#cb10-24" aria-hidden="true" tabindex="-1"></a>SampleType <span class="op">=</span> index.decode_schema(schema_ref)</span>
839<span id="cb10-25"><a href="#cb10-25" aria-hidden="true" tabindex="-1"></a>dataset <span class="op">=</span> atdata.Dataset[SampleType](entry.data_urls[<span class="dv">0</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
840</div>
841</section>
842<section id="s3datastore" class="level2">
843<h2 class="anchored" data-anchor-id="s3datastore">S3DataStore</h2>
844<p>For direct S3 operations without Redis indexing:</p>
845<div id="3fe31407" class="cell">
846<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="im">from</span> atdata.local <span class="im">import</span> S3DataStore</span>
847<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a></span>
848<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>store <span class="op">=</span> S3DataStore(</span>
849<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> credentials<span class="op">=</span><span class="st">"path/to/.env"</span>,</span>
850<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> bucket<span class="op">=</span><span class="st">"my-bucket"</span>,</span>
851<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a>)</span>
852<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a></span>
853<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a><span class="co"># Write dataset shards</span></span>
854<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a>urls <span class="op">=</span> store.write_shards(</span>
855<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a> dataset,</span>
856<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a> prefix<span class="op">=</span><span class="st">"datasets/v1"</span>,</span>
857<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a> maxcount<span class="op">=</span><span class="dv">10000</span>,</span>
858<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a>)</span>
859<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a><span class="co"># Returns: ["s3://my-bucket/datasets/v1/data--uuid--000000.tar", ...]</span></span>
860<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a></span>
861<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a><span class="co"># Check capabilities</span></span>
862<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a>store.supports_streaming() <span class="co"># True</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
863</div>
864</section>
865<section id="complete-workflow-example" class="level2">
866<h2 class="anchored" data-anchor-id="complete-workflow-example">Complete Workflow Example</h2>
867<div id="42ed52ed" class="cell">
868<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="im">import</span> numpy <span class="im">as</span> np</span>
869<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> numpy.typing <span class="im">import</span> NDArray</span>
870<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> atdata</span>
871<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> atdata.local <span class="im">import</span> LocalIndex, S3DataStore</span>
872<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> webdataset <span class="im">as</span> wds</span>
873<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a></span>
874<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a><span class="co"># 1. Define sample type</span></span>
875<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a><span class="at">@atdata.packable</span></span>
876<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a><span class="kw">class</span> TrainingSample:</span>
877<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a> features: NDArray</span>
878<span id="cb12-11"><a href="#cb12-11" aria-hidden="true" tabindex="-1"></a> label: <span class="bu">int</span></span>
879<span id="cb12-12"><a href="#cb12-12" aria-hidden="true" tabindex="-1"></a> source: <span class="bu">str</span></span>
880<span id="cb12-13"><a href="#cb12-13" aria-hidden="true" tabindex="-1"></a></span>
881<span id="cb12-14"><a href="#cb12-14" aria-hidden="true" tabindex="-1"></a><span class="co"># 2. Create samples</span></span>
882<span id="cb12-15"><a href="#cb12-15" aria-hidden="true" tabindex="-1"></a>samples <span class="op">=</span> [</span>
883<span id="cb12-16"><a href="#cb12-16" aria-hidden="true" tabindex="-1"></a> TrainingSample(</span>
884<span id="cb12-17"><a href="#cb12-17" aria-hidden="true" tabindex="-1"></a> features<span class="op">=</span>np.random.randn(<span class="dv">128</span>).astype(np.float32),</span>
885<span id="cb12-18"><a href="#cb12-18" aria-hidden="true" tabindex="-1"></a> label<span class="op">=</span>i <span class="op">%</span> <span class="dv">10</span>,</span>
886<span id="cb12-19"><a href="#cb12-19" aria-hidden="true" tabindex="-1"></a> source<span class="op">=</span><span class="st">"synthetic"</span>,</span>
887<span id="cb12-20"><a href="#cb12-20" aria-hidden="true" tabindex="-1"></a> )</span>
888<span id="cb12-21"><a href="#cb12-21" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">10000</span>)</span>
889<span id="cb12-22"><a href="#cb12-22" aria-hidden="true" tabindex="-1"></a>]</span>
890<span id="cb12-23"><a href="#cb12-23" aria-hidden="true" tabindex="-1"></a></span>
891<span id="cb12-24"><a href="#cb12-24" aria-hidden="true" tabindex="-1"></a><span class="co"># 3. Write to local tar</span></span>
892<span id="cb12-25"><a href="#cb12-25" aria-hidden="true" tabindex="-1"></a><span class="cf">with</span> wds.writer.TarWriter(<span class="st">"local-data.tar"</span>) <span class="im">as</span> sink:</span>
893<span id="cb12-26"><a href="#cb12-26" 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>
894<span id="cb12-27"><a href="#cb12-27" aria-hidden="true" tabindex="-1"></a> sink.write({<span class="op">**</span>sample.as_wds, <span class="st">"__key__"</span>: <span class="ss">f"</span><span class="sc">{</span>i<span class="sc">:06d}</span><span class="ss">"</span>})</span>
895<span id="cb12-28"><a href="#cb12-28" aria-hidden="true" tabindex="-1"></a></span>
896<span id="cb12-29"><a href="#cb12-29" aria-hidden="true" tabindex="-1"></a><span class="co"># 4. Set up index with S3 data store and insert</span></span>
897<span id="cb12-30"><a href="#cb12-30" aria-hidden="true" tabindex="-1"></a>store <span class="op">=</span> S3DataStore(</span>
898<span id="cb12-31"><a href="#cb12-31" aria-hidden="true" tabindex="-1"></a> credentials<span class="op">=</span>{</span>
899<span id="cb12-32"><a href="#cb12-32" aria-hidden="true" tabindex="-1"></a> <span class="st">"AWS_ENDPOINT"</span>: <span class="st">"http://localhost:9000"</span>,</span>
900<span id="cb12-33"><a href="#cb12-33" aria-hidden="true" tabindex="-1"></a> <span class="st">"AWS_ACCESS_KEY_ID"</span>: <span class="st">"minioadmin"</span>,</span>
901<span id="cb12-34"><a href="#cb12-34" aria-hidden="true" tabindex="-1"></a> <span class="st">"AWS_SECRET_ACCESS_KEY"</span>: <span class="st">"minioadmin"</span>,</span>
902<span id="cb12-35"><a href="#cb12-35" aria-hidden="true" tabindex="-1"></a> },</span>
903<span id="cb12-36"><a href="#cb12-36" aria-hidden="true" tabindex="-1"></a> bucket<span class="op">=</span><span class="st">"datasets-bucket"</span>,</span>
904<span id="cb12-37"><a href="#cb12-37" aria-hidden="true" tabindex="-1"></a>)</span>
905<span id="cb12-38"><a href="#cb12-38" aria-hidden="true" tabindex="-1"></a>index <span class="op">=</span> LocalIndex(data_store<span class="op">=</span>store)</span>
906<span id="cb12-39"><a href="#cb12-39" aria-hidden="true" tabindex="-1"></a></span>
907<span id="cb12-40"><a href="#cb12-40" aria-hidden="true" tabindex="-1"></a><span class="co"># Publish schema and insert dataset</span></span>
908<span id="cb12-41"><a href="#cb12-41" aria-hidden="true" tabindex="-1"></a>index.publish_schema(TrainingSample, version<span class="op">=</span><span class="st">"1.0.0"</span>)</span>
909<span id="cb12-42"><a href="#cb12-42" aria-hidden="true" tabindex="-1"></a>local_ds <span class="op">=</span> atdata.Dataset[TrainingSample](<span class="st">"local-data.tar"</span>)</span>
910<span id="cb12-43"><a href="#cb12-43" aria-hidden="true" tabindex="-1"></a>entry <span class="op">=</span> index.insert_dataset(local_ds, name<span class="op">=</span><span class="st">"training-v1"</span>, prefix<span class="op">=</span><span class="st">"training"</span>)</span>
911<span id="cb12-44"><a href="#cb12-44" aria-hidden="true" tabindex="-1"></a></span>
912<span id="cb12-45"><a href="#cb12-45" aria-hidden="true" tabindex="-1"></a><span class="co"># 5. Retrieve later</span></span>
913<span id="cb12-46"><a href="#cb12-46" aria-hidden="true" tabindex="-1"></a>entry <span class="op">=</span> index.get_entry_by_name(<span class="st">"training-v1"</span>)</span>
914<span id="cb12-47"><a href="#cb12-47" aria-hidden="true" tabindex="-1"></a>dataset <span class="op">=</span> atdata.Dataset[TrainingSample](entry.data_urls[<span class="dv">0</span>])</span>
915<span id="cb12-48"><a href="#cb12-48" aria-hidden="true" tabindex="-1"></a></span>
916<span id="cb12-49"><a href="#cb12-49" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> batch <span class="kw">in</span> dataset.ordered(batch_size<span class="op">=</span><span class="dv">32</span>):</span>
917<span id="cb12-50"><a href="#cb12-50" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(batch.features.shape) <span class="co"># (32, 128)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
918</div>
919</section>
920<section id="related" class="level2">
921<h2 class="anchored" data-anchor-id="related">Related</h2>
922<ul>
923<li><a href="../reference/datasets.html">Datasets</a> - Dataset iteration and batching</li>
924<li><a href="../reference/protocols.html">Protocols</a> - AbstractIndex and IndexEntry interfaces</li>
925<li><a href="../reference/promotion.html">Promotion</a> - Promoting local datasets to ATProto</li>
926<li><a href="../reference/atmosphere.html">Atmosphere</a> - ATProto federation</li>
927</ul>
928
929
930</section>
931
932</main> <!-- /main -->
933<script id="quarto-html-after-body" type="application/javascript">
934 window.document.addEventListener("DOMContentLoaded", function (event) {
935 // Ensure there is a toggle, if there isn't float one in the top right
936 if (window.document.querySelector('.quarto-color-scheme-toggle') === null) {
937 const a = window.document.createElement('a');
938 a.classList.add('top-right');
939 a.classList.add('quarto-color-scheme-toggle');
940 a.href = "";
941 a.onclick = function() { try { window.quartoToggleColorScheme(); } catch {} return false; };
942 const i = window.document.createElement("i");
943 i.classList.add('bi');
944 a.appendChild(i);
945 window.document.body.appendChild(a);
946 }
947 setColorSchemeToggle(hasAlternateSentinel())
948 const icon = "";
949 const anchorJS = new window.AnchorJS();
950 anchorJS.options = {
951 placement: 'right',
952 icon: icon
953 };
954 anchorJS.add('.anchored');
955 const isCodeAnnotation = (el) => {
956 for (const clz of el.classList) {
957 if (clz.startsWith('code-annotation-')) {
958 return true;
959 }
960 }
961 return false;
962 }
963 const onCopySuccess = function(e) {
964 // button target
965 const button = e.trigger;
966 // don't keep focus
967 button.blur();
968 // flash "checked"
969 button.classList.add('code-copy-button-checked');
970 var currentTitle = button.getAttribute("title");
971 button.setAttribute("title", "Copied!");
972 let tooltip;
973 if (window.bootstrap) {
974 button.setAttribute("data-bs-toggle", "tooltip");
975 button.setAttribute("data-bs-placement", "left");
976 button.setAttribute("data-bs-title", "Copied!");
977 tooltip = new bootstrap.Tooltip(button,
978 { trigger: "manual",
979 customClass: "code-copy-button-tooltip",
980 offset: [0, -8]});
981 tooltip.show();
982 }
983 setTimeout(function() {
984 if (tooltip) {
985 tooltip.hide();
986 button.removeAttribute("data-bs-title");
987 button.removeAttribute("data-bs-toggle");
988 button.removeAttribute("data-bs-placement");
989 }
990 button.setAttribute("title", currentTitle);
991 button.classList.remove('code-copy-button-checked');
992 }, 1000);
993 // clear code selection
994 e.clearSelection();
995 }
996 const getTextToCopy = function(trigger) {
997 const codeEl = trigger.previousElementSibling.cloneNode(true);
998 for (const childEl of codeEl.children) {
999 if (isCodeAnnotation(childEl)) {
1000 childEl.remove();
1001 }
1002 }
1003 return codeEl.innerText;
1004 }
1005 const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
1006 text: getTextToCopy
1007 });
1008 clipboard.on('success', onCopySuccess);
1009 if (window.document.getElementById('quarto-embedded-source-code-modal')) {
1010 const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
1011 text: getTextToCopy,
1012 container: window.document.getElementById('quarto-embedded-source-code-modal')
1013 });
1014 clipboardModal.on('success', onCopySuccess);
1015 }
1016 var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
1017 var mailtoRegex = new RegExp(/^mailto:/);
1018 var filterRegex = new RegExp("https:\/\/github\.com\/your-org\/atdata");
1019 var isInternal = (href) => {
1020 return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
1021 }
1022 // Inspect non-navigation links and adorn them if external
1023 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)');
1024 for (var i=0; i<links.length; i++) {
1025 const link = links[i];
1026 if (!isInternal(link.href)) {
1027 // undo the damage that might have been done by quarto-nav.js in the case of
1028 // links that we want to consider external
1029 if (link.dataset.originalHref !== undefined) {
1030 link.href = link.dataset.originalHref;
1031 }
1032 }
1033 }
1034 function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
1035 const config = {
1036 allowHTML: true,
1037 maxWidth: 500,
1038 delay: 100,
1039 arrow: false,
1040 appendTo: function(el) {
1041 return el.parentElement;
1042 },
1043 interactive: true,
1044 interactiveBorder: 10,
1045 theme: 'quarto',
1046 placement: 'bottom-start',
1047 };
1048 if (contentFn) {
1049 config.content = contentFn;
1050 }
1051 if (onTriggerFn) {
1052 config.onTrigger = onTriggerFn;
1053 }
1054 if (onUntriggerFn) {
1055 config.onUntrigger = onUntriggerFn;
1056 }
1057 window.tippy(el, config);
1058 }
1059 const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
1060 for (var i=0; i<noterefs.length; i++) {
1061 const ref = noterefs[i];
1062 tippyHover(ref, function() {
1063 // use id or data attribute instead here
1064 let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
1065 try { href = new URL(href).hash; } catch {}
1066 const id = href.replace(/^#\/?/, "");
1067 const note = window.document.getElementById(id);
1068 if (note) {
1069 return note.innerHTML;
1070 } else {
1071 return "";
1072 }
1073 });
1074 }
1075 const xrefs = window.document.querySelectorAll('a.quarto-xref');
1076 const processXRef = (id, note) => {
1077 // Strip column container classes
1078 const stripColumnClz = (el) => {
1079 el.classList.remove("page-full", "page-columns");
1080 if (el.children) {
1081 for (const child of el.children) {
1082 stripColumnClz(child);
1083 }
1084 }
1085 }
1086 stripColumnClz(note)
1087 if (id === null || id.startsWith('sec-')) {
1088 // Special case sections, only their first couple elements
1089 const container = document.createElement("div");
1090 if (note.children && note.children.length > 2) {
1091 container.appendChild(note.children[0].cloneNode(true));
1092 for (let i = 1; i < note.children.length; i++) {
1093 const child = note.children[i];
1094 if (child.tagName === "P" && child.innerText === "") {
1095 continue;
1096 } else {
1097 container.appendChild(child.cloneNode(true));
1098 break;
1099 }
1100 }
1101 if (window.Quarto?.typesetMath) {
1102 window.Quarto.typesetMath(container);
1103 }
1104 return container.innerHTML
1105 } else {
1106 if (window.Quarto?.typesetMath) {
1107 window.Quarto.typesetMath(note);
1108 }
1109 return note.innerHTML;
1110 }
1111 } else {
1112 // Remove any anchor links if they are present
1113 const anchorLink = note.querySelector('a.anchorjs-link');
1114 if (anchorLink) {
1115 anchorLink.remove();
1116 }
1117 if (window.Quarto?.typesetMath) {
1118 window.Quarto.typesetMath(note);
1119 }
1120 if (note.classList.contains("callout")) {
1121 return note.outerHTML;
1122 } else {
1123 return note.innerHTML;
1124 }
1125 }
1126 }
1127 for (var i=0; i<xrefs.length; i++) {
1128 const xref = xrefs[i];
1129 tippyHover(xref, undefined, function(instance) {
1130 instance.disable();
1131 let url = xref.getAttribute('href');
1132 let hash = undefined;
1133 if (url.startsWith('#')) {
1134 hash = url;
1135 } else {
1136 try { hash = new URL(url).hash; } catch {}
1137 }
1138 if (hash) {
1139 const id = hash.replace(/^#\/?/, "");
1140 const note = window.document.getElementById(id);
1141 if (note !== null) {
1142 try {
1143 const html = processXRef(id, note.cloneNode(true));
1144 instance.setContent(html);
1145 } finally {
1146 instance.enable();
1147 instance.show();
1148 }
1149 } else {
1150 // See if we can fetch this
1151 fetch(url.split('#')[0])
1152 .then(res => res.text())
1153 .then(html => {
1154 const parser = new DOMParser();
1155 const htmlDoc = parser.parseFromString(html, "text/html");
1156 const note = htmlDoc.getElementById(id);
1157 if (note !== null) {
1158 const html = processXRef(id, note);
1159 instance.setContent(html);
1160 }
1161 }).finally(() => {
1162 instance.enable();
1163 instance.show();
1164 });
1165 }
1166 } else {
1167 // See if we can fetch a full url (with no hash to target)
1168 // This is a special case and we should probably do some content thinning / targeting
1169 fetch(url)
1170 .then(res => res.text())
1171 .then(html => {
1172 const parser = new DOMParser();
1173 const htmlDoc = parser.parseFromString(html, "text/html");
1174 const note = htmlDoc.querySelector('main.content');
1175 if (note !== null) {
1176 // This should only happen for chapter cross references
1177 // (since there is no id in the URL)
1178 // remove the first header
1179 if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
1180 note.children[0].remove();
1181 }
1182 const html = processXRef(null, note);
1183 instance.setContent(html);
1184 }
1185 }).finally(() => {
1186 instance.enable();
1187 instance.show();
1188 });
1189 }
1190 }, function(instance) {
1191 });
1192 }
1193 let selectedAnnoteEl;
1194 const selectorForAnnotation = ( cell, annotation) => {
1195 let cellAttr = 'data-code-cell="' + cell + '"';
1196 let lineAttr = 'data-code-annotation="' + annotation + '"';
1197 const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
1198 return selector;
1199 }
1200 const selectCodeLines = (annoteEl) => {
1201 const doc = window.document;
1202 const targetCell = annoteEl.getAttribute("data-target-cell");
1203 const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
1204 const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
1205 const lines = annoteSpan.getAttribute("data-code-lines").split(",");
1206 const lineIds = lines.map((line) => {
1207 return targetCell + "-" + line;
1208 })
1209 let top = null;
1210 let height = null;
1211 let parent = null;
1212 if (lineIds.length > 0) {
1213 //compute the position of the single el (top and bottom and make a div)
1214 const el = window.document.getElementById(lineIds[0]);
1215 top = el.offsetTop;
1216 height = el.offsetHeight;
1217 parent = el.parentElement.parentElement;
1218 if (lineIds.length > 1) {
1219 const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
1220 const bottom = lastEl.offsetTop + lastEl.offsetHeight;
1221 height = bottom - top;
1222 }
1223 if (top !== null && height !== null && parent !== null) {
1224 // cook up a div (if necessary) and position it
1225 let div = window.document.getElementById("code-annotation-line-highlight");
1226 if (div === null) {
1227 div = window.document.createElement("div");
1228 div.setAttribute("id", "code-annotation-line-highlight");
1229 div.style.position = 'absolute';
1230 parent.appendChild(div);
1231 }
1232 div.style.top = top - 2 + "px";
1233 div.style.height = height + 4 + "px";
1234 div.style.left = 0;
1235 let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
1236 if (gutterDiv === null) {
1237 gutterDiv = window.document.createElement("div");
1238 gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
1239 gutterDiv.style.position = 'absolute';
1240 const codeCell = window.document.getElementById(targetCell);
1241 const gutter = codeCell.querySelector('.code-annotation-gutter');
1242 gutter.appendChild(gutterDiv);
1243 }
1244 gutterDiv.style.top = top - 2 + "px";
1245 gutterDiv.style.height = height + 4 + "px";
1246 }
1247 selectedAnnoteEl = annoteEl;
1248 }
1249 };
1250 const unselectCodeLines = () => {
1251 const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
1252 elementsIds.forEach((elId) => {
1253 const div = window.document.getElementById(elId);
1254 if (div) {
1255 div.remove();
1256 }
1257 });
1258 selectedAnnoteEl = undefined;
1259 };
1260 // Handle positioning of the toggle
1261 window.addEventListener(
1262 "resize",
1263 throttle(() => {
1264 elRect = undefined;
1265 if (selectedAnnoteEl) {
1266 selectCodeLines(selectedAnnoteEl);
1267 }
1268 }, 10)
1269 );
1270 function throttle(fn, ms) {
1271 let throttle = false;
1272 let timer;
1273 return (...args) => {
1274 if(!throttle) { // first call gets through
1275 fn.apply(this, args);
1276 throttle = true;
1277 } else { // all the others get throttled
1278 if(timer) clearTimeout(timer); // cancel #2
1279 timer = setTimeout(() => {
1280 fn.apply(this, args);
1281 timer = throttle = false;
1282 }, ms);
1283 }
1284 };
1285 }
1286 // Attach click handler to the DT
1287 const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
1288 for (const annoteDlNode of annoteDls) {
1289 annoteDlNode.addEventListener('click', (event) => {
1290 const clickedEl = event.target;
1291 if (clickedEl !== selectedAnnoteEl) {
1292 unselectCodeLines();
1293 const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
1294 if (activeEl) {
1295 activeEl.classList.remove('code-annotation-active');
1296 }
1297 selectCodeLines(clickedEl);
1298 clickedEl.classList.add('code-annotation-active');
1299 } else {
1300 // Unselect the line
1301 unselectCodeLines();
1302 clickedEl.classList.remove('code-annotation-active');
1303 }
1304 });
1305 }
1306 const findCites = (el) => {
1307 const parentEl = el.parentElement;
1308 if (parentEl) {
1309 const cites = parentEl.dataset.cites;
1310 if (cites) {
1311 return {
1312 el,
1313 cites: cites.split(' ')
1314 };
1315 } else {
1316 return findCites(el.parentElement)
1317 }
1318 } else {
1319 return undefined;
1320 }
1321 };
1322 var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
1323 for (var i=0; i<bibliorefs.length; i++) {
1324 const ref = bibliorefs[i];
1325 const citeInfo = findCites(ref);
1326 if (citeInfo) {
1327 tippyHover(citeInfo.el, function() {
1328 var popup = window.document.createElement('div');
1329 citeInfo.cites.forEach(function(cite) {
1330 var citeDiv = window.document.createElement('div');
1331 citeDiv.classList.add('hanging-indent');
1332 citeDiv.classList.add('csl-entry');
1333 var biblioDiv = window.document.getElementById('ref-' + cite);
1334 if (biblioDiv) {
1335 citeDiv.innerHTML = biblioDiv.innerHTML;
1336 }
1337 popup.appendChild(citeDiv);
1338 });
1339 return popup.innerHTML;
1340 });
1341 }
1342 }
1343 });
1344 </script>
1345</div> <!-- /content -->
1346<footer class="footer">
1347 <div class="nav-footer">
1348 <div class="nav-footer-left">
1349<p>Built with <a href="https://quarto.org/">Quarto</a></p>
1350</div>
1351 <div class="nav-footer-center">
1352
1353 <div class="toc-actions d-sm-block d-md-none"><ul><li><a href="https://github.com/your-org/atdata/edit/main/reference/local-storage.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>
1354 <div class="nav-footer-right">
1355<p>MIT License</p>
1356</div>
1357 </div>
1358</footer>
1359
1360
1361
1362
1363</body></html>