# Create

Jump to the [Code block](#code-block) for a combined complete example.

## Setup

The following examples will use the setup and record structure below to illustrate single record creation in an Aerospike database.

```python
import aerospike

from aerospike import GeoJSON

# Define host configuration

config = {

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

}

# Establishes a connection to the server

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

The record structure:

```plaintext
+------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------+

| PK   | occurred | reported | posted   | report                                                                                                                                                                                                                 | location                                                   |

+------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------+

| 5001 | 20220531 | 20220601 | 20220601 | MAP('{"shape":["circle", "flash", "disc"], "summary":"Large flying disc flashed in the sky above the student union. Craziest thing I've ever seen!", "city":"Ann Arbor", "state":"Michigan", "duration":"5 minutes"}') | GeoJSON('{"type":"Point","coordinates":[42.2808,83.743]}') |

+------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------+
```

## Policies

Write policies define additional semantics for the write operation. Instead of using the default write [policies](https://aerospike.com/docs/database/learn/policies), we can set them on a per command basis.

The following example creates a new write policy container object that sets the send key policy to `true`. This stores the user defined key with the record, and returns it with read commands.

```python
# Create new write policy

write_policy = {'key': aerospike.POLICY_KEY_SEND}
```

## Key

The [key](https://aerospike.com/docs/database/learn/architecture/data-storage/data-model#keys-and-digests) is a tuple made up of: `([namespace](https://aerospike.com/docs/database/learn/architecture/data-storage/data-model#namespaces), [set](https://aerospike.com/docs/database/learn/architecture/data-storage/data-model#sets), user defined key)`.

The following example creates a key using the `sandbox` namespace, `ufodata` set, and user defined key `5001`.

```python
# Create the record key

key = ('sandbox', 'ufodata', 5001)
```

## Create a record

A [record](https://aerospike.com/docs/database/learn/architecture/data-storage/data-model#records) is the basic unit of storage in the database. A record is composed of: `([key](https://aerospike.com/docs/database/learn/architecture/data-storage/data-model#keys-and-digests), [metadata](https://aerospike.com/docs/database/learn/architecture/data-storage/data-model#metadata), [bins](https://aerospike.com/docs/database/learn/architecture/data-storage/data-model#bins-and-data-types))`.

### Setup

Expand the block below to see the creation of the variables used in the [write](#write) example below.

View the data creation

```python
# Create the report map

reportMap = {

    'city': 'Ann Arbor',

    'state': 'Michigan',

    'shape': ['circle', 'flash', 'disc'],

    'duration': '5 minutes',

    'summary': "Large flying disc flashed in the sky above the student union. Craziest thing I've ever seen!"

}

# Format coordinates as a GeoJSON string

geoLoc = GeoJSON({'type':'Point', 'coordinates':[42.2808,83.7430]})
```

### Write

The following example shows the creation of the bins and the writing of the record to the database.

```python
# Create the bins

bins = {

    'occurred': 20220531,

    'reported': 20220601,

    'posted': 20220601,

    # reportMap defined in the section above

    'report': reportMap,

    # geoLoc defined in the section above

    'location': geoLoc

}

# Write the record to Aerospike

client.put(key, bins, policy=write_policy)

# Close the connection to the server

client.close()
```

## Code block

Expand this section for a single code block to create a record

```python
import aerospike

from aerospike import GeoJSON

# Define host configuration

config = {

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

}

# Establishes a connection to the server

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

# Create new write policy

write_policy = {'key': aerospike.POLICY_KEY_SEND}

# Create the record key

key = ('sandbox', 'ufodata', 5001)

# Create the report map

reportMap = {

    'city': 'Ann Arbor',

    'state': 'Michigan',

    'shape': ['circle', 'flash', 'disc'],

    'duration': '5 minutes',

    'summary': "Large flying disc flashed in the sky above the student union. Craziest thing I've ever seen!"

}

# Format coordinates as a GeoJSON string

geoLoc = GeoJSON({'type':'Point', 'coordinates':[42.2808,83.7430]})

# Create the bins

bins = {

    'occurred': 20220531,

    'reported': 20220601,

    'posted': 20220601,

    # reportMap defined in the section above

    'report': reportMap,

    # geoLoc defined in the section above

    'location': geoLoc

}

# Write the record to Aerospike

client.put(key, bins, policy=write_policy)

# Close the connection to the server

client.close()
```