agentleFS
manav8498manav8498/processfork/.claude/skills/pyo3-binding/SKILL.md

pyo3-binding

Skill1 starsChanged 6 months agoMITView on GitHub

Patterns for exposing ProcessFork Rust APIs to Python via pyo3 0.22 and maturin.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Place #![allow(unsafe_op_in_unsafe_fn)] at the top of lib.rs (current approach), with a TODO to revisit on pyo3 ≥0.23.

    line 21
  2. Very specific:

    Use pyo3-asyncio for async fn exposure.

    line 28

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

pyo3 binding patterns

Module shape

  • The cdylib lib name MUST match the Python import name: [lib] name = "_pf_py" → import _pf_py.
  • The Python-facing package wraps the cdylib for ergonomics: crates/pf-py/python/processfork/__init__.py re-exports.
  • Use #[pymodule] fn _pf_py(m: &Bound<'_, PyModule>) -> PyResult<()> signature (pyo3 0.22 bound API). Old &PyModule is deprecated.

Edition 2024 gotcha

pyo3 0.22's #[pyfunction] macro emits unsafe extraction calls that trip the unsafe_op_in_unsafe_fn lint under edition 2024. Either:

  • Place #![allow(unsafe_op_in_unsafe_fn)] at the top of lib.rs (current approach), with a TODO to revisit on pyo3 ≥0.23.
  • Or accept owned Vec<u8> instead of &[u8] (avoids one class of warning but not all).

Async

Use pyo3-asyncio for async fn exposure. Pattern:

#[pyfunction]
fn snapshot<'p>(py: Python<'p>, agent_id: String) -> PyResult<&'p PyAny> {
    pyo3_asyncio::tokio::future_into_py(py, async move {
        let cid = pf_core::snapshot(&agent_id).await?;
        Ok(cid.to_string())
    })
}

Errors

Wrap pf_core::Error into PyErr via a manual From impl in pf-py/src/errors.rs. Map Error::Integrity → PyValueError, Error::Io → PyOSError, etc. Never swallow with a generic RuntimeError.

Type stubs

Hand-write crates/pf-py/python/processfork/_pf_py.pyi so end-users get type hints. Keep it in sync with the Rust signatures; add a CI check.

Build

maturin develop --release for local dev, maturin build --release for wheels. crates/pf-py/pyproject.toml declares [tool.maturin] module-name = "processfork._pf_py".

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.