# SDKs

Source: https://docs.rushdb.com/connect/sdks/

Use the TypeScript or Python SDK when RushDB is part of your application, service, script, or data pipeline. Each SDK works with RushDB in one of two ways, with the same API:

|              | RushDB Cloud                                                 | Self-hosted engine (direct mode)                       |
| ------------ | ------------------------------------------------------------ | ------------------------------------------------------ |
| What you run | Nothing: the managed service at [app.rushdb.com](https://app.rushdb.com) | One `rushdb` binary, on your own infrastructure |
| Connect with | An API key                                                   | The engine URL and the engine token                    |

The engine is what you can self-host. RushDB Cloud runs that engine for you and adds the dashboard, managed embeddings and the AI features (natural-language search, relationship-pattern suggestions), which exist only in RushDB Cloud.

| Package                   | Install                              | Version |
| ------------------------- | ------------------------------------ | ------- |
| `@rushdb/javascript-sdk`  | `npm install @rushdb/javascript-sdk` | 3.x — Node.js and browsers, zero runtime dependencies |
| `rushdb`                  | `pip install rushdb`                 | 3.x — Python 3.10 or newer, no runtime dependencies |

---

## Connect

**TypeScript**

```typescript

// RushDB Cloud
const db = new RushDB(process.env.RUSHDB_API_KEY!)

// A self-hosted engine
const engine = new RushDB(process.env.RUSHDB_TOKEN ?? 'local-token', {
  direct: true,
  engineUrl: 'http://127.0.0.1:3000',
  scope: 'tenant-1' // only for an engine started with --multitenant
})
```

**Python**

```python
from rushdb import RushDB

# RushDB Cloud
db = RushDB(os.environ["RUSHDB_API_KEY"])

# A self-hosted engine
engine = RushDB(
    os.environ.get("RUSHDB_TOKEN", "local-token"),
    direct=True,
    engine_url="http://127.0.0.1:3000",
    scope="tenant-1",  # only for an engine started with --multitenant
)
```

Get an API key at [app.rushdb.com](https://app.rushdb.com), or start an engine with `rushdb up` (see [Get started](../index.mdx)). A local `rushdb up` accepts the token `local-token` unless you set `RUSHDB_TOKEN`. `direct: true` without an engine URL throws instead of falling back to RushDB Cloud.

---

## Write and read

The fastest useful test is a nested import followed by a search. Nested objects become linked records automatically.

**TypeScript**

```typescript
await db.records.importJson({
  label: 'PROJECT',
  data: {
    name: 'RushDB adoption',
    TASK: [
      { title: 'Connect RushDB', status: 'done' },
      { title: 'Query linked records', status: 'pending' }
    ]
  }
})

const { data: projects, total } = await db.records.find({
  labels: ['PROJECT'],
  where: { TASK: { status: 'pending' } }
})
console.log({ total, projects })
```

**Python**

```python
db.records.import_json(
    {
        "name": "RushDB adoption",
        "TASK": [
            {"title": "Connect RushDB", "status": "done"},
            {"title": "Query linked records", "status": "pending"},
        ],
    },
    label="PROJECT",
)

projects = db.records.find({
    "labels": ["PROJECT"],
    "where": {"TASK": {"status": "pending"}},
})
print(projects.total, projects.data)
```

**Shell**

```bash
curl -X POST https://api.rushdb.com/api/v1/records/import/json \
  -H "Authorization: Bearer $RUSHDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "label": "PROJECT",
    "data": {
      "name": "RushDB adoption",
      "TASK": [
        {"title": "Connect RushDB", "status": "done"},
        {"title": "Query linked records", "status": "pending"}
      ]
    }
  }'
```

The REST API is RushDB Cloud's; a self-hosted engine is reached through the SDKs or its own [native protocol](../engine/connectivity/http-api.md).

---

## What each mode offers

| Feature | Cloud | Self-hosted engine |
| --- | :---: | :---: |
| Records: create, read, update, set, upsert, delete, `find` with `where`, `orderBy`, `select`, `groupBy` | ✓ | ✓ |
| Relationships: attach/detach, `relationships.createMany` / `deleteMany` / `find` | ✓ | ✓ |
| Labels, properties, property values | ✓ | ✓ |
| Import JSON and CSV, export CSV | ✓ | ✓ |
| [Keyword (BM25) search](../learn/semantic-search/keyword-search.mdx) and text indexes | ✓ | ✓ |
| External vector indexes; [vector](../learn/semantic-search/semantic-search.mdx) and [hybrid](../learn/semantic-search/hybrid-search.mdx) search with a `queryVector` you supply | ✓ | ✓ |
| [Raw openCypher](../learn/records-and-queries/raw-queries.mdx) (`query.raw`) | ✓ | ✓ (engine started with `--languages cypher,sql`) |
| Schema (`ai.getSchema`, `ai.getSchemaMarkdown`) | ✓ | ✓ |
| [Transactions](../learn/records-and-queries/transactions.mdx) | ✓ | ✓ |
| Managed embeddings: managed indexes, `records.vectorSearch` by text `query` | ✓ | — |
| Natural-language search (`ai.search`) | ✓ | — |
| Relationship-pattern suggestions (`relationships.patterns.*`) | ✓ | — |
| Project settings (`settings.get`), dashboard, projects, team access | ✓ | — |

In both modes, a transaction stages record creates, updates, sets, deletes by id, attaches and imports; other writes are refused inside a transaction. See [Transactions](../learn/records-and-queries/transactions.mdx#supported-operations).

### Errors in direct mode

| Error | Raised when | Fields |
| --- | --- | --- |
| `CloudOnlyError` | A Cloud-only method or form is called. Nothing is sent, and no request ever goes to RushDB Cloud. | `method`, `reason`, `code: 'CLOUD_ONLY'` |
| `DirectModeError` | A write the engine cannot stage is called inside a transaction. Nothing is sent. | `code: 'DIRECT_MODE_UNSUPPORTED'` |

The lists are available in code, so an application can decide at runtime:

**TypeScript**

```typescript

if (!isCloudOnlyMethod('ai.search')) {
  // offer natural-language search
}
```

**Python**

```python
from rushdb import CLOUD_ONLY_METHODS, CloudOnlyError, is_cloud_only_method
```

### The native protocol from the SDK

In direct mode, any [Protocol v1](../engine/connectivity/http-api.md) operation the SDK has no method for is one call away: `db.engine.execute(operation)` in Python.

```python
schema = engine.engine.execute({"kind": "describe", "describe": {"kind": "capabilities"}})
```

---

## Add search

1. Keyword search works as soon as you [declare a text index](../learn/semantic-search/keyword-search.mdx).
2. For vector search, [create an embedding index](../learn/semantic-search/manage-indexes.mdx) — managed on Cloud, or external with your own vectors anywhere — and wait until its status is `ready`.
3. Run [semantic](../learn/semantic-search/semantic-search.mdx) or [hybrid](../learn/semantic-search/hybrid-search.mdx) search.

For natural-language query planning over your schema on RushDB Cloud, see [Smart Search](../learn/search-query/smart-search.mdx).

## Full references

- [TypeScript / JavaScript reference](../learn/reference/typescript/index.md)
- [Python reference](../learn/reference/python/index.md)
- [REST API reference](../learn/reference/rest-api/introduction.md) [Cloud]
- [Store records](../learn/records-and-queries/store-records.mdx)
- [Import nested data](../learn/records-and-queries/import-data.mdx)
