Installation

Install the PaperDB SDK with your package manager of choice.

TypeScript recommended. PaperDB uses your schema definition to generate fully typed collection methods — no extra codegen step required.

npm

npm install paperdb

pnpm

pnpm add paperdb

yarn

yarn add paperdb

Basic setup

import { createClient } from "paperdb";

const db = createClient({
  apiKey: process.env.PAPERDB_API_KEY,
});

Self-hosted setup

If you are running PaperDB on your own infrastructure, pass baseUrl pointing at your API server and realtimeUrl pointing at your realtime server.

const db = createClient({
  apiKey: process.env.PAPERDB_API_KEY,
    baseUrl: "https://api.paperdb.app",      // Backend API
    realtimeUrl: "wss://realtime.paperdb.app", // WebSocket server
});

When baseUrl is http://localhost:3001, the SDK automatically resolves the realtime URL to ws://localhost:3002 unless you override it with realtimeUrl.

With schema (recommended)

Passing a schema gives you full TypeScript autocomplete on every collection method.

const db = createClient({
  apiKey: process.env.PAPERDB_API_KEY,
  schema: {
    users: {
      properties: {
        name: { type: "string", required: true },
        email: { type: "string", required: true },
        isAdmin: { type: "boolean" },
      },
    },
  },
});

// Fully typed:
await db.users.insert({ name: "Alice", email: "alice@example.com" });
const users = await db.users.find({ filter: { isAdmin: true } });