본문으로 건너뛰기
버전: In Development

Getting Started

Prerequisites

  • Python 3.10+

Supported Platforms

OSArchitecture
Linuxx86_64, aarch64
macOSx86_64, aarch64 (Apple Silicon)
Windowsx64

Installation

pip install aerospike-py

설치 확인:

python -c "import aerospike_py as aerospike; print(aerospike.__version__)"
Install from Source

개발 빌드나 기여를 위해서는 Contributing Guide를 참조하세요.

Quick Start

import aerospike_py as aerospike
from aerospike_py import Record

# 생성 및 연결 (Context Manager 사용)
with aerospike.client({
"hosts": [("127.0.0.1", 3000)],
"cluster_name": "docker",
}).connect() as client:

# 레코드 쓰기
key = ("test", "demo", "user1")
client.put(key, {"name": "Alice", "age": 30})

# 레코드 읽기 — Record NamedTuple 반환
record: Record = client.get(key)
print(f"bins={record.bins}, gen={record.meta.gen}, ttl={record.meta.ttl}")

# 튜플 언패킹도 가능 (하위 호환)
_, meta, bins = client.get(key)

# 증분 업데이트
client.increment(key, "age", 1)

# 원자적 다중 연산
ops = [
{"op": aerospike.OPERATOR_INCR, "bin": "age", "val": 1},
{"op": aerospike.OPERATOR_READ, "bin": "age", "val": None},
]
record = client.operate(key, ops)
print(record.bins)

# 삭제
client.remove(key)
# client.close()가 자동으로 호출됩니다
Context Manager 없이 사용

connect() / close()를 수동으로 호출할 수도 있습니다:

client = aerospike.client({...}).connect()
# ... 작업 수행 ...
client.close()

Configuration

config 딕셔너리는 ClientConfig TypedDict를 받습니다. 주요 옵션:

타입설명
hostslist[tuple[str, int]]시드 호스트 주소
cluster_namestr예상 클러스터 이름 (선택)
timeoutint연결 타임아웃 (ms, 기본값: 1000)
auth_modeintAUTH_INTERNAL, AUTH_EXTERNAL, 또는 AUTH_PKI

Policies & Metadata

쓰기 정책에는 WritePolicy, 메타데이터에는 WriteMeta, 읽기 정책에는 ReadPolicy를 사용합니다. 전체 필드는 Types Reference를 참조하세요.

# TTL 설정하여 쓰기 (초 단위)
client.put(key, {"val": 1}, meta={"ttl": 300})

# 키 전송 정책으로 쓰기
client.put(key, {"val": 1}, policy={"key": aerospike.POLICY_KEY_SEND})

# 생성 전용 (이미 존재하면 실패)
client.put(key, bins, policy={"exists": aerospike.POLICY_EXISTS_CREATE_ONLY})

# 세대 검사를 통한 Optimistic Locking
_, meta, bins = client.get(key)
client.put(key, {"val": bins["val"] + 1},
meta={"gen": meta.gen},
policy={"gen": aerospike.POLICY_GEN_EQ})

Next Steps