Replies: 2 comments 4 replies
-
I think the main point here is that tools targeting Python documentation will not be able to process the Rust source code. So generally, you need to build your extension module and then use Python's introspection facilities to extract the documentation embedded in the extension. For Sphinx this is done using the autodoc extension. pydoc seems to work in a similar manner, so building your module using e.g. |
Beta Was this translation helpful? Give feedback.
-
pdoc can pick up type annotations from
/// Start a WireGuard server.
#[pyfunction]
fn start_server(
py: Python<'_>,
host: String,
port: u16,
private_key: String,
peer_public_keys: Vec<String>,
handle_connection: PyObject,
receive_datagram: PyObject,
) -> PyResult<&PyAny> {
/* ... */
}
from typing import Awaitable, Callable
async def start_server(
host: str,
port: int,
private_key: str,
peer_public_keys: list[str],
handle_connection: Callable[[asyncio.StreamReader, asyncio.StreamWriter], Awaitable[None]],
receive_datagram: Callable[[bytes, tuple[str, int], tuple[str, int]], None],
) -> WireguardServer: ... ⬇️
I should mention that this uses a yet-unreleased version of maturin (to include PyO3/maturin#886), but given the current release cadence that should be a matter of weeks. :) |
Beta Was this translation helpful? Give feedback.
-
Can I use pydoc or pdoc or something else to generate Python api documents from rust code which uses PyO3? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions