feat(python): add PyO3-based Python bindings#600
Conversation
- Add native PyO3 extension in crates/fff-python - Replace ctypes wrapper with maturin-built package in packages/fff-python - Expose FileFinder, search/glob/directory/mixed/grep APIs and result types - Use PyPI package name fff-python (import name remains fff) - Update workspace Cargo.toml/Cargo.lock and .gitignore for Python artifacts
- Add .github/workflows/python.yml to test bindings on Ubuntu/macOS/Windows - Extend release.yaml with Python wheel builds (x86_64/aarch64) and sdist - Add optional PyPI publish job using trusted publishing
dmtrKovalenko
left a comment
There was a problem hiding this comment.
it looks good to me (Im not a good python dev lol)
@gustav-fff can you also review for any issues
|
@gustav-fff are you here? |
|
[triage-bot] DIRECTED: Here. Standing by for instructions. Honk-Honk 🪿 |
|
@gustav-fff review this PR lol |
|
[triage-bot] DIRECTED: Review. Cross-repo PR; cannot push. Findings below, ordered by impact. Blocking (perf):
Should fix:
Nits:
LGTM:
Recommend addressing the GIL release and Honk-Honk 🪿 |
Rust bindings: - Release GIL during heavy search/grep operations via py.allow_threads - Add MixedFileItem/MixedDirItem::from_core to avoid double-cloning - Return PyDict directly from health_check and drop serde_json dependency - Call destroy() in __exit__ so the context manager releases resources - Add mode parameter to multi_grep for parity with grep - Preserve cache budget overrides across reindex() - Rename combo_boost param to match FuzzySearchOptions field Docs/tests: - Update Python test for dict-returning health_check - Add Python bindings section to main README CI: - Fix pypi-publish job to depend on build-python/build-python-sdist instead of release, making the workflow_dispatch checkbox functional
|
This is the logic I added for the release CI. Please take a look and let me know if it makes sense. How to publish
|
|
Hey, I went through the review points from you and gustav-fff and fixed all of them in the latest commit:
Also updated the Python test and pushed everything. Let me know if anything looks off! |
- Split crates/fff-python/src/lib.rs into modules: - types.rs: all pyclass result types - finder.rs: FileFinder implementation - conversions.rs: From/core conversions - Make API more Pythonic: - FileFinder now accepts pathlib.Path / os.PathLike for base_path and reindex - Add close() alias for destroy() - grep/multi_grep now raise FFFException for invalid modes - GrepResult gains has_more property and next_cursor() method - Add type stubs: - packages/fff-python/src/fff/__init__.pyi - packages/fff-python/src/fff/py.typed - Add __repr__ implementations for all exposed pyclasses - Expand Python tests for pathlib, close(), reprs, invalid mode, and cursor pagination
Make the Python binding API more idiomatic before merge: replace getter-style methods with properties, keep close() as the single explicit shutdown API, add container semantics for result objects, and tighten type stubs with Literal/Sequence/PathLike support. Also reduce Rust binding duplication with shared option/result helpers and release the Python GIL around blocking filesystem, git, and query-history operations.
|
made wait for scan api async and some additional changes |
…rors; expand readme
Summary
This PR adds a new Python binding for FFF using PyO3, providing a native extension with a clean Pythonic API.
Changes
crates/fff-python/with PyO3 bindingsFileFinderclass exposing search, glob, directory search, mixed search, grep and multi-grep APIsFileItem,DirItem,GrepMatch,Score, etc.destroy()packages/fff-python/using thematurinbuild backendfff-python; import name remainsfff.github/workflows/python.ymlfor Ubuntu/macOS/Windows testingrelease.yamlto build Python wheels (x86_64/aarch64) and sdist, with optional PyPI publishing via trusted publishingcrates/fff-pythonto workspace members and updatedCargo.lock.gitignorefor Python build artifactsVerification
Tested on the fork repository; the relevant CI checks pass:
cargo check -p fff-python✅cargo clippy -p fff-python --no-deps -- -D warnings✅uv run pytest -v✅ (8 passed)uv run python examples/basic.py .✅Python CIpasses on Ubuntu, macOS and WindowsPrebuildPython wheel jobs build successfully across all target platforms