Embedded local-first property graph with vector search
Project description
polypack (Python)
Python bindings for the polypack embedded property-graph and vector-search
core. PolyGraph and GraphQuery are a native Python layer mirroring the
TypeScript PolyGraph/GraphQuery API; vector indexing,
query execution, and directory-backed persistence run in the Rust core
(polypack._core, built from crates/polypack-python).
Install
pip install polypack-db
Requires Python 3.8+ and numpy. Prebuilt wheels are published from
polypack-db on PyPI; the version
tracks the TypeScript package and polypack-core crate in lockstep.
Quick start
import time
from polypack import PolyGraph
graph = PolyGraph()
graph.add_node({
"id": "doc_1",
"type": "document",
"data": {"title": "Quantum Computing"},
"vector": [0.95, 0.20, 0.10],
"insertedAt": int(time.time() * 1000),
"updatedAt": int(time.time() * 1000),
})
graph.add_edge("doc_1", "REFERENCES", "doc_2", ownership="owned")
# Search by similarity
graph.query() \
.where_type("document") \
.similar_to([0.90, 0.30, 0.10], 0.5, 5) \
.to_list()
# Filter, traverse, aggregate
graph.query().where("title", "Quantum Computing").traverse("REFERENCES", 3).to_list()
graph.query().where_type("book").aggregate("price", "avg")
Persistence
PolyGraph.open(directory) attaches a directory-backed binary store
(snapshot + write-ahead log, shared format with the TypeScript
BinaryStoreAdapter) and loads any existing state. Use it as a context
manager so the store is compacted and closed on exit:
with PolyGraph.open("./data") as graph:
graph.add_node({...})
graph.save() # persists queued puts and deletions
save() writes the complete current graph and flushes any deletions
recorded since the last save; close_store() compacts and closes explicitly.
Vector indexes
ExactIndex and HnswIndex wrap the Rust vector core directly and can be
used standalone, independent of PolyGraph:
from polypack import ExactIndex, HnswIndex
index = ExactIndex(distance="cosine")
index.add("doc_1", [0.95, 0.20, 0.10])
index.query([0.90, 0.30, 0.10], top_k=5, threshold=0.5)
approx = HnswIndex(m=16, ef_search=200)
approx.add_many([("doc_1", [0.95, 0.20, 0.10]), ("doc_2", [0.10, 0.90, 0.05])])
Errors
Native errors surface as PolypackError subclasses: PolypackValueError,
PolypackDimensionError, PolypackClosedError, PolypackVersionError,
PolypackCorruptDataError, and PolypackStorageError.
Development
See the top-level CONTRIBUTING.md for building the native extension with maturin and running the Python test suite.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polypack_db-2.4.6-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: polypack_db-2.4.6-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 472.8 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa653252e7bac93266c9d1e9a568155bf88c29231b718a32b6e4f6f2cb60e918
|
|
| MD5 |
614c29a6e30c6807ba36b6b82d1eb138
|
|
| BLAKE2b-256 |
7b8b243294cec2ee61261ca6be63fae0e9b288dd2f6edfe5bd8bc1a27c48f269
|
Provenance
The following attestation bundles were made for polypack_db-2.4.6-cp38-abi3-win_amd64.whl:
Publisher:
release.yml on imattau/polypack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polypack_db-2.4.6-cp38-abi3-win_amd64.whl -
Subject digest:
fa653252e7bac93266c9d1e9a568155bf88c29231b718a32b6e4f6f2cb60e918 - Sigstore transparency entry: 2311133995
- Sigstore integration time:
-
Permalink:
imattau/polypack@1273f96863a0ffeb60cb905c0ec35eaa1eb2aa49 -
Branch / Tag:
refs/tags/v2.4.6 - Owner: https://github.com/imattau
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1273f96863a0ffeb60cb905c0ec35eaa1eb2aa49 -
Trigger Event:
release
-
Statement type:
File details
Details for the file polypack_db-2.4.6-cp38-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: polypack_db-2.4.6-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 623.2 kB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f33aee1949027b9581244d337de330087f4b9316fd1bc2eee2b3f10fae9461d
|
|
| MD5 |
cbe914461c51d77de2a67eb17ebdadb8
|
|
| BLAKE2b-256 |
91b3eaa85a94323098f9b8944a69b7a94bfffb2513bd8c9e284b26308c06da6e
|
Provenance
The following attestation bundles were made for polypack_db-2.4.6-cp38-abi3-manylinux_2_34_x86_64.whl:
Publisher:
release.yml on imattau/polypack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polypack_db-2.4.6-cp38-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
1f33aee1949027b9581244d337de330087f4b9316fd1bc2eee2b3f10fae9461d - Sigstore transparency entry: 2311134094
- Sigstore integration time:
-
Permalink:
imattau/polypack@1273f96863a0ffeb60cb905c0ec35eaa1eb2aa49 -
Branch / Tag:
refs/tags/v2.4.6 - Owner: https://github.com/imattau
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1273f96863a0ffeb60cb905c0ec35eaa1eb2aa49 -
Trigger Event:
release
-
Statement type:
File details
Details for the file polypack_db-2.4.6-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: polypack_db-2.4.6-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 563.5 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
079283cb3d359b0dee6c70d307ebed13b420889aafbf83cdc3554e9293b9c658
|
|
| MD5 |
4ccd626a0a9f5ee6f0a95bb4c28c9c9c
|
|
| BLAKE2b-256 |
5fef94f976ac2f60f68b3c9f7f083ce77c9ba58e071b079d035fb8be9df47082
|
Provenance
The following attestation bundles were made for polypack_db-2.4.6-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on imattau/polypack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polypack_db-2.4.6-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
079283cb3d359b0dee6c70d307ebed13b420889aafbf83cdc3554e9293b9c658 - Sigstore transparency entry: 2311133937
- Sigstore integration time:
-
Permalink:
imattau/polypack@1273f96863a0ffeb60cb905c0ec35eaa1eb2aa49 -
Branch / Tag:
refs/tags/v2.4.6 - Owner: https://github.com/imattau
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1273f96863a0ffeb60cb905c0ec35eaa1eb2aa49 -
Trigger Event:
release
-
Statement type: