Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mitsuhiko/snaek
DEPRECATED: Being replaced with milksnake: https://github.com/getsentry/milksnake
https://github.com/mitsuhiko/snaek
Last synced: 2 months ago
JSON representation
DEPRECATED: Being replaced with milksnake: https://github.com/getsentry/milksnake
- Host: GitHub
- URL: https://github.com/mitsuhiko/snaek
- Owner: mitsuhiko
- License: apache-2.0
- Created: 2017-06-12T14:21:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-03T14:33:30.000Z (over 7 years ago)
- Last Synced: 2024-10-13T01:36:52.458Z (3 months ago)
- Language: Python
- Homepage:
- Size: 23.4 KB
- Stars: 224
- Watchers: 15
- Forks: 4
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**DEPRECATED**
This project is (temporarily) deprecated in favour of [milksnake](https://github.com/getsentry/milksnake).
Milksnake lets you do the same thing as snaek but does it on a lower level so
that (until we can generate significantly higher level bindings to Python) we
put more controls in the hands of the developer.-----------
# Snaek
Snaek is a Python library that helps you build Rust libraries and bridge them to
Python with the help of cffi.## Why?
There are already other projects that make Python and Rust play along but this
one is different. Unlike other projects that build Python extension modules the
goal of this project is to build regular Rust libraries that are then loaded
with CFFI at runtime. The advantage of this is that it does not link against
libpython which means that you only need to build a handful of Python wheels
to cover all platforms you care about.In particular you will most likely only need two wheels for Linux, one for macs
and soon one for Windows independently of how many Python interpreters you want
to target.## What is supported?
* Platforms: Linux, Mac (Windows later)
* setuptools commands: `bdist_wheel`, `build`, `build_ext`, `develop`
* `pip install --editable .`
* Universal wheels (`PACKAGE-py2.py3-none-PLATFORM.whl`); this can be disabled
with `snaek_universal=False` in `setup()` in case the package also contains
stuff that does link against libpython.## How?
This is what a `setup.py` file looks like:
```python
from setuptools import setupsetup(
name='example',
version='0.0.1',
packages=['example'],
zip_safe=False,
platforms='any',
setup_requires=['snaek'],
install_requires=['snaek'],
snaek_rust_modules=[
('example._native', 'rust/'),
]
)
```You then need a `rust/` folder that has a Rust library (with a crate type
of `cdylib`) and a `example/` python package.Example `example/__init__.py` file:
```python
from example._native import ffi, libdef test():
return lib.a_function_from_rust()
```And a `rust/src/lib.rs`:
```rust
#[no_mangle]
pub unsafe extern "C" fn a_function_from_rust() -> i32 {
42
}
```