Skip to main content

Asyncio wrapper of the Aerospike python client

Project description

asyncio wrapper of aerospike python client library

Latest Commit Contributors Package version

This project is work in progress. please do not use it in production yet.

This project provides a simple way to use aerospike with asyncio.

This project is based on Aerospike python client library docs Docs

installation

pip install aio-aerospike-python

Quick start

start docker compose

docker compose up -d 
from aio_aerospike_python import AioAerospikeClient
import asyncio
config = {
    'hosts': [('0.0.0.0', 3000)]
}
client = AioAerospikeClient(config)
print(client.is_connected())
async def put_some_data(limit:int):
    for i in range(limit):
        key = ("test","test",i)
        data = {"a":i}
        await client.put(key,data)


async def read_data(limit:int):
    for i in range(limit):
        key = ("test","test",i)
        r = await client.get(key)
        print(r)


loop = asyncio.get_event_loop()
loop.run_until_complete(put_some_data(33))
loop.run_until_complete(read_data(33))

client.close()

Now lets test it with concurrency

from aio_aerospike_python import AioAerospikeClient
from aio_aerospike_python import exception
from aerospike_helpers import expressions as exp
import aerospike


import asyncio
config = {
    'hosts': [('0.0.0.0', 3000)]
}

client = AioAerospikeClient(config)
print(client.is_connected())


async def put_some_data(limit: int):
    for i in range(limit):
        key = ("test", "test", i)
        data = {"a": i}
        await client.put(key, data)


async def read_data(limit: int):
    keys = [("test", "test", i) for i in range(limit) ]
    # print(keys)
    r = await client.get_many(keys)
    print(r)


async def use_query(mina: int, maxa: int):
    query = client.query("test", "test")
    expr = expr = exp.And(
        exp.LT(exp.IntBin("a"), maxa),
        exp.GT(exp.IntBin("a"), mina)
    ).compile()
    scan_policy = {"expressions": expr}
    results = await query.results(scan_policy)
    print("query results ===")
    for r in results:
        print(r)


async def use_scan(mina: int, maxa: int):
    scan = client.query("test", "test")
    expr = exp.And(
        exp.LT(exp.IntBin("a"), maxa),
        exp.GT(exp.IntBin("a"), mina)
    ).compile()
    scan_policy = {"expressions": expr}
    results = await scan.results(scan_policy)
    print("scan results ===")
    for r in results:
        print(r)



async def test_append(key=("test","test",3), bin="a", val="test", meta=None, policy=None):
    await client.put(key=key, bins={"vv":"test_"})
    await client.append(key=key, bin="vv", val="append", meta=meta, policy=policy)
    r = await client.get(key=key)
    key, _, bin = r
    print("append")
    print(r)

async def main():
    L = await asyncio.gather(
        put_some_data(700),
        read_data(50),
        use_query(10, 20),
        use_scan(40, 45),
        test_append()
    )

asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aio_aerospike_python-0.0.4.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

aio_aerospike_python-0.0.4-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file aio_aerospike_python-0.0.4.tar.gz.

File metadata

  • Download URL: aio_aerospike_python-0.0.4.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for aio_aerospike_python-0.0.4.tar.gz
Algorithm Hash digest
SHA256 503016001ab79e34872195bb21d5f36701f762016b377ad9404cecb883d5b63d
MD5 d08e28c5738b16b11639def95149164c
BLAKE2b-256 97f1c34064bf181e84c2681aee7eb08ae0eb20dc72be521296b28cba4406da4f

See more details on using hashes here.

Provenance

File details

Details for the file aio_aerospike_python-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for aio_aerospike_python-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9430023cb04feb9195253e9b6eb21048d073477fb82c7297a963b3d46eaeb85c
MD5 2f9d6a70a71698fe0343cb63191f0ebc
BLAKE2b-256 484066066fb15cd21312f3dffa5cf67d602363819f2a139a443e486e331475e3

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page