Skip to main content

Python library to perform code execution in fully isolated environments

Project description

pascua

PyPI Read the Docs Travis (.org) branch Coveralls github GitHub GitHub stars

Description

Python library to perform code execution in fully isolated environments.

IMPORTANT: This repository is in the early stage of development, so its not recommended to be used yet. Nevertheless, contributions are welcome!

Installation

You can install the latest pascua version via pip:

pip install pascua

How it works?

pascua allow us to perform code executions in isolated environments through containerization techniques. The main idea is that pascua builds a docker image with the given parameters defined in the corresponding implementation of the Environment constructor.

When a call to exec(.) method is performed, it uses the generated docker image as the base in which it launches the proper interpreter or code compilation to execute the given source_code in combination with the variables defined in the context dictionary.

Usage

Python Environment

import pascua as psc

context = {
    'size': 100,
}

source_code = [
    'import numpy as np',
    'random_numbers = np.random.uniform(size=size)',
]

env = psc.PythonEnvironment(
    version='3.7.3', 
    pip_dependencies=[
        'numpy>=1.14.0',
    ]
)

result = env.exec(source_code, context)

R Environment

import pascua as psc

context = {
    'size': 100,
}

source_code = [
    'random_numbers <- runif(n = size)',
]

env = psc.REnvironment(
    version='latest',
)

result = env.exec(source_code, context)

C++ Environment

import pascua as psc

context = {
    'size': 100,
}

source_code = [
    'float r;',
    'vector<float> random_numbers;',
    'for (int i = 0; i < size; i++) {',
    '  r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);',
    '  random_numbers.push_back(r);',
    '}',
]

env = psc.CCEnvironment(
    version='latest',
    includes=[
        'vector',
        'numeric',
    ]
)

result = env.exec(source_code, context)

Development

You can install it simply typing:

python setup.py install

To run the tests perform:

python -m unittest discover tests

License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pascua-0.0.2.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

pascua-0.0.2-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page