Add Python bindings via PyO3/maturin#22
Open
arunmk wants to merge 2 commits into
Open
Conversation
Exposes Witchcraft as a Python extension module using PyO3. Each instance owns an independent reader DB (search/score) and a background indexer thread (add/remove/index/clear), mirroring the napi module's architecture. Key details: - src/python.rs: new PyO3 module behind the `python` feature flag - build.rs: napi_build::setup() is now conditional on CARGO_FEATURE_NAPI so non-napi builds don't set conflicting linker flags - pyo3 uses abi3-py38 stable ABI; single wheel runs on Python 3.8–3.14+ - unsafe impl Send + Sync justified by GIL: rusqlite::Connection is !Send/!Sync but only ever accessed from the Python thread - Witchcraft::new() creates the write DB first so DB::new_reader succeeds on fresh paths; fails fast with PyRuntimeError on bad paths - Embedder loaded once and shared via Arc between reader and indexer thread, halving peak memory (~200-500 MB saved per instance) - Date validation: invalid ISO 8601 strings raise ValueError (consistent with UUID validation) instead of silently defaulting to now_utc() - Indexer thread logs embed_chunks, index_chunks, add_doc, remove_doc failures via tracing::warn! instead of silently discarding them - Drop impl joins the indexer thread so shutdown() is never required - Makefile: python-wheel / python-dev targets with auto-detected platform features; Linux aarch64 guard added across CLI/napi/python feature sets to avoid x86-only fbgemm/hybrid-dequant on ARM - pyproject.toml added for maturin; platform features come from Makefile - tests/test_witchcraft.py: smoke tests with @needs_assets skip marker for tests requiring downloaded model weights - README: Python build instructions, platform matrix, test instructions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
"Reader DB" implied a separate database; it is just a read-only connection to the same underlying SQLite file. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exposes Witchcraft as a Python extension module using PyO3. Each instance owns an independent reader connection (search/score) and a background indexer thread (add/remove/index/clear), mirroring the napi module's architecture.
Key details:
pythonfeature flagCo-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com