py_env 1.0.0

A wrapper for Python commands to easily install dependencies and run Python scripts in an optionally impersistent environment.
Documentation
py_env-1.0.0 has been yanked.

py_env

A Rust library to run Python scripts and install dependencies within a given environment path.

Table of Contents

Installation

This library requires no dependencies and is not on crates.io (yet), and as such the easiest method is to just copy the lib.rs file into your project, rename it to py_env.rs or some other name, and import it from your code.

Usage

Creating a Python Environment

This library uses a very simple syntax to run Python scripts. To create a Python environment, simply run PyEnv::at(PathBuf).

use py_env::PyEnv;

let env = PyEnv::at("./py_test");

Running Arbitrary Code

use py_env::PyEnv;

PyEnv::at("./py_test")
    .execute("print('hello world')")
    .expect("Failed to execute code");

Installing Python Dependencies

The following code installs numpy into the ./py_test directory's site-packages and uses it in executed code.

use py_env::PyEnv;

PyEnv::at("./py_test")
    .install("numpy")
    .expect("Failed to install numpy")
    .execute("a = numpy.arange(15).reshape(3, 5); print(a.shape)")
    .expect("Failed to execute code");

Making Environments Impersistent

The following code deletes the python environment off of the disk once it's done running.

use py_env::PyEnv;

PyEnv::at("./py_test")
    .persistent(false)
    .install("numpy").expect("Failed to install numpy");

Contributing

This was made as a code bounty, and as such is not a maintained project, but PRs are always welcome and will be reviewed when I see them.

License

This code is licensed under the MIT License.