Getting Started
Installation
pip install aerospike-py
Requirements: Python 3.10+ (CPython)
Quick Start
- Sync
- Async
import aerospike_py as aerospike
from aerospike_py import Record
with aerospike.client({
"hosts": [("127.0.0.1", 3000)],
}).connect() as client:
key: tuple[str, str, str] = ("test", "demo", "user1")
# Write
client.put(key, {"name": "Alice", "age": 30})
# Read
record: Record = client.get(key)
print(record.bins) # {"name": "Alice", "age": 30}
print(record.meta.gen) # 1
# Update
client.increment(key, "age", 1)
# Delete
client.remove(key)
import asyncio
import aerospike_py as aerospike
from aerospike_py import AsyncClient, Record
async def main() -> None:
async with AsyncClient({"hosts": [("127.0.0.1", 3000)]}) as client:
await client.connect()
key: tuple[str, str, str] = ("test", "demo", "user1")
await client.put(key, {"name": "Bob", "age": 25})
record: Record = await client.get(key)
print(record.bins) # {"name": "Bob", "age": 25}
# Concurrent writes
keys = [("test", "demo", f"item_{i}") for i in range(10)]
await asyncio.gather(*(client.put(k, {"idx": i}) for i, k in enumerate(keys)))
await client.remove(key)
asyncio.run(main())
Policies & Metadata
import aerospike_py as aerospike
key = ("test", "demo", "user1")
# TTL (seconds)
client.put(key, {"val": 1}, meta={"ttl": 300})
# Create only (fail if exists)
client.put(key, {"val": 1}, policy={"exists": aerospike.POLICY_EXISTS_CREATE_ONLY})
# Optimistic locking
record = client.get(key)
client.put(
key,
{"val": record.bins["val"] + 1},
meta={"gen": record.meta.gen},
policy={"gen": aerospike.POLICY_GEN_EQ},
)
Next Steps
| Topic | Description |
|---|---|
| Read Operations | Get, select, exists, batch read |
| Write Operations | Put, update, delete, operate, batch operate |
| CDT Operations | Atomic list & map operations |
| NumPy Batch | Zero-copy columnar batch reads |
| Query | Secondary index queries |
| Expression Filters | Server-side filtering |
| Configuration | Connection, pool, timeouts |
| API Reference | Full method signatures |
| Types | NamedTuple / TypedDict definitions |