Apache Iceberg REST Catalog Client

0.8.1 · active · verified Sun Apr 19

Iceberg.js is a small, framework-agnostic JavaScript and TypeScript client specifically designed for interacting with Apache Iceberg REST Catalogs. It provides a thin HTTP wrapper over the official REST API, making it generic enough to work with any Iceberg REST Catalog implementation without vendor lock-in. The current stable version is `0.8.1`. The project maintains an active release cadence, with multiple minor versions released within short intervals, indicating ongoing development towards a stable 1.0.0. Key differentiators include first-class TypeScript support for strong typing, reliance on the native `fetch` API for universal compatibility (Node.js 20+ and modern browsers), and a focused scope on catalog operations, deliberately excluding data reading or Parquet file support.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the IcebergRestCatalog client, create a new namespace, and then define and create a new table within that namespace, including schema and basic properties.

import { IcebergRestCatalog } from 'iceberg-js'

const catalog = new IcebergRestCatalog({
  baseUrl: 'https://my-catalog.example.com/iceberg/v1',
  auth: {
    type: 'bearer',
    token: process.env.ICEBERG_TOKEN ?? '', // Provide a fallback for process.env
  },
})

async function setupIceberg() {
  try {
    // Create a namespace
    console.log('Creating namespace...')
    await catalog.createNamespace({ namespace: ['analytics'] })
    console.log('Namespace "analytics" created.')

    // Create a table
    console.log('Creating table "events"...')
    await catalog.createTable(
      { namespace: ['analytics'] },
      {
        name: 'events',
        schema: {
          type: 'struct',
          fields: [
            { id: 1, name: 'id', type: 'long', required: true },
            { id: 2, name: 'timestamp', type: 'timestamp', required: true },
            { id: 3, name: 'user_id', type: 'string', required: false },
          ],
          'schema-id': 0,
          'identifier-field-ids': [1],
        },
        'partition-spec': {
          'spec-id': 0,
          fields: [],
        },
        'write-order': {
          'order-id': 0,
          fields: [],
        },
        properties: {
          'write.format.default': 'parquet',
        },
      }
    )
    console.log('Table "events" created in "analytics" namespace.')
  } catch (error) {
    console.error('Error during Iceberg setup:', error)
  }
}

setupIceberg();

view raw JSON →