Skip to content

Add Python bindings via PyO3/maturin#22

Open
arunmk wants to merge 2 commits into
dropbox:masterfrom
arunmk:python-bindings
Open

Add Python bindings via PyO3/maturin#22
arunmk wants to merge 2 commits into
dropbox:masterfrom
arunmk:python-bindings

Conversation

@arunmk

@arunmk arunmk commented Jun 13, 2026

Copy link
Copy Markdown

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:

  • 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

@CLAassistant

CLAassistant commented Jun 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

arunmk and others added 2 commits June 13, 2026 13:41
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>
@arunmk arunmk force-pushed the python-bindings branch from cb35ed2 to 44002cf Compare June 13, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants