Python module generation is powered by unstable [Procedural Macros](https://doc.rust-lang.org/book/first-edition/procedural-macros.html) feature, so you need to turn on `proc_macro` feature:
```rust
#![feature(proc_macro)]
extern crate pyo3;
# fn main() {}
```
You need to change your `crate-type` to `cdylib` to produce a Python compatible library:
```toml
[lib]
name = "rust2py"
crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "0.1", features = ["extension-module"] }
```
Now you can write your module, for example
```rust
#![feature(proc_macro)]
extern crate pyo3;
use pyo3::{py, PyResult, Python, PyModule};
// add bindings to the generated python module
// N.B: names: "librust2py" must be the name of the `.so` or `.pyd` file
The `modinit` procedural macro attribute takes care of exporting the initialization function of your module to Python. It takes one argument as the name of your module, it must be the name of the `.so` or `.pyd` file.
The [Rust doc comments](https://doc.rust-lang.org/stable/book/first-edition/comments.html) of the module initialization function will be applied automatically as the Python doc string of your module.
```python
import rust2py
print(rust2py.__doc__)
```
Which means that the above Python code will print `This module is implemented in Rust.`.