Skip to main content

Python bindings for Alopex DB

Project description

Alopex Python バインディング

Python から AlopexDB を操作するためのバインディングです。
Database/Transaction の基本機能に加え、ベクトル検索(numpy)と Unity Catalog 互換の Catalog API(polars)を提供します。

インストール

pip install alopex

Catalog API (polars) を使う場合:

pip install alopex[polars]

開発中は maturin を利用できます。

maturin develop -m crates/alopex-py/pyproject.toml

オプション依存:

  • numpy を使う場合: pip install alopex[numpy]
  • polars を使う場合: pip install alopex[polars]

対応バージョン

依存関係 対応バージョン
Python 3.8+
Polars 0.20+ (Catalog API)
NumPy 1.20+ (Vector API)

基本的な使い方

Database / Transaction

from alopex import Database, TxnMode

db = Database.new()

with db.begin(TxnMode.READ_WRITE) as txn:
    txn.put(b"user:1", b"alice")
    txn.commit()

with db.begin(TxnMode.READ_ONLY) as txn:
    value = txn.get(b"user:1")
    print(value)

db.close()

ベクトル検索(numpy 必須)

import numpy as np
from alopex import Database, Metric, TxnMode

db = Database.new()
with db.begin(TxnMode.READ_WRITE) as txn:
    vec = np.array([1.0, 0.0, 0.0], dtype=np.float32)
    txn.upsert_vector(b"k1", None, vec, Metric.COSINE)
    results = txn.search_similar(vec, Metric.COSINE, 1, return_vectors=True)
    print(results[0].key, results[0].score)
    if results[0].vector is not None:
        print(results[0].vector.dtype, results[0].vector.shape)

NumPy 入出力とゼロコピー条件(v0.3.5)

入力(Python → Rust):

  • dtype: float32 が優先。float64float32 に変換して処理します。
  • layout: C-contiguous が優先。非連続(strided/Fortran order 等)は C-contiguous に変換して処理します。
  • ゼロコピー入力: float32 かつ C-contiguous の場合は Rust 側でコピーなしに参照します。

出力(Rust → Python):

  • Transaction.search_similar(..., return_vectors=True) の場合、SearchResult.vectornumpy.ndarray[float32] を含められます。
  • Transaction.search_similar(..., zero_copy_return=True) / Transaction.get_vector(..., zero_copy_return=True) の場合、可能なら所有権移譲によるゼロコピー返却を行います(False の場合はコピー)。

GIL:

  • upsert_vector / search_similar / search_hnsw は重い処理中に GIL を解放します。

HNSW インデックス(numpy 必須)

import numpy as np
from alopex import Database, HnswConfig, TxnMode

db = Database.new()
db.create_hnsw_index("idx", HnswConfig(2))

with db.begin(TxnMode.READ_WRITE) as txn:
    vec = np.array([1.0, 0.0], dtype=np.float32)
    txn.upsert_to_hnsw("idx", b"k1", vec, None)
    txn.commit()

results, stats = db.search_hnsw("idx", np.array([1.0, 0.0], dtype=np.float32), 1)
print(stats.node_count)

Catalog API(polars 必須)

import polars as pl
from alopex import Catalog, ColumnInfo

Catalog.create_catalog("main")
Catalog.create_namespace("main", "default")

columns = [ColumnInfo("id", "int", 0, False)]
Catalog.create_table("main", "default", "users", columns, "/tmp/users.parquet")

df = pl.DataFrame({"id": [1, 2], "name": ["a", "b"]})
Catalog.write_table(
    df,
    "main",
    "default",
    "users",
    delta_mode="overwrite",
    storage_location="/tmp/users.parquet",
)

lazy_frame = Catalog.scan_table("main", "default", "users")
print(lazy_frame.collect())

注意事項

  • numpy / polars が未インストールの場合、対応 API は AlopexError を返します。
  • Phase 1 では Parquet のみ対応しています。

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

alopex-0.4.0.tar.gz (490.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

alopex-0.4.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (644.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

alopex-0.4.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (646.4 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

alopex-0.4.0-cp38-abi3-win_amd64.whl (551.1 kB view details)

Uploaded CPython 3.8+Windows x86-64

alopex-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (671.4 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

alopex-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (647.2 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

alopex-0.4.0-cp38-abi3-macosx_11_0_arm64.whl (624.0 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

alopex-0.4.0-cp38-abi3-macosx_10_12_x86_64.whl (658.7 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file alopex-0.4.0.tar.gz.

File metadata

  • Download URL: alopex-0.4.0.tar.gz
  • Upload date:
  • Size: 490.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for alopex-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8d291ffb9a3b3ef73cfc9958b6f981aad83d80ee4d71f3c311bb560a17063ce0
MD5 492a3426e02bc0dd893e958a5de4e5b7
BLAKE2b-256 277f9d27a506ac119d75cc19b9010847391ceae8ead079023ba0b71f6f9dcafe

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.4.0.tar.gz:

Publisher: alopex-py-release.yml on alopex-db/alopex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alopex-0.4.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for alopex-0.4.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 82fe9f846c2757ce3626e7497380f4face0b53488e13de143ea766a102ff863a
MD5 577ad3b7f4334c3a916830ea21ee581d
BLAKE2b-256 332464a185029a98a54ade24ce5d04e9c1b1ccdec2288cab55361eaa25d2e72a

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.4.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: alopex-py-release.yml on alopex-db/alopex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alopex-0.4.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for alopex-0.4.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f75f12951caab1b106ab8c9b87866063ef41af8e1859eb0a04616368e78225f9
MD5 8aa0eea6b2d02cf768c158f26ecb1c6e
BLAKE2b-256 8d16898f8b63d67e277780493548d953e43b1fd868f5296f33156d2e7b48194d

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.4.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: alopex-py-release.yml on alopex-db/alopex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alopex-0.4.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: alopex-0.4.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 551.1 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for alopex-0.4.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7cfc1935a27ffd5b8d2ecfa9a95b465e89980576f22927399524c851e8fb935d
MD5 9b815e787ff1a14ab8a085148e61fc20
BLAKE2b-256 2a44b634752f9a8ae16a476bcb8f1baac2a895a96b9207b1810bebfa78e2bcd3

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.4.0-cp38-abi3-win_amd64.whl:

Publisher: alopex-py-release.yml on alopex-db/alopex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alopex-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for alopex-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8f677698b17731217607d58d1676f1436b20a81d4815275a95548c1912b93f4
MD5 1a016b3c7261e4512fcf6669be0f703e
BLAKE2b-256 33a54ef477e7bbff0c0c55476f847b02b33b959384b866e3136ac41dbf12baa6

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: alopex-py-release.yml on alopex-db/alopex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alopex-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for alopex-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 19db22d8448bd31605cbb1cbfa559a6a3800c6d71ca8045de32db64e9eea93b6
MD5 d6d77eb28ecac001b6cae0ff0afd2ebd
BLAKE2b-256 c14f35acfdddbee876ab0ffd853ef7644deddac1f1377f2e1055ba2bd2bb9887

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: alopex-py-release.yml on alopex-db/alopex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alopex-0.4.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for alopex-0.4.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2912266c3fdcd916bb4bf4558f1d38fc4c9f1acae097afe7a985af803a4bdba2
MD5 88c80e17716632dbdf9c7a5443c69cc8
BLAKE2b-256 4a92c9d8ae5680e9b92145b9491c075fac49f97c5628715ef424eaef3e18a406

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.4.0-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: alopex-py-release.yml on alopex-db/alopex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alopex-0.4.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for alopex-0.4.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cb66ea36f59b370605584ecda626211cc4bd2e3aac123b7149b6ccf16166ed84
MD5 102993b2754eebae81f36c2a33c795a3
BLAKE2b-256 903ebedd24034e1f95534e181057f0fab9b3cdc50b9fea609ede05e4b8f53eb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.4.0-cp38-abi3-macosx_10_12_x86_64.whl:

Publisher: alopex-py-release.yml on alopex-db/alopex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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