Skip to main content

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 のみ対応しています。

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.7.7.tar.gz (822.3 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.7.7-cp38-abi3-win_amd64.whl (6.4 MB view details)

Uploaded CPython 3.8+Windows x86-64

alopex-0.7.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.6 MB view details)

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

alopex-0.7.7-cp38-abi3-macosx_11_0_arm64.whl (5.8 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

alopex-0.7.7-cp38-abi3-macosx_10_12_x86_64.whl (6.3 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: alopex-0.7.7.tar.gz
  • Upload date:
  • Size: 822.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for alopex-0.7.7.tar.gz
Algorithm Hash digest
SHA256 f4db9166caccb025d2ab277dff3c38dcbf3bfd71023a3aacbcd4993a592c6b1c
MD5 a0de852d80274097bf26c63ee43bbcdf
BLAKE2b-256 c02b66eb40316a092030f94d370acff4bd2836069c83cdd9507378d2ebda35d3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: alopex-0.7.7-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 6.4 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for alopex-0.7.7-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 af917fbce53f086c04886afdb9e61d3041bf7dbad9bcba69003c59d5868870e5
MD5 66c78373c9dd42487c01f3ea36a9798b
BLAKE2b-256 a89676e874bf900bc3d38cc771fadbfe8300381f59f007745012a2d46e666c5d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for alopex-0.7.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 49b5a465ca0f18393b54fc95cba1381afc2142c2bd2e2a15a3c5d011b4d21064
MD5 0fa2bb8743d9b3b9077fd30359db86bf
BLAKE2b-256 43524e617837f3481ecf722c4f297726115920ab02f34d484bd19d73b456d72b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for alopex-0.7.7-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d4417df548583eeb6d512244709e52d6fcf4d07aa1e454c9dab2ed0d24f172b8
MD5 fbf38350ef4115137194bfc1b533dedf
BLAKE2b-256 a2d7cdd43cec122db62ee736e181141232a5f584e365bec91d6d4a20e67baaf8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for alopex-0.7.7-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ecb494fe550b75e67c1a9f8d7caa1d4f90edcea6d86417df792a8e8b62b2e5ca
MD5 c74aff78ccfcf484a8b6c173b5a21548
BLAKE2b-256 de564fd01f651f5cd6bc83e1f61cd6ac39314d8e3944beb619dfca107f98177a

See more details on using hashes here.

Provenance

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

Release history Release notifications | RSS feed

0.8.13

5 files

0.8.12

5 files

0.8.11

5 files

0.8.10

5 files

0.8.9

5 files

0.8.8

5 files

0.8.7

5 files

0.8.6

5 files

0.8.5

5 files

0.8.4

5 files

0.8.3

5 files

0.8.2

5 files

0.8.1

5 files

0.8.0

5 files

This release

0.7.7 This release

5 files

0.7.6

5 files

0.7.5

5 files

0.7.4

5 files

0.7.3

5 files

0.7.2

5 files

0.7.1

5 files

0.7.0

5 files

0.6.0

5 files

0.4.0

8 files

0.3.5

8 files

0.3.3

8 files

0.3.2

8 files

0.3.1

8 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page