Giter Club home page Giter Club logo

rustpy's Introduction

Rustpy

A simple library to allow for easy use of python from rust.

Status

Currently this library has not received much love (pull requests welcome for any interested) and does not build with rust 1.0.

For another library that also strives to bridge the gap between python and rust and might be a little more up to day see:

https://github.com/dgrunwald/rust-python27-sys

https://github.com/dgrunwald/rust-cpython

How to Use

This library is meant to be middle ware for users wanting to use python libraries from rust. It allows users to quickly use existing tools and get working on interesting things fast!

See pysmtplib.rs for an example of how to bind enough smtplib to send emails.

For more documentation, run rustdoc src/rustpy.rs and look at doc/rustpy/index.html. Pull requests are welcome!

extern crate rustpy;
use rustpy::{ToPyType, FromPyType, PyState};

fn main() {
  let py = PyState::new();
  let module = py.get_module("math").unwrap();
  let func = module.get_func("sqrt").unwrap();
  let args = (144f32, ).to_py_object(&py).unwrap();
  let untyped_res = func.call(&args).unwrap();
  let result = py.from_py_object::<f32>(untyped_res).unwrap();
  assert_eq!(result, 12f32);
}

Important note: Only create one instance of PyState at a time. On construction, it grabs a global lock to prevent more than one thread from interacting with the interpreter thus making it very easy to deadlock.

rustpy's People

Contributors

lukemetz avatar mvdnes avatar steveklabnik avatar subterran3an avatar yberreby avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.