Rust bindings for the Python interpreter
Find a file
Daniel Grunwald b37fa220df On Python 2.7, PyString now corresponds to basestring instead of str.
`<str as ToPyObject>::ObjectType` now always is `PyString`
  (previously the type differed between Python 2.7 and 3.x)

`PyStringData` allows zero-copy access to Python's underlying string
representation.
2016-05-05 07:26:52 +02:00
examples
extensions Add support for __len__ special method. 2016-04-17 23:26:33 +02:00
python3-sys Merge pull request #45 from royalstream/royalstream-macos 2016-04-17 23:46:18 +02:00
python27-sys Add support for __len__ special method. 2016-04-17 23:26:33 +02:00
src On Python 2.7, PyString now corresponds to basestring instead of str. 2016-05-05 07:26:52 +02:00
tests Add support for __iter__ and __next__ slots. 2016-04-30 23:41:18 +02:00
.gitignore
.travis.yml
appveyor.yml
build.rs
Cargo.toml We only need num-traits, not the full num crate. 2016-04-17 23:35:17 +02:00
LICENSE
Makefile
README.md

rust-cpython Build Status

Rust bindings for the python interpreter.


Copyright (c) 2015-2016 Daniel Grunwald. Rust-cpython is licensed under the MIT license. Python is licensed under the Python License.

Supported Python versions:

  • Python 2.7
  • Python 3.3
  • Python 3.4
  • Python 3.5

Supported Rust version:

  • Rust 1.7.0 or later

Usage

To use cpython, add this to your Cargo.toml:

[dependencies]
cpython = { git = "https://github.com/dgrunwald/rust-cpython.git" }

Example program displaying the value of sys.version:

extern crate cpython;

use cpython::Python;
use cpython::ObjectProtocol; //for call method

fn main() {
    let gil = Python::acquire_gil();
    let py = gil.python();

    let sys = py.import("sys").unwrap();
    let version: String = sys.get(py, "version").unwrap().extract(py).unwrap();

    let os = py.import("os").unwrap();
    let getenv = os.get(py, "getenv").unwrap();
    let user: String = getenv.call(py, ("USER",), None).unwrap().extract(py).unwrap();

    println!("Hello {}, I'm Python {}", user, version);
}