things-we-should-build / ideas /038-tiny-paste.md
broadfield's picture
Add idea 038: Tiny Paste (datasets-as-database pastebin)
e4a769e verified
|
Raw History Blame Contribute Delete
2.31 kB

038 · Tiny Paste

title: Tiny Paste — a 10-line pastebin / key-value store, backed by datasets-you-own, 100% free forever status: MVP + live license: MIT

why

HF gives hobbyists something no other free host does: an authenticated LFS-backed key-value store in the form of datasets. Tiny Paste wraps that in a human API: paste("hello") → URL; get(url) → text. No server, no DB, no bill — just a repo, a token, and the Hub API. One small Gradio app can give every user of any Space a "save this" button whose storage costs $0.

what

  • Static-to-Gradio paste page with two modes:
    • Read (no auth): paste a https://huggingface.co/datasets/{you}/tiny-paste/resolve/main/p/abc123.txt URL → text.
    • Write (token in localStorage): POST via hf_upload_repo_file, key = random 6 chars.
  • Optional expiry: cron/dataset hook clears keys older than N days.
  • Namespace per user: any dataset id works ({user}/{anything} for keyspace separation).

plan

  1. Gradio (CPU, free) with gr.Textbox in/out; read via requests to resolve URL.
  2. Write impl: call the Hub upload API with a stored token.
  3. TTL via last_seen repo file + periodic cleanup (#049 cron).
  4. Ship; also expose an HTTP API so other Spaces can use it as their scratch storage.

code

# tiny_paste.py — read/write through the Hub API
import os, random, string, requests

BASE = "https://huggingface.co/datasets/{repo}/resolve/main/p"
def read(key: str) -> str:
    url = f"{BASE}/{key}.txt"
    r = requests.get(url)
    return r.text if r.ok else f"(missing: {key})"

def write(repo: str, token: str, text: str) -> str:
    key = "".join(random.choices(string.ascii_lowercase + string.digits, k=6))
    api = f"https://huggingface.co/api/datasets/{repo}/upload"
    r = requests.post(api, headers={"Authorization": f"Bearer {token}"},
                      json={"path": f"p/{key}.txt", "content": text, "commitMessage": f"paste {key}"})
    return f"https://huggingface.co/datasets/{repo}/resolve/main/p/{key}.txt" if r.ok else r.text

next

  • Signed URLs: HMAC key so only owners can list/delete.
  • Big blobs via LFS (>50MB) with progress bars.
  • Namespace the whole things-we-should-build suite: "save my filter settings" for every Space here, backed by one dataset.