---
title: "Aerospike Interactive Tutorial: Simple Put-Get Example"
description: "Learn how to perform simple put and get operations in Aerospike using Python."
---

# Simple Put-Get Example

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

#### For an interactive Jupyter notebook experience [ ![Binder Hub](https://static.mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/aerospike-examples/interactive-notebooks/main?filepath=python/SimplePutGetExample.ipynb)

A simple example of `put` and `get` calls in Aerospike.

#### Prerequisites

-   [Aerospike database](https://aerospike.com/docs/database/install) running locally
-   [Python](https://www.python.org/)
-   [Aerospike Python client](https://aerospike.com/docs/develop/client/python/install/)

Visit the [Aerospike notebooks repo](https://github.com/aerospike-examples/interactive-notebooks) for additional details and the Docker container.

## Import the module

```python
import aerospike
```

## Configure the client

This configuration is for Aerospike running on port 3000 of localhost which is the default. If your environment is different, such as Aerospike Database running on a different host or different port, you can use different configuration arguments.

```python
config = {

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

}
```

## Create a client and connect it to the cluster

```python
try:

  client = aerospike.client(config).connect()

except:

  import sys

  print("failed to connect to the cluster with", config['hosts'])

  sys.exit(1)
```

## Records are addressable via a tuple of (namespace, set, key)

These three components form the key. `set` is optional. For a detailed description of the data model, see the [Data Model overview](https://aerospike.com/docs/database/learn/architecture/data-storage/data-model).

```python
key = ('test', 'demo', 'foo')
```

## Writing a record

Aerospike is schemaless. You can create and modify records without any other setup. The following example writes a record with two bins, `name` and `age`, using the key defined above.

```python
try:

  # Write a record

  client.put(key, {

    'name': 'John Doe',

    'age': 32

  })

except Exception as e:

  import sys

  print("error: {0}".format(e), file=sys.stderr)
```

## Reading a record

The following example retrieves the same record.

```python
(key, metadata, record) = client.get(key)
```

## Display result

The following example prints data from the same record, including:

1.  The contents of the record’s bins.
2.  The components of the key which are: namespace, the set, a user key (by default there is no user key), and a hash which is the internal representation of the key.
3.  The metadata with the time to live (TTL) and the record’s generation.

Lastly it is important to clean up the client we created at the beginning.

```python
print("record contents are", record)

print("key components are", key)

print("metadata is", metadata)

# Close the connection to the Aerospike cluster

client.close()
```