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

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

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

オプション依存:

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

基本的な使い方

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.3.5.tar.gz (478.8 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.3.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (620.9 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

alopex-0.3.5-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (622.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

alopex-0.3.5-cp38-abi3-win_amd64.whl (525.6 kB view details)

Uploaded CPython 3.8+Windows x86-64

alopex-0.3.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (645.8 kB view details)

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

alopex-0.3.5-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (622.7 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

alopex-0.3.5-cp38-abi3-macosx_11_0_arm64.whl (599.7 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

alopex-0.3.5-cp38-abi3-macosx_10_12_x86_64.whl (634.6 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for alopex-0.3.5.tar.gz
Algorithm Hash digest
SHA256 bd3d617e108defd43ae2c66ff188878856a50b1f4a21875d4e7232799ab4fb5b
MD5 26ad8f4c65a6b8f9a639cc58a7b03b31
BLAKE2b-256 f9af05819eb9d08f48209f501b0fa9a569ce416d7ae13fbfdefd4dc140420f22

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.3.5.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.3.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for alopex-0.3.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7fdd613d29304f9c4620d1302180f2c8a2b59aae9d833ebc147c380531b1ce7a
MD5 c1759edf4216c0a82975d06e8f0c7446
BLAKE2b-256 0c86653a305b400a5508b9f60822ef6ff8283f39f0b6f905c8253f1071673872

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.3.5-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.3.5-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for alopex-0.3.5-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1bb9894ee7c7bf6455f24e3ab041c558899de8f81959c8e737029f77fc2f9331
MD5 f23df0cb04add50de809e2dd5d34f5cd
BLAKE2b-256 d3098f1e9306a9120b76887d3253174765aed42e345368c32e180d76154fbce3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: alopex-0.3.5-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 525.6 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.3.5-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fe1d5bc1e4d045db3f58e87442290da83eb5a1ecff72ee42c3b2a3cf2a609156
MD5 f23c1c91db19107e7e08deb90ef4d4a6
BLAKE2b-256 0ea7208fe5602a0063193e143480372c4b90bbaa299a8bda4841802195759456

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for alopex-0.3.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 168a350334a9eefb4b03bde0f212c85cc375b3ea744a0605675b4057e5f86dcb
MD5 67ee0bdf08fe36abc7f65f79d8e5206c
BLAKE2b-256 59f248bfb1736426018be40ee4f0409773b1bb6becb11002a574c550dd77b7b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for alopex-0.3.5-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.3.5-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for alopex-0.3.5-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5df418807bbf15e39c24036ff8b2332f6f2a7dcc8a8611b521ff603086ce1feb
MD5 4bfca67a62b067932ef7165a6b27a152
BLAKE2b-256 e24ff309b6e73b77538209eae0f5107804d33579513e0dc21374a9c549a454e7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for alopex-0.3.5-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c7ae5f5a401cb24e76926eaf32074b325120c792ca29e1f6f3a9076bdc74008f
MD5 4daf00cb827af80787128064b98ddd0d
BLAKE2b-256 df9ae08db07f126921037d8957601e0a65a7792ec6c1de5ff691d47590e5cec5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for alopex-0.3.5-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 803e1c0e82e1bbb29299011eb3845b3801f936503dae347bbb79d32f2d67a2b5
MD5 b36b25cd88c217ed4758451798dfaa8e
BLAKE2b-256 25165e28d1f53fa68a23e02a43ed083210daef051b67505af36d8f62904a7376

See more details on using hashes here.

Provenance

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