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.6.0.tar.gz (740.4 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.6.0-cp38-abi3-win_amd64.whl (827.7 kB view details)

Uploaded CPython 3.8+Windows x86-64

alopex-0.6.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

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

alopex-0.6.0-cp38-abi3-macosx_11_0_arm64.whl (925.6 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

alopex-0.6.0-cp38-abi3-macosx_10_12_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for alopex-0.6.0.tar.gz
Algorithm Hash digest
SHA256 1ec4810ac135d8963ea4d68964eeb80d0e28b7410404023f679857d4ebe8d93b
MD5 9dc592bc49a5fafcde4835882e566823
BLAKE2b-256 bfce810c2a8c008877fc02d3615b52844c05dda40ef51f76f47c8ab4c7e3150a

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.6.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.6.0-cp38-abi3-win_amd64.whl.

File metadata

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

File hashes

Hashes for alopex-0.6.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4861ea1f28a4ccccb4494d90b2ecb689524f2f8c24a44c332d54f3bb07ce7990
MD5 5ce529e356deaaaf1da4e833324931af
BLAKE2b-256 f175354fc6a839d0b7d5fe30af0b7a377ccec6c5d716fe3383a8a8ecd528f9b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.6.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.6.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for alopex-0.6.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4223210921b34de5bb89f81b7970103232db6afd91694713be9c1418349d543e
MD5 cf512685c031503b09f48381bef35ec4
BLAKE2b-256 bd0563b071a093c1d87cc3260c1a7200043ebbf3f38387db910d9cb09380f18b

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.6.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.6.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for alopex-0.6.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6124f65a22d42e7fb2972bb5e1bcac5687ca37ad25c709022df11699e03a7d4e
MD5 8bccc81fd6f508cb5ba010385030505b
BLAKE2b-256 e0c4843afaca567be238292450d90bf5d751ea0fead74fe31fec67f4f13e849a

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.6.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.6.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for alopex-0.6.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b0d2bdf03eaf9fd1c80017880eee3e73c54ca40a1ad5887ec200999955ead161
MD5 136f5be52e0f6ad3cc38faf61fba7fde
BLAKE2b-256 8e969c8af4f267b5474ba8609cb9836c28eabff0aa5efb4abb6af00e9608a8f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.6.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