>_ DashByte
Python 3.10+ Stdlib ⏱ 60 Minutes Zero pip Installs

Build a CLI Bookmark & Snippet Vault

Create a fast terminal tool to save, tag, search, and delete useful URLs and commands—persisted locally in a local SQLite database using Python's built-in sqlite3 and argparse modules.

Project Folder Structure

py-bookmark-vault/
├── vault.py      # CLI commands + SQLite CRUD
├── README.md     # Usage examples & flags
└── vault.db      # Auto-created on first run

60-Minute Build Checklist

0 / 5 Done

Check off each milestone as you build. Your progress saves automatically in your browser.

vault.py — Complete Stdlib CLI + SQLite
#!/usr/bin/env python3
"""DashByte 1-Hour Project: CLI Bookmark & Snippet Vault."""

import argparse
import sqlite3
from pathlib import Path

DB_PATH = Path(__file__).parent / "vault.db"


def get_connection() -> sqlite3.Connection:
    conn = sqlite3.connect(DB_PATH)
    conn.row_factory = sqlite3.Row
    conn.execute(
        """
        CREATE TABLE IF NOT EXISTS bookmarks (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            title TEXT NOT NULL,
            url TEXT NOT NULL,
            tag TEXT DEFAULT 'general',
            created_at TEXT DEFAULT CURRENT_TIMESTAMP
        )
        """
    )
    return conn


def add_bookmark(title: str, url: str, tag: str) -> None:
    with get_connection() as conn:
        conn.execute(
            "INSERT INTO bookmarks (title, url, tag) VALUES (?, ?, ?)",
            (title.strip(), url.strip(), tag.strip().lower()),
        )
    print(f"[+] Saved: {title} ({tag})")


def list_bookmarks(query: str | None = None) -> None:
    with get_connection() as conn:
        if query:
            like = f"%{query.strip()}%"
            rows = conn.execute(
                "SELECT * FROM bookmarks WHERE title LIKE ? OR url LIKE ? OR tag LIKE ? ORDER BY id DESC",
                (like, like, like),
            ).fetchall()
        else:
            rows = conn.execute("SELECT * FROM bookmarks ORDER BY id DESC").fetchall()

    if not rows:
        print("No bookmarks found.")
        return

    for row in rows:
        print(f"#{row['id']:<3} [{row['tag']}] {row['title']} -> {row['url']}")


def delete_bookmark(bookmark_id: int) -> None:
    with get_connection() as conn:
        cursor = conn.execute("DELETE FROM bookmarks WHERE id = ?", (bookmark_id,))
    if cursor.rowcount:
        print(f"[-] Deleted bookmark #{bookmark_id}")
    else:
        print(f"[!] Bookmark #{bookmark_id} not found.")


def main() -> None:
    parser = argparse.ArgumentParser(description="CLI Bookmark & Snippet Vault")
    sub = parser.add_subparsers(dest="command", required=True)

    p_add = sub.add_parser("add", help="Add a new bookmark")
    p_add.add_argument("title", help="Short label for the link")
    p_add.add_argument("url", help="URL or command snippet")
    p_add.add_argument("-t", "--tag", default="general", help="Category tag")

    sub.add_parser("list", help="List all saved bookmarks")

    p_search = sub.add_parser("search", help="Search by keyword or tag")
    p_search.add_argument("query", help="Search term")

    p_del = sub.add_parser("delete", help="Delete a bookmark by ID")
    p_del.add_argument("id", type=int, help="Bookmark ID")

    args = parser.parse_args()

    if args.command == "add":
        add_bookmark(args.title, args.url, args.tag)
    elif args.command == "list":
        list_bookmarks()
    elif args.command == "search":
        list_bookmarks(args.query)
    elif args.command == "delete":
        delete_bookmark(args.id)


if __name__ == "__main__":
    main()
README.md — Quick Terminal Commands
# CLI Bookmark & Snippet Vault

Zero-dependency Python 3 CLI tool backed by SQLite.

## Usage

```bash
# Add a bookmark
python vault.py add "Python Docs" "[https://docs.python.org/3/](https://docs.python.org/3/)" -t docs

# List all bookmarks
python vault.py list

# Search by title, URL, or tag
python vault.py search docs

# Delete by ID
python vault.py delete 1
```