---
title: "Migrating from legacy client"
description: "Migrate your Aerospike application from the legacy client to the Developer SDK with Java and Python examples."
---

# Migrating from legacy client

> For the complete documentation index see: [llms.txt](https://aerospike.com/docs/llms.txt)
> 
> All documentation pages available in markdown.

## Applies to

-   Aerospike Developer SDK (Java 21+ and Python 3.11+)
-   Aerospike Database 8.2.0 or later, unless a section states otherwise

::: code examples
Examples assume a connected `session` from [Connect to Aerospike](https://aerospike.com/docs/develop/client/sdk/connect). Each usage guide lists shared imports in a tabbed block near the top of the page; snippet blocks add imports only for types not already shown. The first code block in each section includes dataset setup; later blocks in that section reuse those values. When a page includes a **Complete example** section, that block is fully self-contained.
:::

This guide helps you migrate an existing application from the Classic Aerospike client to the Developer SDK.

## Why migrate?

The Developer SDK offers several advantages over the legacy client:

-   **Cleaner syntax** — Chainable, fluent APIs reduce boilerplate
-   **AEL queries** — Human-readable filter expressions
-   **Better error handling** — Actionable errors with recovery suggestions
-   **Decoupled configuration** — Separate connection from behavior

## Before you start

1.  Confirm your Aerospike server is compatible. The Python SDK and AEL `where` queries require Aerospike Server 8.2.0 or later. See [Compatibility](https://aerospike.com/docs/develop/client/sdk/reference/compatibility).
2.  Install the Developer SDK as a separate package. It does not replace the legacy client.
3.  Plan to run both clients side by side during migration if you need a gradual cutover.
4.  Inventory the secondary indexes your filtered queries depend on. See [Query with filters](#query-with-filters).

## Conceptual changes

### Connection model

**Classic**: Direct client with embedded configuration

**SDK**: Separate `Cluster` (connection) and `Session` (behavior)

-   [Java Classic](#tab-panel-5250)
-   [Java SDK](#tab-panel-5251)
-   [Python Classic](#tab-panel-5252)
-   [Python SDK](#tab-panel-5253)

```java
// Classic: Everything in one place

AerospikeClient client = new AerospikeClient(

    new ClientPolicy(),

    new Host("localhost", 3000)

);
```

> 📖 **API reference**: [`Host(String,int)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Host.html#%3Cinit%3E%28java.lang.String%2Cint%29) | [`Host(String,String,int)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Host.html#%3Cinit%3E%28java.lang.String%2Cjava.lang.String%2Cint%29)

```java
import com.aerospike.client.sdk.policy.Behavior;

import com.aerospike.client.sdk.Cluster;

import com.aerospike.client.sdk.ClusterDefinition;

import com.aerospike.client.sdk.Session;

// SDK: Connection separate from behavior

try (Cluster cluster = new ClusterDefinition("localhost", 3000).connect()) {

    Session session = cluster.createSession(Behavior.DEFAULT);

}
```

> 📖 **API reference**: [`ClusterDefinition(String,int)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/ClusterDefinition.html#%3Cinit%3E%28java.lang.String%2Cint%29) | [`ClusterDefinition.connect()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/ClusterDefinition.html#connect%28%29) | [`Cluster.createSession(Behavior)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Cluster.html#createSession%28com.aerospike.client.sdk.policy.Behavior%29) | [`Cluster.close()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Cluster.html#close%28%29)

```python
# Classic: Everything in one place

client = aerospike.client({

    'hosts': [('localhost', 3000)]

}).connect()
```

> 📖 **API reference**: [`aerospike.client()`](https://aerospike-python-client.readthedocs.io/en/latest/aerospike.html#aerospike.client) | [`Client.connect()`](https://aerospike-python-client.readthedocs.io/en/latest/client.html#aerospike.Client.connect)

```python
from aerospike_sdk import Behavior, ClusterDefinition

# SDK: Connection separate from behavior

async with ClusterDefinition("localhost", 3000).connect() as cluster:

    session = cluster.create_session(Behavior.DEFAULT)
```

> 📖 **API reference**: [`Behavior.DEFAULT`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/behavior.html#aerospike%5Fsdk.policy.behavior.Behavior.DEFAULT)

### Key and record references

**Classic**: Explicit `Key` objects with namespace, set, and user key

**SDK**: `DataSet` represents namespace + set, `.id()` creates a `Key`

-   [Java Classic](#tab-panel-5254)
-   [Java SDK](#tab-panel-5255)
-   [Python Classic](#tab-panel-5256)
-   [Python SDK](#tab-panel-5257)

```java
Key key = new Key("test", "users", "user-1");
```

> 📖 **API reference**: [`Key`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Key.html)

```java
DataSet users = DataSet.of("test", "users");

Key key = users.id("user-1");
```

> 📖 **API reference**: [`DataSet.of(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/DataSet.html#of%28java.lang.String%2Cjava.lang.String%29) | [`DataSet.id(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/DataSet.html#id%28java.lang.String%29)

```python
key = ("test", "users", "user-1")
```

> 📖 **API reference**: [`Key Tuple`](https://aerospike-python-client.readthedocs.io/en/latest/client.html#key-tuple)

```python
users = DataSet.of("test", "users")

ref = users.id("user-1")
```

> 📖 **API reference**: [`DataSet.of()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/dataset.html#aerospike%5Fsdk.dataset.DataSet.of) | [`DataSet.id()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/dataset.html#aerospike%5Fsdk.dataset.DataSet.id)

## Operation mapping

### Create (put)

-   [Java Classic](#tab-panel-5258)
-   [Java SDK](#tab-panel-5259)
-   [Python Classic](#tab-panel-5260)
-   [Python SDK](#tab-panel-5261)

```java
client.put(null, key, new Bin("name", "Alice"), new Bin("age", 30));
```

> 📖 **API reference**: [`com.aerospike.client.sdk`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/package-summary.html)

```java
session.insert(users)

    .bins("name", "age")

    .id("user-1").values("Alice", 30)

    .execute();
```

> 📖 **API reference**: [`Session.insert(DataSet)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Session.html#insert%28com.aerospike.client.sdk.DataSet%29) | [`OperationObjectBuilder.bins(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/OperationObjectBuilder.html#bins%28java.lang.String%2Cjava.lang.String...%29) | [`IdValuesBuilder.id(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/IdValuesBuilder.html#id%28java.lang.String%29) | [`IdValuesRowBuilder.values(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/IdValuesRowBuilder.html#values%28java.lang.Object...%29) | [`ChainableQueryBuilder.execute()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/ChainableQueryBuilder.html#execute%28%29)

```python
client.put(key, {"name": "Alice", "age": 30})
```

> 📖 **API reference**: [`Client.put()`](https://aerospike-python-client.readthedocs.io/en/latest/client.html#aerospike.Client.put)

```python
await session.insert(users.id("user-1")).put(

    {"name": "Alice", "age": 30}

).execute()
```

> 📖 **API reference**: [`DataSet.id()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/dataset.html#aerospike%5Fsdk.dataset.DataSet.id) | [`Session.insert()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/session.html#aerospike%5Fsdk.aio.session.Session.insert) | [`WriteSegmentBuilder.put()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/write-segment.html#aerospike%5Fsdk.aio.operations.query.WriteSegmentBuilder.put) | [`WriteSegmentBuilder.execute()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/write-segment.html#aerospike%5Fsdk.aio.operations.query.WriteSegmentBuilder.execute)

### Read (get)

-   [Java Classic](#tab-panel-5262)
-   [Java SDK](#tab-panel-5263)
-   [Python Classic](#tab-panel-5264)
-   [Python SDK](#tab-panel-5265)

```java
Record record = client.get(null, key);

String name = record.getString("name");
```

> 📖 **API reference**: [`Record.getString(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Record.html#getString%28java.lang.String%29)

```java
import com.aerospike.client.sdk.Record;

import com.aerospike.client.sdk.RecordStream;

String name;

try (RecordStream stream = session.query(users.id("user-1")).execute()) {

    Record user = stream.getFirstRecord();

    name = user.getString("name");

}
```

> 📖 **API reference**: [`DataSet.id(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/DataSet.html#id%28java.lang.String%29) | [`Session.query(Key)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Session.html#query%28com.aerospike.client.sdk.Key%29) | [`ChainableQueryBuilder.execute()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/ChainableQueryBuilder.html#execute%28%29) | [`RecordStream.getFirstRecord()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/RecordStream.html#getFirstRecord%28%29) | [`Record.getString(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Record.html#getString%28java.lang.String%29)

```python
key, meta, bins = client.get(key)

name = bins["name"]
```

> 📖 **API reference**: [`Client.get()`](https://aerospike-python-client.readthedocs.io/en/latest/client.html#aerospike.Client.get)

```python
row = await session.query(users.id("user-1")).first_or_raise()

user = row.record_or_raise()

name = user.bins.get("name")
```

> 📖 **API reference**: [`DataSet.id()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/dataset.html#aerospike%5Fsdk.dataset.DataSet.id) | [`Session.query()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/session.html#aerospike%5Fsdk.aio.session.Session.query) | [`RecordResult.record_or_raise()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/record-result.html#aerospike%5Fsdk.record%5Fresult.RecordResult.record%5For%5Fraise) | [`RecordStream.first_or_raise()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/record-stream.html#aerospike%5Fsdk.record%5Fstream.RecordStream.first%5For%5Fraise) | [`RecordStream.close()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/record-stream.html#aerospike%5Fsdk.record%5Fstream.RecordStream.close) | [`QueryBuilder.execute()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/query.html#aerospike%5Fsdk.aio.operations.query.QueryBuilder.execute)

### Update

-   [Java Classic](#tab-panel-5266)
-   [Java SDK](#tab-panel-5267)
-   [Python Classic](#tab-panel-5268)
-   [Python SDK](#tab-panel-5269)

```java
client.put(null, key, new Bin("visits", 1), new Bin("updated", true));
```

> 📖 **API reference**: [`com.aerospike.client.sdk`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/package-summary.html)

```java
session.update(users.id("user-1"))

    .bin("visits").setTo(1)

    .bin("updated").setTo(true)

    .execute();
```

> 📖 **API reference**: [`DataSet.id(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/DataSet.html#id%28java.lang.String%29) | [`Session.update(DataSet)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Session.html#update%28com.aerospike.client.sdk.DataSet%29) | [`ChainableOperationBuilder.bin(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/ChainableOperationBuilder.html#bin%28java.lang.String%29) | [`ChainableQueryBuilder.bin(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/ChainableQueryBuilder.html#bin%28java.lang.String%29) | [`ChainableQueryBuilder.execute()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/ChainableQueryBuilder.html#execute%28%29)

```python
client.put(key, {"visits": 1, "updated": True})
```

> 📖 **API reference**: [`Client.put()`](https://aerospike-python-client.readthedocs.io/en/latest/client.html#aerospike.Client.put)

```python
await (

    session.update(users.id("user-1"))

    .bin("visits").set_to(1)

    .bin("updated").set_to(True)

    .execute()

)
```

> 📖 **API reference**: [`DataSet.id()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/dataset.html#aerospike%5Fsdk.dataset.DataSet.id) | [`Session.update()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/session.html#aerospike%5Fsdk.aio.session.Session.update) | [`QueryBuilder.bin()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/query.html#aerospike%5Fsdk.aio.operations.query.QueryBuilder.bin) | [`WriteSegmentBuilder.set_to()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/write-segment.html#aerospike%5Fsdk.aio.operations.query.WriteSegmentBuilder.set%5Fto) | [`WriteSegmentBuilder.bin()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/write-segment.html#aerospike%5Fsdk.aio.operations.query.WriteSegmentBuilder.bin) | [`WriteSegmentBuilder.execute()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/write-segment.html#aerospike%5Fsdk.aio.operations.query.WriteSegmentBuilder.execute)

### Delete

-   [Java Classic](#tab-panel-5270)
-   [Java SDK](#tab-panel-5271)
-   [Python Classic](#tab-panel-5272)
-   [Python SDK](#tab-panel-5273)

```java
client.delete(null, key);
```

> 📖 **API reference**: [`com.aerospike.client.sdk`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/package-summary.html)

```java
session.delete(users.id("user-1")).execute().close();
```

> 📖 **API reference**: [`DataSet.id(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/DataSet.html#id%28java.lang.String%29) | [`Session.delete(Key)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Session.html#delete%28com.aerospike.client.sdk.Key%29) | [`ChainableQueryBuilder.execute()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/ChainableQueryBuilder.html#execute%28%29) | [`ChainableNoBinsBuilder.execute()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/ChainableNoBinsBuilder.html#execute%28%29) | [`RecordStream.close()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/RecordStream.html#close%28%29)

```python
client.remove(key)
```

> 📖 **API reference**: [`Client.remove()`](https://aerospike-python-client.readthedocs.io/en/latest/client.html#aerospike.Client.remove)

```python
await session.delete(users.id("user-1")).execute()
```

> 📖 **API reference**: [`DataSet.id()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/dataset.html#aerospike%5Fsdk.dataset.DataSet.id) | [`Session.delete()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/session.html#aerospike%5Fsdk.aio.session.Session.delete) | [`RecordStream.close()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/record-stream.html#aerospike%5Fsdk.record%5Fstream.RecordStream.close) | [`WriteSegmentBuilder.execute()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/write-segment.html#aerospike%5Fsdk.aio.operations.query.WriteSegmentBuilder.execute)

### Query with filters

-   [Java Classic](#tab-panel-5274)
-   [Java SDK](#tab-panel-5275)
-   [Python Classic](#tab-panel-5276)
-   [Python SDK](#tab-panel-5277)

```java
Statement stmt = new Statement();

stmt.setNamespace("test");

stmt.setSetName("users");

stmt.setFilter(Filter.range("age", 21, 100));

RecordSet rs = client.query(null, stmt);

while (rs.next()) {

    Record record = rs.getRecord();

    // process record

}
```

```java
import com.aerospike.client.sdk.Record;

import com.aerospike.client.sdk.RecordStream;

RecordStream stream = session.query(users)

    .where("$.age >= 21")

    .execute();

stream.forEach(result -> {

    Record row = result.recordOrThrow();

    // process record

});

stream.close();
```

> 📖 **API reference**: [`Session.query(DataSet)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/Session.html#query%28com.aerospike.client.sdk.DataSet%29) | [`ChainableQueryBuilder.where(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/ChainableQueryBuilder.html#where%28java.lang.String%2Cjava.lang.Object...%29) | [`ChainableQueryBuilder.execute()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/ChainableQueryBuilder.html#execute%28%29) | [`RecordStream.forEach(...)`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/RecordStream.html#forEach%28java.util.function.Consumer%29) | [`RecordStream.close()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/RecordStream.html#close%28%29) | [`RecordResult.recordOrThrow()`](https://javadoc.io/doc/com.aerospike/aerospike-client-sdk/latest/com/aerospike/client/sdk/RecordResult.html#recordOrThrow%28%29)

```python
query = client.query("test", "users")

query.where(aerospike.predicates.between("age", 21, 100))

for record in query.results():

    # process record

    pass
```

> 📖 **API reference**: [`Client.query()`](https://aerospike-python-client.readthedocs.io/en/latest/client.html#aerospike.Client.query) | [`Query.where()`](https://aerospike-python-client.readthedocs.io/en/latest/query.html#aerospike.Query.where) | [`predicates.between()`](https://aerospike-python-client.readthedocs.io/en/latest/predicates.html#aerospike.predicates.between) | [`Query.results()`](https://aerospike-python-client.readthedocs.io/en/latest/query.html#aerospike.Query.results)

```python
stream = await session.query(users).where("$.age >= 21").execute()

async for row in stream:

    row.record_or_raise()

    pass  # process the returned record

stream.close()
```

> 📖 **API reference**: [`Session.query()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/session.html#aerospike%5Fsdk.aio.session.Session.query) | [`QueryBuilder.where()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/query.html#aerospike%5Fsdk.aio.operations.query.QueryBuilder.where) | [`RecordResult.record_or_raise()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/record-result.html#aerospike%5Fsdk.record%5Fresult.RecordResult.record%5For%5Fraise) | [`RecordStream.close()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/record-stream.html#aerospike%5Fsdk.record%5Fstream.RecordStream.close) | [`QueryBuilder.execute()`](https://aerospike-python-sdk.readthedocs.io/en/latest/api/query.html#aerospike%5Fsdk.aio.operations.query.QueryBuilder.execute)

::: behavior change: the server now selects the index
A legacy filter names a secondary index. Without an index on that bin, the query fails with [`AS_ERR_SINDEX_NOT_FOUND`](https://aerospike.com/docs/database/reference/error-codes/#server-errors) (201).

An AEL `where` clause names a bin. The [query optimizer](https://aerospike.com/docs/develop/learn/queries/query-optimizer/) selects a readable secondary index that can serve the predicate. If none matches, the query either runs as a primary index (PI) query and reads every record in the set, or fails with 201, depending on [`allowScansWithWhere`](https://aerospike.com/docs/develop/learn/queries/query-optimizer/#control-pi-fallback).

A ported query therefore does not fail the way the original did when its index is missing. Confirm that every filtered bin still has a readable (`RW`) index before you cut over.
:::

## Migration strategy

### Option 1: gradual migration

1.  Add Developer SDK dependency alongside classic
2.  Create new features with Developer SDK
3.  Migrate existing code incrementally
4.  Remove legacy client when migration complete

### Option 2: full migration

1.  Create a feature branch
2.  Replace all legacy client calls with Developer SDK equivalents
3.  Run comprehensive tests
4.  Deploy with confidence

## What’s not supported (yet)

Some advanced features from the legacy client are not yet available in the Developer SDK:

-   Admin operations (cluster management)

HyperLogLog and GeoJSON are supported in both SDKs. See [Update records](https://aerospike.com/docs/develop/client/sdk/usage/update) and [Secondary indexes](https://aerospike.com/docs/develop/client/sdk/concepts/secondary-indexes).

## Next steps

-   [Quickstart](https://aerospike.com/docs/develop/client/sdk/quickstart) — Get started with Developer SDK
-   [AEL Queries](https://aerospike.com/docs/develop/client/sdk/concepts/ael) — Learn the query syntax
-   [Error Handling](https://aerospike.com/docs/develop/client/sdk/concepts/errors) — Understand error recovery